Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed Oct 15, 2024
1 parent 8c3eec4 commit e87f259
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/constants/cctp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export const getMapOfLowestFeeTokensByChainId = (type: NullableTransferType) =>
export const getMapOfHighestFeeTokensByChainId = (type: NullableTransferType) =>
getMapOfChainsByChainId(getHighestFeeChains(type));

export const cctpTokensByDenom = cctpTokens.reduce(
export const cctpTokensByDenomLowerCased = cctpTokens.reduce(
(acc, token) => {
const upperCasedAddress = token.tokenAddress.toUpperCase();
if (!acc[upperCasedAddress]) {
acc[upperCasedAddress] = [];
const lowerCasedAddress = token.tokenAddress.toLowerCase();
if (!acc[lowerCasedAddress]) {
acc[lowerCasedAddress] = [];
}
acc[upperCasedAddress].push(token);
acc[lowerCasedAddress].push(token);
return acc;
},
{} as Record<string, CctpTokenInfo[]>
Expand All @@ -88,5 +88,5 @@ export const isTokenCctp = (token: Asset | undefined) => {

const isDenomCctp = (denom: string | undefined) => {
if (!denom) return false;
return Boolean(cctpTokensByDenom[denom.toUpperCase()]);
return Boolean(cctpTokensByDenomLowerCased[denom.toLowerCase()]);
};
14 changes: 8 additions & 6 deletions src/constants/transfers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Asset } from '@skip-go/client';

import { ConnectorType, WalletInfo } from '@/constants/wallets';
import { WalletNetworkType } from '@/constants/wallets';

import { isNativeDenom } from '@/lib/assetUtils';

Expand All @@ -11,7 +11,7 @@ export enum TransferType {
Withdraw = 'WITHDRAW',
}

export type NetworkType = 'evm' | 'svm' | 'cosmos' | 'unknown';
export type NetworkType = 'evm' | 'svm' | 'cosmos';

// TODO: followup with skip about making logoUri an optional property
const DUMMY_LOGO_URI = 'dummy-logo-uri';
Expand Down Expand Up @@ -74,14 +74,16 @@ export const COSMOS_SWAP_VENUES = [

export const SWAP_VENUES = [...UNISWAP_VENUES, ...COSMOS_SWAP_VENUES];

export const getNetworkTypeFromWalletInfo = (connectedWalletInfo?: WalletInfo): NetworkType => {
if (connectedWalletInfo?.connectorType === ConnectorType.Injected) {
export const getNetworkTypeFromWalletNetworkType = (
walletNetworkType?: WalletNetworkType
): NetworkType => {
if (walletNetworkType === WalletNetworkType.Evm) {
return 'evm';
}
if (connectedWalletInfo?.connectorType === ConnectorType.PhantomSolana) {
if (walletNetworkType === WalletNetworkType.Solana) {
return 'svm';
}
if (connectedWalletInfo?.connectorType === ConnectorType.Cosmos) {
if (walletNetworkType === WalletNetworkType.Cosmos) {
return 'cosmos';
}
return 'evm';
Expand Down
16 changes: 7 additions & 9 deletions src/hooks/transfers/useTransfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
COSMOS_SWAP_VENUES,
getDefaultChainIDFromNetworkType,
getDefaultTokenDenomFromAssets,
getNetworkTypeFromWalletInfo,
getNetworkTypeFromWalletNetworkType,
SWAP_VENUES,
TransferType,
} from '@/constants/transfers';
Expand All @@ -37,10 +37,10 @@ export const useTransfers = () => {
const { dydxAddress, sourceAccount } = useAccounts();
const selectedDydxChainId = useAppSelector(getSelectedDydxChainId);

const [fromTokenDenom, setFromTokenDenom] = useState<string | null>(null);
const [fromChainId, setFromChainId] = useState<string | null>(null);
const [toTokenDenom, setToTokenDenom] = useState<string | null>(null);
const [toChainId, setToChainId] = useState<string | null>(null);
const [fromTokenDenom, setFromTokenDenom] = useState<string | undefined>();
const [fromChainId, setFromChainId] = useState<string | undefined>();
const [toTokenDenom, setToTokenDenom] = useState<string | undefined>();
const [toChainId, setToChainId] = useState<string | undefined>();
const [fromAddress, setFromAddress] = useState<EvmAddress | SolAddress | DydxAddress | undefined>(
undefined
);
Expand Down Expand Up @@ -90,7 +90,7 @@ export const useTransfers = () => {
const { chainsByNetworkMap = {} } = chainsQuery.data ?? {};
const { assetsByChain = {} } = assetsQuery.data ?? {};

const walletNetworkType = getNetworkTypeFromWalletInfo(sourceAccount?.walletInfo);
const walletNetworkType = getNetworkTypeFromWalletNetworkType(sourceAccount?.chain);
const selectedChainId = transferType === TransferType.Deposit ? fromChainId : toChainId;

const toToken = useMemo(() => {
Expand Down Expand Up @@ -165,6 +165,7 @@ export const useTransfers = () => {
allowUnsafe: true,
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(),
};

Expand Down Expand Up @@ -210,9 +211,6 @@ export const useTransfers = () => {
}

// DEPOSITS
// This should never happen. Consider moving to a useMemo hook
// and setting as part of allParams + query keys

if (isTokenCctp(fromToken)) {
// CCTP Deposits
return skipClient.msgsDirect({
Expand Down
8 changes: 4 additions & 4 deletions src/views/forms/AccountManagementForms/TokenSelectMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { shallowEqual } from 'react-redux';
import tw from 'twin.macro';

import { TransferInputTokenResource, TransferType } from '@/constants/abacus';
import { cctpTokensByDenom, getMapOfLowestFeeTokensByDenom } from '@/constants/cctp';
import { cctpTokensByDenomLowerCased, getMapOfLowestFeeTokensByDenom } from '@/constants/cctp';
import { NEUTRON_USDC_IBC_DENOM, OSMO_USDC_IBC_DENOM, SOLANA_USDC_DENOM } from '@/constants/denoms';
import { getNeutronChainId, getNobleChainId, getOsmosisChainId } from '@/constants/graz';
import { STRING_KEYS } from '@/constants/localization';
Expand Down Expand Up @@ -86,16 +86,16 @@ export const TokenSelectMenu = ({ selectedToken, onSelectToken, isExchange }: El
}
// if deposit and CCTPDepositOnly enabled, only return cctp tokens
if (type === TransferType.deposit && CCTPDepositOnly) {
return !!cctpTokensByDenom[token.value];
return !!cctpTokensByDenomLowerCased[token.value.toLowerCase()];
}
// if withdrawal and CCTPWithdrawalOnly enabled, only return cctp tokens
if (type === TransferType.withdrawal && CCTPWithdrawalOnly) {
return !!cctpTokensByDenom[token.value];
return !!cctpTokensByDenomLowerCased[token.value.toLowerCase()];
}
return true;
})
// we want lowest fee tokens first followed by non-lowest fee cctp tokens
.sort((token) => (cctpTokensByDenom[token.value] ? -1 : 1))
.sort((token) => (cctpTokensByDenomLowerCased[token.value.toLowerCase()] ? -1 : 1))
.sort((token) => (lowestFeeTokensByDenom[token.value] ? -1 : 1));

return (
Expand Down

0 comments on commit e87f259

Please sign in to comment.