Skip to content

Commit

Permalink
Merge pull request #103 from etherspot/feature/local-instabce-cached-…
Browse files Browse the repository at this point in the history
…address

Feature/local instance cached address
  • Loading branch information
poocart authored Feb 22, 2024
2 parents 691fa40 + 60b438f commit 1c6756e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.7.6] - 2024-02-21

### Added Changes
- Added Etherspot Prime SDK computed account pull from SDK instance state

## [0.7.5] - 2024-02-21

### Added Changes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@etherspot/transaction-kit",
"description": "React Etherspot Transaction Kit",
"version": "0.7.5",
"version": "0.7.6",
"main": "dist/cjs/index.js",
"scripts": {
"rollup:build": "NODE_OPTIONS=--max-old-space-size=8192 rollup -c",
Expand Down
26 changes: 22 additions & 4 deletions src/hooks/useWalletAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,31 @@ const useWalletAddress = (walletType: IWalletType = 'etherspot-prime', chainId?:
const updateAccountAddress = async () => {
const etherspotPrimeSdk = await getSdk(walletAddressChainId);

let newAccountAddress;

try {
const newAccountAddress = await etherspotPrimeSdk.getCounterFactualAddress();
if (!shouldUpdate) return;
setAccountAddress(newAccountAddress);
/**
* 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
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 1c6756e

Please sign in to comment.