Skip to content

Commit fb3f64f

Browse files
authored
fix: Restore backup bug fix and clean up sol error message (#1614)
* fix: Restore backup bug fix and clean up sol error message * fix: Add async await to reinitialize
1 parent 102139b commit fb3f64f

29 files changed

+95
-9
lines changed

lib/reactions/bootstrap.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ Future<void> bootstrap(GlobalKey<NavigatorState> navigatorKey) async {
2121
final settingsStore = getIt.get<SettingsStore>();
2222
final fiatConversionStore = getIt.get<FiatConversionStore>();
2323

24-
final currentWalletName = getIt
25-
.get<SharedPreferences>()
26-
.getString(PreferencesKey.currentWalletName);
24+
final currentWalletName =
25+
getIt.get<SharedPreferences>().getString(PreferencesKey.currentWalletName);
2726
if (currentWalletName != null) {
2827
authenticationStore.installed();
2928
}
3029

31-
startAuthenticationStateChange(authenticationStore, navigatorKey);
32-
startCurrentWalletChangeReaction(
33-
appStore, settingsStore, fiatConversionStore);
30+
await startAuthenticationStateChange(authenticationStore, navigatorKey);
31+
startCurrentWalletChangeReaction(appStore, settingsStore, fiatConversionStore);
3432
startCurrentFiatChangeReaction(appStore, settingsStore, fiatConversionStore);
3533
startCurrentFiatApiModeChangeReaction(appStore, settingsStore, fiatConversionStore);
3634
startOnCurrentNodeChangeReaction(appStore);

lib/reactions/on_authentication_state_change.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@ ReactionDisposer? _onAuthenticationStateChange;
1313
dynamic loginError;
1414
StreamController<dynamic> authenticatedErrorStreamController = StreamController<dynamic>();
1515

16-
void startAuthenticationStateChange(
17-
AuthenticationStore authenticationStore, GlobalKey<NavigatorState> navigatorKey) {
16+
Future<void> reInitializeStreamController() async {
17+
if (!authenticatedErrorStreamController.isClosed) {
18+
await authenticatedErrorStreamController.close();
19+
}
20+
21+
authenticatedErrorStreamController = StreamController<dynamic>();
22+
}
23+
24+
Future<void> startAuthenticationStateChange(
25+
AuthenticationStore authenticationStore,
26+
GlobalKey<NavigatorState> navigatorKey,
27+
) async {
28+
await reInitializeStreamController();
29+
1830
authenticatedErrorStreamController.stream.listen((event) {
1931
if (authenticationStore.state == AuthenticationState.allowed) {
2032
ExceptionHandler.showError(event.toString(), delayInSeconds: 3);

lib/view_model/send/send_view_model.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,30 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
583583
String errorMessage = error.toString();
584584

585585
if (walletType == WalletType.solana) {
586+
if (errorMessage.contains('insufficient lamports')) {
587+
double solValueNeeded = 0.0;
588+
589+
// Regular expression to match the number after "need". This shows the exact lamports the user needs to perform the transaction.
590+
RegExp regExp = RegExp(r'need (\d+)');
591+
592+
// Find the match
593+
Match? match = regExp.firstMatch(errorMessage);
594+
595+
if (match != null) {
596+
String neededAmount = match.group(1)!;
597+
final lamportsNeeded = int.tryParse(neededAmount);
598+
599+
// 5000 lamport used here is the constant for sending a transaction on solana
600+
int lamportsPerSol = 1000000000;
601+
602+
solValueNeeded =
603+
lamportsNeeded != null ? ((lamportsNeeded + 5000) / lamportsPerSol) : 0.0;
604+
return S.current.insufficient_lamports(solValueNeeded.toString());
605+
} else {
606+
print("No match found.");
607+
return S.current.insufficient_lamport_for_tx;
608+
}
609+
}
586610
if (errorMessage.contains('insufficient funds for rent')) {
587611
return S.current.insufficientFundsForRentError;
588612
}

res/values/strings_ar.arb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@
338338
"incoming": "الواردة",
339339
"incorrect_seed": "النص الذي تم إدخاله غير صالح.",
340340
"inputs": "المدخلات",
341+
"insufficient_lamport_for_tx": "ليس لديك ما يكفي من SOL لتغطية المعاملة ورسوم المعاملات الخاصة بها. يرجى إضافة المزيد من SOL إلى محفظتك أو تقليل كمية SOL التي ترسلها.",
342+
"insufficient_lamports": "ليس لديك ما يكفي من SOL لتغطية المعاملة ورسوم المعاملات الخاصة بها. تحتاج على الأقل ${solValueNeeded} sol. يرجى إضافة المزيد من sol إلى محفظتك أو تقليل مبلغ sol الذي ترسله",
341343
"insufficientFundsForRentError": "ليس لديك ما يكفي من SOL لتغطية رسوم المعاملة والإيجار للحساب. يرجى إضافة المزيد من sol إلى محفظتك أو تقليل مبلغ sol الذي ترسله",
342344
"introducing_cake_pay": "نقدم لكم Cake Pay!",
343345
"invalid_input": "مدخل غير صالح",

res/values/strings_bg.arb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@
338338
"incoming": "Входящи",
339339
"incorrect_seed": "Въведеният текст е невалиден.",
340340
"inputs": "Входове",
341+
"insufficient_lamport_for_tx": "Нямате достатъчно SOL, за да покриете транзакцията и таксата му за транзакция. Моля, добавете повече SOL към портфейла си или намалете сумата на SOL, която изпращате.",
342+
"insufficient_lamports": "Нямате достатъчно SOL, за да покриете транзакцията и таксата му за транзакция. Имате нужда от поне ${solValueNeeded} sol. Моля, добавете повече SOL към портфейла си или намалете сумата на SOL, която изпращате",
341343
"insufficientFundsForRentError": "Нямате достатъчно SOL, за да покриете таксата за транзакцията и наемането на сметката. Моля, добавете повече SOL към портфейла си или намалете сумата на SOL, която изпращате",
342344
"introducing_cake_pay": "Запознайте се с Cake Pay!",
343345
"invalid_input": "Невалиден вход",

res/values/strings_cs.arb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@
338338
"incoming": "Příchozí",
339339
"incorrect_seed": "Zadaný text není správný.",
340340
"inputs": "Vstupy",
341+
"insufficient_lamport_for_tx": "Nemáte dostatek SOL na pokrytí transakce a jejího transakčního poplatku. Laskavě přidejte do své peněženky více solu nebo snižte množství Sol, kterou odesíláte.",
342+
"insufficient_lamports": "Nemáte dostatek SOL na pokrytí transakce a jejího transakčního poplatku. Potřebujete alespoň ${solValueNeeded} sol. Laskavě přidejte do své peněženky více SOL nebo snižte množství Sol, kterou odesíláte",
341343
"insufficientFundsForRentError": "Nemáte dostatek SOL na pokrytí transakčního poplatku a nájemného za účet. Laskavě přidejte do své peněženky více SOL nebo snižte množství Sol, kterou odesíláte",
342344
"introducing_cake_pay": "Představujeme Cake Pay!",
343345
"invalid_input": "Neplatný vstup",

res/values/strings_de.arb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@
338338
"incoming": "Eingehend",
339339
"incorrect_seed": "Der eingegebene Text ist ungültig.",
340340
"inputs": "Eingänge",
341+
"insufficient_lamport_for_tx": "Sie haben nicht genug SOL, um die Transaktion und ihre Transaktionsgebühr abzudecken. Bitte fügen Sie Ihrer Brieftasche mehr Sol hinzu oder reduzieren Sie die SO -Menge, die Sie senden.",
342+
"insufficient_lamports": "Sie haben nicht genug SOL, um die Transaktion und ihre Transaktionsgebühr abzudecken. Sie brauchen mindestens ${solValueNeeded} Sol. Bitte fügen Sie mehr Sol zu Ihrer Wallet hinzu oder reduzieren Sie den von Ihnen gesendeten Sol -Betrag",
341343
"insufficientFundsForRentError": "Sie haben nicht genug SOL, um die Transaktionsgebühr und die Miete für das Konto zu decken. Bitte fügen Sie mehr Sol zu Ihrer Brieftasche hinzu oder reduzieren Sie den von Ihnen gesendeten Sol -Betrag",
342344
"introducing_cake_pay": "Einführung von Cake Pay!",
343345
"invalid_input": "Ungültige Eingabe",

res/values/strings_en.arb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@
338338
"incoming": "Incoming",
339339
"incorrect_seed": "The text entered is not valid.",
340340
"inputs": "Inputs",
341+
"insufficient_lamport_for_tx": "You do not have enough SOL to cover the transaction and its transaction fee. Kindly add more SOL to your wallet or reduce the SOL amount you\\'re sending.",
342+
"insufficient_lamports": "You do not have enough SOL to cover the transaction and its transaction fee. You need at least ${solValueNeeded} SOL. Kindly add more SOL to your wallet or reduce the SOL amount you\\'re sending",
341343
"insufficientFundsForRentError": "You do not have enough SOL to cover the transaction fee and rent for the account. Kindly add more SOL to your wallet or reduce the SOL amount you\\'re sending",
342344
"introducing_cake_pay": "Introducing Cake Pay!",
343345
"invalid_input": "Invalid input",

res/values/strings_es.arb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@
338338
"incoming": "Entrante",
339339
"incorrect_seed": "El texto ingresado no es válido.",
340340
"inputs": "Entradas",
341+
"insufficient_lamport_for_tx": "No tiene suficiente SOL para cubrir la transacción y su tarifa de transacción. Por favor, agregue más SOL a su billetera o reduzca la cantidad de sol que está enviando.",
342+
"insufficient_lamports": "No tiene suficiente SOL para cubrir la transacción y su tarifa de transacción. Necesita al menos ${solValueNeeded} sol. Por favor, agregue más sol a su billetera o reduzca la cantidad de sol que está enviando",
341343
"insufficientFundsForRentError": "No tiene suficiente SOL para cubrir la tarifa de transacción y alquilar para la cuenta. Por favor, agregue más sol a su billetera o reduzca la cantidad de sol que está enviando",
342344
"introducing_cake_pay": "¡Presentamos Cake Pay!",
343345
"invalid_input": "Entrada inválida",

res/values/strings_fr.arb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@
338338
"incoming": "Entrantes",
339339
"incorrect_seed": "Le texte entré est invalide.",
340340
"inputs": "Contributions",
341+
"insufficient_lamport_for_tx": "Vous n'avez pas assez de sol pour couvrir la transaction et ses frais de transaction. Veuillez ajouter plus de Sol à votre portefeuille ou réduire la quantité de Sol que vous envoyez.",
342+
"insufficient_lamports": "Vous n'avez pas assez de sol pour couvrir la transaction et ses frais de transaction. Vous avez besoin d'au moins ${solValueNeeded} sol. Veuillez ajouter plus de Sol à votre portefeuille ou réduire la quantité de sol que vous envoyez",
341343
"insufficientFundsForRentError": "Vous n'avez pas assez de SOL pour couvrir les frais de transaction et le loyer pour le compte. Veuillez ajouter plus de Sol à votre portefeuille ou réduire la quantité de sol que vous envoyez",
342344
"introducing_cake_pay": "Présentation de Cake Pay !",
343345
"invalid_input": "Entrée invalide",

0 commit comments

Comments
 (0)