Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/local instance cached address #103

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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