Skip to content

Commit

Permalink
Fix rare crash on iOS when restoring fails the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Jun 17, 2020
1 parent 2f43603 commit 7cfc25d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
10 changes: 9 additions & 1 deletion App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ class LoadingView extends Component<LoadingProps, LoadingState> {

this.setState({actionButtonsDisabled: true});
setTimeout(async () => {
const error = await RPCModule.restoreWallet(seedPhrase.toLowerCase(), birthday || '0');
let walletBirthday = birthday || '0';
if (parseInt(walletBirthday, 10) < 0) {
walletBirthday = '0';
}
if (isNaN(parseInt(walletBirthday, 10))) {
walletBirthday = '0';
}

const error = await RPCModule.restoreWallet(seedPhrase.toLowerCase(), walletBirthday || '0');
if (!error.startsWith('Error')) {
this.navigateToLoaded();
} else {
Expand Down
4 changes: 3 additions & 1 deletion android/app/src/main/java/com/zecwalletmobile/RPCModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class RPCModule internal constructor(private val reactContext: ReactApplicationC
Base64.encodeToString(saplingSpend, Base64.NO_WRAP))
Log.w("MAIN", seed)

saveWallet()
if (!rseed.startsWith("Error")) {
saveWallet()
}

promise.resolve(rseed)
}
Expand Down
6 changes: 4 additions & 2 deletions ios/RPCModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ -(void) saveWalletInternal {

RCTLogInfo(@"Seed: %@", seedStr);

// Also save the wallet after restore
[self saveWalletInternal];
if (![seedStr hasPrefix:@"Error"]) {
// Also save the wallet after restore
[self saveWalletInternal];
}

resolve(seedStr);
}
Expand Down
5 changes: 4 additions & 1 deletion rust/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ pub fn init_from_b64(server_uri: String, base64_data: String, sapling_output_b64
}
};

let decoded_bytes = decode(&base64_data).unwrap();
let decoded_bytes = match decode(&base64_data) {
Ok(b) => b,
Err(e) => { return format!("Error: Decoding Base64: {}", e); }
};

let lightclient = match LightClient::read_from_buffer(&config, &decoded_bytes[..]) {
Ok(mut l) => {
Expand Down

0 comments on commit 7cfc25d

Please sign in to comment.