Skip to content

Commit

Permalink
Merge pull request #126 from etherspot/fix/cast-chain-id-as-number
Browse files Browse the repository at this point in the history
cast chain ids as number
  • Loading branch information
poocart authored Mar 20, 2024
2 parents 9f57aad + 13b5028 commit d91c37b
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 14 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.9.2] - 2024-03-20

### Breaking Changes
- Cast `chainId` to number throughout the library to make it failproof for string chain IDs

## [0.9.1] - 2024-03-16

### Breaking 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.9.1",
"version": "0.9.2",
"main": "dist/cjs/index.js",
"scripts": {
"rollup:build": "NODE_OPTIONS=--max-old-space-size=8192 rollup -c",
Expand Down
2 changes: 1 addition & 1 deletion src/components/EtherspotTransactionKit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const EtherspotTransactionKit = ({
}: EtherspotTransactionKitProps) => (
<EtherspotContextProvider
provider={provider}
chainId={chainId}
chainId={+chainId} // cast to make it less failproof when passed as string, i.e. from env file
accountTemplate={accountTemplate}
projectKey={projectKey}
>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useEtherspotAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const useEtherspotAssets = (chainId?: number): IEtherspotAssetsHook => {
const dataService = getDataService();
assets = await dataService.getTokenListTokens({
name: 'EtherspotPopularTokens',
chainId: assetsChainId,
chainId: +assetsChainId,
});
} catch (e) {
console.warn(
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useEtherspotBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const useEtherspotBalances = (chainId?: number): IEtherspotBalancesHook => {
const dataService = getDataService();
const { items } = await dataService.getAccountBalances({
account: balancesForAccount,
chainId: balancesChainId,
chainId: +balancesChainId,
});

return items;
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useEtherspotHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const useEtherspotHistory = (chainId: number): IEtherspotHistoryHook => {
// @ts-ignore
({ items: transactions } = await dataService.getTransactions({
account: transactionsForAccount,
chainId: historyChainId,
chainId: +historyChainId,
}));
} catch (e) {

Expand All @@ -56,7 +56,7 @@ const useEtherspotHistory = (chainId: number): IEtherspotHistoryHook => {
const getAccountTransaction = async (hash: string): Promise<Transaction | undefined> => {
try {
const dataService = getDataService();
return dataService.getTransaction({ hash, chainId: historyChainId });
return dataService.getTransaction({ hash, chainId: +historyChainId });
} catch (e) {
console.warn(
`Sorry, an error occurred whilst trying to fetch the transaction`
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useEtherspotNfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const useEtherspotNfts = (chainId?: number): IEtherspotNftsHook => {
const dataService = getDataService();
const { items } = await dataService.getNftList({
account: nftsForAccount,
chainId: nftsChainId,
chainId: +nftsChainId,
});

return items;
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useEtherspotPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ const useEtherspotPrices = (chainId?: number): IEtherspotPricesHook => {
}, [chainId, etherspotChainId]);

const getPrice = async (assetAddress: string, assetChainId: number = defaultChainId) => {
const [price] = await getPrices([assetAddress], assetChainId);
const [price] = await getPrices([assetAddress], +assetChainId);
return price;
}

const getPrices = async (assetAddresses: string[], assetsChainId: number = defaultChainId) => {
try {
const dataService = getDataService();
const result = await dataService.fetchExchangeRates({
chainId: assetsChainId,
chainId: +assetsChainId,
tokens: assetAddresses,
});

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useEtherspotSwaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const useEtherspotSwaps = (chainId?: number): IEtherspotSwapsHook => {
if (toChainId && toChainId !== chainId) {
try {
const { items: offers } = await dataService.getAdvanceRoutesLiFi({
fromChainId: swapsChainId,
fromChainId: +swapsChainId,
toChainId,
fromAmount,
fromTokenAddress,
Expand All @@ -111,7 +111,7 @@ const useEtherspotSwaps = (chainId?: number): IEtherspotSwapsHook => {
fromTokenAddress,
toTokenAddress,
fromAddress: fromAccount,
fromChainId: swapsChainId,
fromChainId: +swapsChainId,
});
return { type: 'same-chain', offers };
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/EtherspotContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const EtherspotContextProvider = ({

// @ts-ignore
const sdkForChain = new PrimeSdk(mappedProvider ?? provider, {
chainId: sdkChainId,
chainId: +sdkChainId,
etherspotBundlerApiKey: projectKey ?? ('__ETHERSPOT_PROJECT_KEY__' || undefined),
factoryWallet: accountTemplate as Factory,
});
Expand Down

0 comments on commit d91c37b

Please sign in to comment.