Skip to content

Commit

Permalink
address comments!
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed Oct 16, 2024
1 parent 43b39a9 commit 7ae0a82
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/constants/transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const getDefaultTokenDenomFromAssets = (assets: Asset[]): string => {
const nativeChainToken = assets.find((asset) => {
return isNativeDenom(asset.denom);
});
// If not cctp or native chain token, default to the first item in the list
const defaultTokenDenom = cctpToken?.denom ?? nativeChainToken?.denom ?? assets[0]?.denom;
return defaultTokenDenom;
};
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/transfers/useTransfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const useTransfers = () => {
queryFn: async () => {
// this should never happen, this is just to satisfy typescript
// react queries should never return null.
if (!hasAllParams) return null;
if (!hasAllParams || !fromToken.decimals) return null;

const baseParams = {
sourceAssetDenom: fromToken.denom,
Expand All @@ -166,7 +166,7 @@ export const useTransfers = () => {
slippageTolerancePercent: '1',
smartRelay: true,
// TODO: talk to skip about this, why are decimals optional? when would that happen?
amountIn: parseUnits(amount, fromToken.decimals ?? 0).toString(),
amountIn: parseUnits(amount, fromToken.decimals).toString(),
};

// consider moving to useMemo outside of this query
Expand Down
9 changes: 4 additions & 5 deletions src/lib/assetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ export const getAssetFromMarketId = (marketId: string): string => {
const SKIP_NATIVE_DENOM_SUFFIX = 'native';

/**
* cosmjs uses this 0x address as the chain's native token.
* skip does not, but we add this value in order to be able to send payloads to cosmjs
* @todo We may need to add additional logic here if we 'useAccountBalance' on forms that do not follow this format.
* cosmjs and wagmi expect this 0x address to represent a chain's native token address.
* skip has a unique format that differs from this.
*/
export const NATIVE_TOKEN_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
export const WAGMI_COSMJS_NATIVE_TOKEN_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';

export const isNativeDenom = (denom: string | undefined): boolean => {
if (!denom) return false;
return denom === NATIVE_TOKEN_ADDRESS || denom?.endsWith(SKIP_NATIVE_DENOM_SUFFIX);
return denom === WAGMI_COSMJS_NATIVE_TOKEN_ADDRESS || denom?.endsWith(SKIP_NATIVE_DENOM_SUFFIX);
};
4 changes: 2 additions & 2 deletions src/views/forms/AccountManagementForms/DepositForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import { getTransferInputs } from '@/state/inputsSelectors';
import abacusStateManager from '@/lib/abacus';
import { track } from '@/lib/analytics/analytics';
import { dd } from '@/lib/analytics/datadog';
import { isNativeDenom, NATIVE_TOKEN_ADDRESS } from '@/lib/assetUtils';
import { isNativeDenom, WAGMI_COSMJS_NATIVE_TOKEN_ADDRESS } from '@/lib/assetUtils';
import { MustBigNumber } from '@/lib/numbers';
import { log } from '@/lib/telemetry';
import { sleep } from '@/lib/timeUtils';
Expand Down Expand Up @@ -176,7 +176,7 @@ export const DepositForm = ({ onDeposit, onError }: DepositFormProps) => {

// Async Data
const { balance } = useAccountBalance({
addressOrDenom: sourceToken?.address || NATIVE_TOKEN_ADDRESS,
addressOrDenom: sourceToken?.address || WAGMI_COSMJS_NATIVE_TOKEN_ADDRESS,
chainId,
isCosmosChain: isKeplrWallet,
});
Expand Down

0 comments on commit 7ae0a82

Please sign in to comment.