diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 3f96b5c8..c5046e40 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,11 @@ # @tangled3/react +## 1.16.26 + +### Patch Changes + +- fix(useSendTransaction) current account comparison + ## 1.16.25 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index 25cf15fb..2ab1414c 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,7 +1,7 @@ { "name": "@tangled3/react", "private": false, - "version": "1.16.25", + "version": "1.16.26", "type": "module", "license": "MIT", "main": "./src/index.ts", diff --git a/packages/react/src/actions/cosmos/getCosmosToken.ts b/packages/react/src/actions/cosmos/getCosmosToken.ts index a825ba62..c7460ffe 100644 --- a/packages/react/src/actions/cosmos/getCosmosToken.ts +++ b/packages/react/src/actions/cosmos/getCosmosToken.ts @@ -2,7 +2,7 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'; import { maxInt256 } from 'viem'; import { RouterLCDBalancesResponse } from '../../types/cosmos.js'; import { ChainData, ConnectionOrConfig, CosmsosChainType } from '../../types/index.js'; -import { areTokensEqual, formatTokenAddress, isNativeOrFactoryToken } from '../../utils/index.js'; +import { compareStrings, formatTokenAddress, isNativeOrFactoryToken } from '../../utils/index.js'; export const getCosmosTokenMetadata = async ({ token, @@ -17,7 +17,7 @@ export const getCosmosTokenMetadata = async ({ const assetList = registryClient.getChainAssetList(chain.chainName).assets; - const asset = assetList.find((asset) => areTokensEqual(asset.base, token)); + const asset = assetList.find((asset) => compareStrings(asset.base, token)); if (!asset) { throw new Error('Token not found'); diff --git a/packages/react/src/actions/getToken.ts b/packages/react/src/actions/getToken.ts index ffb8a29b..30feae58 100644 --- a/packages/react/src/actions/getToken.ts +++ b/packages/react/src/actions/getToken.ts @@ -5,7 +5,7 @@ import { trc20Abi } from '../constants/abi/trc20.js'; import { ETH_ADDRESS, SOL_ADDRESS, SUI_ADDRESS } from '../constants/index.js'; import { TokenMetadata } from '../hooks/useToken.js'; import { ChainData, ChainId, ChainType, ConnectionOrConfig, GetTokenMetadataParams } from '../types/index.js'; -import { areTokensEqual } from '../utils/index.js'; +import { compareStrings } from '../utils/index.js'; import { getFormattedBalance as getBitcoinBalance } from './bitcoin/balance.js'; import { getCosmosTokenBalanceAndAllowance, getCosmosTokenMetadata } from './cosmos/getCosmosToken.js'; import { getEVMTokenBalanceAndAllowance, getEVMTokenMetadata } from './evm/getEVMToken.js'; @@ -22,7 +22,7 @@ export const getTokenMetadata = async ({ token, chain, config }: GetTokenMetadat // console.log('[Token] configs', { token, chain, config }); // evm chain if (chain?.type === 'evm') { - if (areTokensEqual(token, ETH_ADDRESS)) { + if (compareStrings(token, ETH_ADDRESS)) { return { name: chain.nativeCurrency.name, symbol: chain.nativeCurrency.symbol, @@ -38,7 +38,7 @@ export const getTokenMetadata = async ({ token, chain, config }: GetTokenMetadat } if (chain.type === 'tron') { - if (areTokensEqual(token, ETH_ADDRESS)) { + if (compareStrings(token, ETH_ADDRESS)) { return { ...chain.nativeCurrency, address: ETH_ADDRESS, chainId: chain.id, isNative: true }; } let contractAddress: string = token; @@ -59,7 +59,7 @@ export const getTokenMetadata = async ({ token, chain, config }: GetTokenMetadat } if (chain.type === 'solana') { - if (areTokensEqual(token, SOL_ADDRESS)) { + if (compareStrings(token, SOL_ADDRESS)) { return { ...chain.nativeCurrency, address: SOL_ADDRESS, chainId: chain.id, isNative: true }; } @@ -83,7 +83,7 @@ export const getTokenMetadata = async ({ token, chain, config }: GetTokenMetadat } if (chain.type === 'cosmos') { - if (areTokensEqual(token, ETH_ADDRESS)) { + if (compareStrings(token, ETH_ADDRESS)) { return { ...chain.nativeCurrency, address: ETH_ADDRESS, chainId: chain.id, isNative: true }; } const res = await getCosmosTokenMetadata({ token, chain, getCosmosClient: config.getCosmosClient }); @@ -96,13 +96,13 @@ export const getTokenMetadata = async ({ token, chain, config }: GetTokenMetadat } if (chain.type === 'bitcoin') { - if (areTokensEqual(token, ETH_ADDRESS)) { + if (compareStrings(token, ETH_ADDRESS)) { return { ...chain.nativeCurrency, address: ETH_ADDRESS, chainId: chain.id, isNative: true }; } } if (chain.type === 'sui') { - if (areTokensEqual(token, SUI_ADDRESS)) { + if (compareStrings(token, SUI_ADDRESS)) { return { ...chain.nativeCurrency, address: SUI_ADDRESS, chainId: chain.id, isNative: true }; } @@ -167,7 +167,7 @@ export const getTokenBalanceAndAllowance = (async (params) => { // evm chain if (chain.type === 'evm') { - if (areTokensEqual(token, ETH_ADDRESS)) { + if (compareStrings(token, ETH_ADDRESS)) { const result = { balance: await getBalance(config.wagmiConfig, { address: account as EVMAddress, @@ -181,7 +181,7 @@ export const getTokenBalanceAndAllowance = (async (params) => { } if (chain.type === 'tron') { - if (areTokensEqual(token, ETH_ADDRESS)) { + if (compareStrings(token, ETH_ADDRESS)) { const balance = BigInt(await config.tronWeb.trx.getBalance(account)); const allowance = BigInt(0); return { balance, allowance }; @@ -203,7 +203,7 @@ export const getTokenBalanceAndAllowance = (async (params) => { const accountPbKey = new PublicKey(account); // if asset is native solana token - if (areTokensEqual(token, SOL_ADDRESS)) { + if (compareStrings(token, SOL_ADDRESS)) { const balance = BigInt(await config.solanaConnection.getBalance(accountPbKey)); return { balance, allowance: 0n }; } diff --git a/packages/react/src/hooks/useSendTransaction.ts b/packages/react/src/hooks/useSendTransaction.ts index 102237b4..59b9ed41 100644 --- a/packages/react/src/hooks/useSendTransaction.ts +++ b/packages/react/src/hooks/useSendTransaction.ts @@ -1,6 +1,7 @@ import { useMutation } from '@tanstack/react-query'; import { SendTransactionParams, sendTransactionToChain } from '../actions/sendTransaction.js'; import { ChainData, ChainId } from '../types/index.js'; +import { compareStrings } from '../utils/index.js'; import { useConnectionOrConfig } from './useConnectionOrConfig.js'; import { useCurrentAccount } from './useCurrentAccount.js'; import { useCurrentWallet } from './useCurrentWallet.js'; @@ -50,7 +51,7 @@ export const useSendTransaction = () => { } // check if from address matches currentAccount - if (from !== currentAccount.address) { + if (!compareStrings(from, currentAccount.address)) { throw new Error('From address does not match current account'); } diff --git a/packages/react/src/utils/index.ts b/packages/react/src/utils/index.ts index 8df1b7ea..46f1f1fa 100644 --- a/packages/react/src/utils/index.ts +++ b/packages/react/src/utils/index.ts @@ -37,7 +37,7 @@ export const isMobile = () => { * @param tokenB The second token. * @returns True if the two tokens are equal. */ -export const areTokensEqual = (tokenA: string | undefined, tokenB: string | undefined): boolean => { +export const compareStrings = (tokenA: string | undefined, tokenB: string | undefined): boolean => { // Early return if either token is undefined if (!tokenA || !tokenB) return false;