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
This commit is contained in:
David Adegoke
2024-08-17 01:21:03 +03:00
committed by GitHub
parent 102139b061
commit fb3f64facf
29 changed files with 95 additions and 9 deletions
+4 -6
View File
@@ -21,16 +21,14 @@ Future<void> bootstrap(GlobalKey<NavigatorState> navigatorKey) async {
final settingsStore = getIt.get<SettingsStore>();
final fiatConversionStore = getIt.get<FiatConversionStore>();
final currentWalletName = getIt
.get<SharedPreferences>()
.getString(PreferencesKey.currentWalletName);
final currentWalletName =
getIt.get<SharedPreferences>().getString(PreferencesKey.currentWalletName);
if (currentWalletName != null) {
authenticationStore.installed();
}
startAuthenticationStateChange(authenticationStore, navigatorKey);
startCurrentWalletChangeReaction(
appStore, settingsStore, fiatConversionStore);
await startAuthenticationStateChange(authenticationStore, navigatorKey);
startCurrentWalletChangeReaction(appStore, settingsStore, fiatConversionStore);
startCurrentFiatChangeReaction(appStore, settingsStore, fiatConversionStore);
startCurrentFiatApiModeChangeReaction(appStore, settingsStore, fiatConversionStore);
startOnCurrentNodeChangeReaction(appStore);
@@ -13,8 +13,20 @@ ReactionDisposer? _onAuthenticationStateChange;
dynamic loginError;
StreamController<dynamic> authenticatedErrorStreamController = StreamController<dynamic>();
void startAuthenticationStateChange(
AuthenticationStore authenticationStore, GlobalKey<NavigatorState> navigatorKey) {
Future<void> reInitializeStreamController() async {
if (!authenticatedErrorStreamController.isClosed) {
await authenticatedErrorStreamController.close();
}
authenticatedErrorStreamController = StreamController<dynamic>();
}
Future<void> startAuthenticationStateChange(
AuthenticationStore authenticationStore,
GlobalKey<NavigatorState> navigatorKey,
) async {
await reInitializeStreamController();
authenticatedErrorStreamController.stream.listen((event) {
if (authenticationStore.state == AuthenticationState.allowed) {
ExceptionHandler.showError(event.toString(), delayInSeconds: 3);
+24
View File
@@ -583,6 +583,30 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
String errorMessage = error.toString();
if (walletType == WalletType.solana) {
if (errorMessage.contains('insufficient lamports')) {
double solValueNeeded = 0.0;
// Regular expression to match the number after "need". This shows the exact lamports the user needs to perform the transaction.
RegExp regExp = RegExp(r'need (\d+)');
// Find the match
Match? match = regExp.firstMatch(errorMessage);
if (match != null) {
String neededAmount = match.group(1)!;
final lamportsNeeded = int.tryParse(neededAmount);
// 5000 lamport used here is the constant for sending a transaction on solana
int lamportsPerSol = 1000000000;
solValueNeeded =
lamportsNeeded != null ? ((lamportsNeeded + 5000) / lamportsPerSol) : 0.0;
return S.current.insufficient_lamports(solValueNeeded.toString());
} else {
print("No match found.");
return S.current.insufficient_lamport_for_tx;
}
}
if (errorMessage.contains('insufficient funds for rent')) {
return S.current.insufficientFundsForRentError;
}