Skip to content

Commit

Permalink
added additional exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
poocart committed Feb 22, 2024
1 parent 0bfcf08 commit 60b438f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/hooks/useWalletAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,31 @@ const useWalletAddress = (walletType: IWalletType = 'etherspot-prime', chainId?:
const updateAccountAddress = async () => {
const etherspotPrimeSdk = await getSdk(walletAddressChainId);

let newAccountAddress;

try {
/**
* Currently `etherspotWallet` is marked as private on SDK, let's ignore until SDK team fixes it
* Reference – https://github.com/etherspot/etherspot-prime-sdk/blob/master/src/sdk/sdk.ts#L31
*/
// @ts-ignore
const storedAddress = etherspotPrimeSdk?.etherspotWallet?.accountAddress;
const newAccountAddress = storedAddress ?? await etherspotPrimeSdk.getCounterFactualAddress();
if (!shouldUpdate) return;
setAccountAddress(newAccountAddress);
// @ts-ignore
newAccountAddress = etherspotPrimeSdk?.etherspotWallet?.accountAddress;
} catch (e) {
console.warn(`Unable to get wallet address for etherspot-prime type for chainId ID ${walletAddressChainId}.`, e);
console.warn(`Unable to get wallet address from SDK state for etherspot-prime type for chainId ID ${walletAddressChainId}.`, e);
}

// if were unable to get wallet address from SDK state, try to get using getCounterFactualAddress
if (!newAccountAddress) {
try {
newAccountAddress = await etherspotPrimeSdk.getCounterFactualAddress();
} catch (e) {
console.warn(`Unable to get wallet address for etherspot-prime type for chainId ID ${walletAddressChainId}.`, e);
}
}

if (!newAccountAddress || !shouldUpdate) return;

setAccountAddress(newAccountAddress);
}

updateAccountAddress();
Expand Down

0 comments on commit 60b438f

Please sign in to comment.