feat: Scan Silent Payments homepage toggle

This commit is contained in:
Rafael Saes 2024-04-01 19:19:31 -03:00
parent 7197a7bc71
commit 8ed3e41b2b
30 changed files with 172 additions and 46 deletions

View file

@ -142,6 +142,33 @@ abstract class ElectrumWalletBase
bool hasSilentPaymentsScanning = false;
@observable
bool nodeSupportsSilentPayments = true;
@observable
bool silentPaymentsScanningActive = false;
@action
void setSilentPaymentsScanning(bool value) {
hasSilentPaymentsScanning = value;
if (value) {
_setInitialHeight().then((_) {
if ((currentChainTip ?? 0) > walletInfo.restoreHeight) {
_setListeners(walletInfo.restoreHeight, chainTip: currentChainTip);
}
});
} else {
_isolate?.then((runningIsolate) => runningIsolate.kill(priority: Isolate.immediate));
if (electrumClient.isConnected) {
syncStatus = SyncedSyncStatus();
} else {
if (electrumClient.uri != null) {
electrumClient.connectToUri(electrumClient.uri!).then((_) {
startSync();
});
}
}
}
}
@observable
int? currentChainTip;
@ -260,7 +287,7 @@ abstract class ElectrumWalletBase
try {
syncStatus = AttemptingSyncStatus();
if (hasSilentPaymentsScanning) {
if (silentPaymentsScanningActive) {
try {
await _setInitialHeight();
} catch (_) {}
@ -279,7 +306,7 @@ abstract class ElectrumWalletBase
Timer.periodic(
const Duration(minutes: 1), (timer) async => _feeRates = await electrumClient.feeRates());
if (!hasSilentPaymentsScanning || walletInfo.restoreHeight == currentChainTip) {
if (!silentPaymentsScanningActive || walletInfo.restoreHeight == currentChainTip) {
syncStatus = SyncedSyncStatus();
}
} catch (e, stacktrace) {
@ -1335,7 +1362,9 @@ abstract class ElectrumWalletBase
Future<void> _setInitialHeight() async {
currentChainTip = await electrumClient.getCurrentBlockChainTip();
if (currentChainTip != null) walletInfo.restoreHeight = currentChainTip!;
if (currentChainTip != null && walletInfo.restoreHeight == 0) {
walletInfo.restoreHeight = currentChainTip!;
}
}
static BasedUtxoNetwork _getNetwork(bitcoin.NetworkType networkType, CryptoCurrency? currency) {

View file

@ -263,4 +263,14 @@ class CWBitcoin extends Bitcoin {
BitcoinAddressType getOptionToType(ReceivePageOption option) {
return (option as BitcoinReceivePageOption).toType();
}
bool getScanningActive(Object wallet) {
final bitcoinWallet = wallet as ElectrumWallet;
return bitcoinWallet.silentPaymentsScanningActive;
}
void setScanningActive(Object wallet, bool active) {
final bitcoinWallet = wallet as ElectrumWallet;
bitcoinWallet.setSilentPaymentsScanning(active);
}
}

View file

@ -9,6 +9,7 @@ import 'package:cake_wallet/src/screens/dashboard/widgets/home_screen_account_wi
import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
import 'package:cake_wallet/src/screens/exchange_trade/information_page.dart';
import 'package:cake_wallet/src/widgets/introducing_card.dart';
import 'package:cake_wallet/src/widgets/standard_switch.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/themes/extensions/balance_page_theme.dart';
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
@ -193,21 +194,29 @@ class CryptoBalanceWidget extends StatelessWidget {
itemBuilder: (__, index) {
final balance =
dashboardViewModel.balanceViewModel.formattedBalances.elementAt(index);
return BalanceRowWidget(
availableBalanceLabel:
'${dashboardViewModel.balanceViewModel.availableBalanceLabel}',
availableBalance: balance.availableBalance,
availableFiatBalance: balance.fiatAvailableBalance,
additionalBalanceLabel:
'${dashboardViewModel.balanceViewModel.additionalBalanceLabel}',
additionalBalance: balance.additionalBalance,
additionalFiatBalance: balance.fiatAdditionalBalance,
frozenBalance: balance.frozenBalance,
frozenFiatBalance: balance.fiatFrozenBalance,
currency: balance.asset,
hasAdditionalBalance:
dashboardViewModel.balanceViewModel.hasAdditionalBalance,
);
return Observer(builder: (_) {
return BalanceRowWidget(
availableBalanceLabel:
'${dashboardViewModel.balanceViewModel.availableBalanceLabel}',
availableBalance: balance.availableBalance,
availableFiatBalance: balance.fiatAvailableBalance,
additionalBalanceLabel:
'${dashboardViewModel.balanceViewModel.additionalBalanceLabel}',
additionalBalance: balance.additionalBalance,
additionalFiatBalance: balance.fiatAdditionalBalance,
frozenBalance: balance.frozenBalance,
frozenFiatBalance: balance.fiatFrozenBalance,
currency: balance.asset,
hasAdditionalBalance:
dashboardViewModel.balanceViewModel.hasAdditionalBalance,
hasSilentPayments: dashboardViewModel.balanceViewModel.hasSilentPayments,
silentPaymentsScanningActive:
dashboardViewModel.balanceViewModel.silentPaymentsScanningActive,
setSilentPaymentsScanning: () => dashboardViewModel.balanceViewModel
.setSilentPaymentsScanning(
!dashboardViewModel.balanceViewModel.silentPaymentsScanningActive),
);
});
},
);
},
@ -231,6 +240,9 @@ class BalanceRowWidget extends StatelessWidget {
required this.frozenFiatBalance,
required this.currency,
required this.hasAdditionalBalance,
required this.hasSilentPayments,
required this.silentPaymentsScanningActive,
required this.setSilentPaymentsScanning,
super.key,
});
@ -244,6 +256,9 @@ class BalanceRowWidget extends StatelessWidget {
final String frozenFiatBalance;
final CryptoCurrency currency;
final bool hasAdditionalBalance;
final bool hasSilentPayments;
final bool silentPaymentsScanningActive;
final void Function() setSilentPaymentsScanning;
// void _showBalanceDescription(BuildContext context) {
// showPopUp<void>(
@ -339,19 +354,19 @@ class BalanceRowWidget extends StatelessWidget {
height: 40,
width: 40,
displayOnError: Container(
height: 30.0,
width: 30.0,
child: Center(
child: Text(
currency.title.substring(0, min(currency.title.length, 2)),
style: TextStyle(fontSize: 11),
),
),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey.shade400,
),
height: 30.0,
width: 30.0,
child: Center(
child: Text(
currency.title.substring(0, min(currency.title.length, 2)),
style: TextStyle(fontSize: 11),
),
),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey.shade400,
),
),
),
const SizedBox(height: 10),
Text(
@ -410,9 +425,7 @@ class BalanceRowWidget extends StatelessWidget {
fontSize: 20,
fontFamily: 'Lato',
fontWeight: FontWeight.w400,
color: Theme.of(context)
.extension<BalancePageTheme>()!
.balanceAmountColor,
color: Theme.of(context).extension<BalancePageTheme>()!.balanceAmountColor,
height: 1,
),
maxLines: 1,
@ -476,6 +489,37 @@ class BalanceRowWidget extends StatelessWidget {
),
],
),
if (hasSilentPayments) ...[
Padding(
padding: const EdgeInsets.only(right: 8, top: 8),
child: Divider(
color: Theme.of(context).extension<BalancePageTheme>()!.labelTextColor,
thickness: 1,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AutoSizeText(
S.of(context).silent_payments_scanning,
style: TextStyle(
fontSize: 14,
fontFamily: 'Lato',
fontWeight: FontWeight.w400,
color: Theme.of(context).extension<BalancePageTheme>()!.assetTitleColor,
height: 1,
),
maxLines: 1,
textAlign: TextAlign.center,
),
Padding(
padding: const EdgeInsets.only(right: 8),
child: StandardSwitch(
value: silentPaymentsScanningActive, onTaped: setSilentPaymentsScanning),
)
],
),
]
],
),
),

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/entities/sort_balance_types.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
@ -45,6 +46,8 @@ abstract class BalanceViewModelBase with Store {
: isReversing = false,
isShowCard = appStore.wallet!.walletInfo.isShowIntroCakePayCard,
wallet = appStore.wallet! {
silentPaymentsScanningActive = hasSilentPayments && bitcoin!.getScanningActive(wallet);
reaction((_) => appStore.wallet, _onWalletChange);
}
@ -60,6 +63,20 @@ abstract class BalanceViewModelBase with Store {
@observable
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet;
@computed
bool get hasSilentPayments => wallet.type == WalletType.bitcoin;
@observable
bool silentPaymentsScanningActive = false;
@action
void setSilentPaymentsScanning(bool active) {
if (hasSilentPayments) {
bitcoin!.setScanningActive(wallet, active);
silentPaymentsScanningActive = active;
}
}
@computed
double get price {
final price = fiatConvertationStore.prices[appStore.wallet!.currency];

View file

@ -610,6 +610,7 @@
"sign_up": "اشتراك",
"signTransaction": " ﺔﻠﻣﺎﻌﻤﻟﺍ ﻊﻴﻗﻮﺗ",
"signup_for_card_accept_terms": "قم بالتسجيل للحصول على البطاقة وقبول الشروط.",
"silent_payments_scanning": "المدفوعات الصامتة المسح الضوئي",
"slidable": "قابل للانزلاق",
"sort_by": "ترتيب حسب",
"spend_key_private": "مفتاح الإنفاق (خاص)",

View file

@ -610,6 +610,7 @@
"sign_up": "Регистрация",
"signTransaction": "Подпишете транзакция",
"signup_for_card_accept_terms": "Регистрайте се за картата и приемете условията.",
"silent_payments_scanning": "Безшумни плащания за сканиране",
"slidable": "Плъзгащ се",
"sort_by": "Сортирай по",
"spend_key_private": "Spend key (таен)",

View file

@ -610,6 +610,7 @@
"sign_up": "Registrovat se",
"signTransaction": "Podepsat transakci",
"signup_for_card_accept_terms": "Zaregistrujte se pro kartu a souhlaste s podmínkami.",
"silent_payments_scanning": "Skenování tichých plateb",
"slidable": "Posuvné",
"sort_by": "Seřazeno podle",
"spend_key_private": "Klíč pro platby (soukromý)",

View file

@ -611,6 +611,7 @@
"sign_up": "Anmelden",
"signTransaction": "Transaktion unterzeichnen",
"signup_for_card_accept_terms": "Melden Sie sich für die Karte an und akzeptieren Sie die Bedingungen.",
"silent_payments_scanning": "Stille Zahlungen scannen",
"slidable": "Verschiebbar",
"sort_by": "Sortiere nach",
"spend_key_private": "Spend Key (geheim)",

View file

@ -610,6 +610,7 @@
"sign_up": "Sign Up",
"signTransaction": "Sign Transaction",
"signup_for_card_accept_terms": "Sign up for the card and accept the terms.",
"silent_payments_scanning": "Silent Payments Scanning",
"slidable": "Slidable",
"sort_by": "Sort by",
"spend_key_private": "Spend key (private)",

View file

@ -611,6 +611,7 @@
"sign_up": "Registrarse",
"signTransaction": "Firmar transacción",
"signup_for_card_accept_terms": "Regístrese para obtener la tarjeta y acepte los términos.",
"silent_payments_scanning": "Escaneo de pagos silenciosos",
"slidable": "deslizable",
"sort_by": "Ordenar por",
"spend_key_private": "Spend clave (privado)",

View file

@ -610,6 +610,7 @@
"sign_up": "S'inscrire",
"signTransaction": "Signer une transaction",
"signup_for_card_accept_terms": "Inscrivez-vous pour la carte et acceptez les conditions.",
"silent_payments_scanning": "Payments silencieux SCANNING",
"slidable": "Glissable",
"sort_by": "Trier par",
"spend_key_private": "Clef de dépense (spend key) (privée)",

View file

@ -612,6 +612,7 @@
"sign_up": "Shiga",
"signTransaction": "Sa hannu Ma'amala",
"signup_for_card_accept_terms": "Yi rajista don katin kuma karɓi sharuɗɗan.",
"silent_payments_scanning": "Silent biya scanning",
"slidable": "Mai iya zamewa",
"sort_by": "Kasa",
"spend_key_private": "makullin biya (maɓallin kalmar sirri)",

View file

@ -612,6 +612,7 @@
"sign_up": "साइन अप करें",
"signTransaction": "लेन-देन पर हस्ताक्षर करें",
"signup_for_card_accept_terms": "कार्ड के लिए साइन अप करें और शर्तें स्वीकार करें।",
"silent_payments_scanning": "मूक भुगतान स्कैनिंग",
"slidable": "फिसलने लायक",
"sort_by": "इसके अनुसार क्रमबद्ध करें",
"spend_key_private": "खर्च करना (निजी)",

View file

@ -610,6 +610,7 @@
"sign_up": "Prijavite se",
"signTransaction": "Potpišite transakciju",
"signup_for_card_accept_terms": "Prijavite se za karticu i prihvatite uvjete.",
"silent_payments_scanning": "Skeniranje tihih plaćanja",
"slidable": "Klizna",
"sort_by": "Poredaj po",
"spend_key_private": "Spend key (privatni)",

View file

@ -613,6 +613,7 @@
"sign_up": "Daftar",
"signTransaction": "Tandatangani Transaksi",
"signup_for_card_accept_terms": "Daftar untuk kartu dan terima syarat dan ketentuan.",
"silent_payments_scanning": "Pemindaian pembayaran diam",
"slidable": "Dapat digeser",
"sort_by": "Sortir dengan",
"spend_key_private": "Kunci pengeluaran (privat)",

View file

@ -612,6 +612,7 @@
"sign_up": "Registrati",
"signTransaction": "Firma la transazione",
"signup_for_card_accept_terms": "Registrati per la carta e accetta i termini.",
"silent_payments_scanning": "Scansione di pagamenti silenziosi",
"slidable": "Scorrevole",
"sort_by": "Ordina per",
"spend_key_private": "Chiave di spesa (privata)",

View file

@ -611,6 +611,7 @@
"sign_up": "サインアップ",
"signTransaction": "トランザクションに署名する",
"signup_for_card_accept_terms": "カードにサインアップして、利用規約に同意してください。",
"silent_payments_scanning": "サイレントペイメントスキャン",
"slidable": "スライド可能",
"sort_by": "並び替え",
"spend_key_private": "キーを使う (プライベート)",
@ -804,4 +805,4 @@
"you_will_get": "に変換",
"you_will_send": "から変換",
"yy": "YY"
}
}

View file

@ -611,6 +611,7 @@
"sign_up": "가입",
"signTransaction": "거래 서명",
"signup_for_card_accept_terms": "카드에 가입하고 약관에 동의합니다.",
"silent_payments_scanning": "조용한 지불 스캔",
"slidable": "슬라이딩 가능",
"sort_by": "정렬 기준",
"spend_key_private": "지출 키 (은밀한)",
@ -805,4 +806,4 @@
"you_will_send": "다음에서 변환",
"YY": "YY",
"yy": "YY"
}
}

View file

@ -610,6 +610,7 @@
"sign_up": "ဆိုင်းအပ်",
"signTransaction": "ငွေလွှဲဝင်ပါ။",
"signup_for_card_accept_terms": "ကတ်အတွက် စာရင်းသွင်းပြီး စည်းကမ်းချက်များကို လက်ခံပါ။",
"silent_payments_scanning": "အသံတိတ်ငွေပေးချေမှု scanning",
"slidable": "လျှောချနိုင်သည်။",
"sort_by": "အလိုက်စဥ်သည်",
"spend_key_private": "သော့သုံးရန် (သီးသန့်)",
@ -803,4 +804,4 @@
"you_will_get": "သို့ပြောင်းပါ။",
"you_will_send": "မှပြောင်းပါ။",
"yy": "YY"
}
}

View file

@ -610,6 +610,7 @@
"sign_up": "Aanmelden",
"signTransaction": "Transactie ondertekenen",
"signup_for_card_accept_terms": "Meld je aan voor de kaart en accepteer de voorwaarden.",
"silent_payments_scanning": "Stille betalingen scannen",
"slidable": "Verschuifbaar",
"sort_by": "Sorteer op",
"spend_key_private": "Sleutel uitgeven (privaat)",
@ -804,4 +805,4 @@
"you_will_get": "Converteren naar",
"you_will_send": "Converteren van",
"yy": "JJ"
}
}

View file

@ -610,6 +610,7 @@
"sign_up": "Zarejestruj się",
"signTransaction": "Podpisz transakcję",
"signup_for_card_accept_terms": "Zarejestruj się, aby otrzymać kartę i zaakceptuj warunki.",
"silent_payments_scanning": "Skanowanie cichych płatności",
"slidable": "Przesuwne",
"sort_by": "Sortuj według",
"spend_key_private": "Klucz prywatny",
@ -803,4 +804,4 @@
"you_will_get": "Konwertuj na",
"you_will_send": "Konwertuj z",
"yy": "RR"
}
}

View file

@ -612,6 +612,7 @@
"sign_up": "Inscrever-se",
"signTransaction": "Assinar transação",
"signup_for_card_accept_terms": "Cadastre-se no cartão e aceite os termos.",
"silent_payments_scanning": "Scanear Pagamentos Silenciosos",
"slidable": "Deslizável",
"sort_by": "Ordenar por",
"spend_key_private": "Chave de gastos (privada)",

View file

@ -611,6 +611,7 @@
"sign_up": "Зарегистрироваться",
"signTransaction": "Подписать транзакцию",
"signup_for_card_accept_terms": "Подпишитесь на карту и примите условия.",
"silent_payments_scanning": "Сканирование безмолвных платежей",
"slidable": "Скользящий",
"sort_by": "Сортировать по",
"spend_key_private": "Приватный ключ траты",
@ -804,4 +805,4 @@
"you_will_get": "Конвертировать в",
"you_will_send": "Конвертировать из",
"yy": "ГГ"
}
}

View file

@ -610,6 +610,7 @@
"sign_up": "สมัครสมาชิก",
"signTransaction": "ลงนามในการทำธุรกรรม",
"signup_for_card_accept_terms": "ลงทะเบียนสำหรับบัตรและยอมรับเงื่อนไข",
"silent_payments_scanning": "การสแกนการชำระเงินแบบเงียบ",
"slidable": "เลื่อนได้",
"sort_by": "เรียงตาม",
"spend_key_private": "คีย์จ่าย (ส่วนตัว)",
@ -803,4 +804,4 @@
"you_will_get": "แปลงเป็น",
"you_will_send": "แปลงจาก",
"yy": "ปี"
}
}

View file

@ -610,6 +610,7 @@
"sign_up": "Mag -sign up",
"signTransaction": "Mag-sign Transaksyon",
"signup_for_card_accept_terms": "Mag -sign up para sa card at tanggapin ang mga termino.",
"silent_payments_scanning": "Tahimik na pag -scan ng mga pagbabayad",
"slidable": "Slidable",
"sort_by": "Pag -uri -uriin sa pamamagitan ng",
"spend_key_private": "Gumastos ng susi (pribado)",
@ -803,4 +804,4 @@
"you_will_get": "Mag -convert sa",
"you_will_send": "I -convert mula sa",
"yy": "YY"
}
}

View file

@ -610,6 +610,7 @@
"sign_up": "Kaydol",
"signTransaction": "İşlem İmzala",
"signup_for_card_accept_terms": "Kart için kaydol ve koşulları kabul et.",
"silent_payments_scanning": "Sessiz Ödemeler Taraması",
"slidable": "kaydırılabilir",
"sort_by": "Göre sırala",
"spend_key_private": "Harcama anahtarı (özel)",
@ -803,4 +804,4 @@
"you_will_get": "Biçimine dönüştür:",
"you_will_send": "Biçiminden dönüştür:",
"yy": "YY"
}
}

View file

@ -611,6 +611,7 @@
"sign_up": "Зареєструватися",
"signTransaction": "Підписати транзакцію",
"signup_for_card_accept_terms": "Зареєструйтеся на картку та прийміть умови.",
"silent_payments_scanning": "Мовчазні платежі сканування",
"slidable": "Розсувний",
"sort_by": "Сортувати за",
"spend_key_private": "Приватний ключ витрати",
@ -804,4 +805,4 @@
"you_will_get": "Конвертувати в",
"you_will_send": "Конвертувати з",
"yy": "YY"
}
}

View file

@ -612,6 +612,7 @@
"sign_up": "سائن اپ",
"signTransaction": "۔ﮟﯾﺮﮐ ﻂﺨﺘﺳﺩ ﺮﭘ ﻦﯾﺩ ﻦﯿﻟ",
"signup_for_card_accept_terms": "کارڈ کے لیے سائن اپ کریں اور شرائط کو قبول کریں۔",
"silent_payments_scanning": "خاموش ادائیگی اسکیننگ",
"slidable": "سلائیڈ ایبل",
"sort_by": "ترتیب دیں",
"spend_key_private": "خرچ کی کلید (نجی)",
@ -805,4 +806,4 @@
"you_will_get": "میں تبدیل کریں۔",
"you_will_send": "سے تبدیل کریں۔",
"yy": "YY"
}
}

View file

@ -611,6 +611,7 @@
"sign_up": "Forúkọ sílẹ̀",
"signTransaction": "Wole Idunadura",
"signup_for_card_accept_terms": "Ẹ f'orúkọ sílẹ̀ láti gba káàdì àti àjọrò.",
"silent_payments_scanning": "Awọn sisanwo ipalọlọ",
"slidable": "Slidable",
"sort_by": "Sa pelu",
"spend_key_private": "Kọ́kọ́rọ́ sísan (àdáni)",
@ -804,4 +805,4 @@
"you_will_get": "Ṣe pàṣípààrọ̀ sí",
"you_will_send": "Ṣe pàṣípààrọ̀ láti",
"yy": "Ọd"
}
}

View file

@ -610,6 +610,7 @@
"sign_up": "注册",
"signTransaction": "签署交易",
"signup_for_card_accept_terms": "注册卡并接受条款。",
"silent_payments_scanning": "无声付款扫描",
"slidable": "可滑动",
"sort_by": "排序方式",
"spend_key_private": "Spend 密钥 (私钥)",
@ -803,4 +804,4 @@
"you_will_get": "转换到",
"you_will_send": "转换自",
"yy": "YY"
}
}