FIX: remove checks before invoking getAddressAsync

This commit is contained in:
Gabriele Genta 2021-07-14 14:40:19 +02:00
parent ce1027a2ce
commit c56acd5e54
3 changed files with 18 additions and 24 deletions

View file

@ -126,24 +126,22 @@ function WatchConnectivity() {
for (const wallet of wallets) { for (const wallet of wallets) {
let receiveAddress; let receiveAddress;
if (wallet.getAddressAsync) { if (wallet.chain === Chain.ONCHAIN) {
if (wallet.chain === Chain.ONCHAIN) { try {
try { receiveAddress = await wallet.getAddressAsync();
receiveAddress = await wallet.getAddressAsync(); } catch (_) {}
} catch (_) {} if (!receiveAddress) {
if (!receiveAddress) { // either sleep expired or getAddressAsync threw an exception
// either sleep expired or getAddressAsync threw an exception receiveAddress = wallet._getExternalAddressByIndex(wallet.next_free_address_index);
receiveAddress = wallet._getExternalAddressByIndex(wallet.next_free_address_index); }
} } else if (wallet.chain === Chain.OFFCHAIN) {
} else if (wallet.chain === Chain.OFFCHAIN) { try {
try { await wallet.getAddressAsync();
await wallet.getAddressAsync(); receiveAddress = wallet.getAddress();
receiveAddress = wallet.getAddress(); } catch (_) {}
} catch (_) {} if (!receiveAddress) {
if (!receiveAddress) { // either sleep expired or getAddressAsync threw an exception
// either sleep expired or getAddressAsync threw an exception receiveAddress = wallet.getAddress();
receiveAddress = wallet.getAddress();
}
} }
} }
const transactions = wallet.getTransactions(10); const transactions = wallet.getTransactions(10);

View file

@ -216,7 +216,7 @@ const ReceiveDetails = () => {
setAddressBIP21Encoded(address); setAddressBIP21Encoded(address);
await Notifications.tryToObtainPermissions(); await Notifications.tryToObtainPermissions();
Notifications.majorTomToGroundControl([address], [], []); Notifications.majorTomToGroundControl([address], [], []);
} else if (wallet.getAddressAsync) { } else {
if (wallet.chain === Chain.ONCHAIN) { if (wallet.chain === Chain.ONCHAIN) {
try { try {
newAddress = await Promise.race([wallet.getAddressAsync(), sleep(1000)]); newAddress = await Promise.race([wallet.getAddressAsync(), sleep(1000)]);
@ -244,10 +244,6 @@ const ReceiveDetails = () => {
setAddressBIP21Encoded(newAddress); setAddressBIP21Encoded(newAddress);
await Notifications.tryToObtainPermissions(); await Notifications.tryToObtainPermissions();
Notifications.majorTomToGroundControl([newAddress], [], []); Notifications.majorTomToGroundControl([newAddress], [], []);
} else if (wallet.getAddress) {
setAddressBIP21Encoded(wallet.getAddress());
await Notifications.tryToObtainPermissions();
Notifications.majorTomToGroundControl([wallet.getAddress()], [], []);
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);

View file

@ -37,7 +37,7 @@ const AOPP = () => {
const wallet = await selectWallet(navigation.navigate, name, false, availableWallets, 'Onchain wallet is required to sign a message'); const wallet = await selectWallet(navigation.navigate, name, false, availableWallets, 'Onchain wallet is required to sign a message');
if (!wallet) return navigation.pop(); if (!wallet) return navigation.pop();
const address = wallet.getAddressAsync ? await wallet.getAddressAsync() : wallet.getAddress(); const address = await wallet.getAddressAsync();
navigation.navigate('SignVerify', { navigation.navigate('SignVerify', {
walletID: wallet.getID(), walletID: wallet.getID(),
address, address,