8000 feat: update deposit ui receipts and routeoptions by jaredvu · Pull Request #1640 · dydxprotocol/v4-web · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: update deposit ui receipts and routeoptions #1640

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

Merged
merged 6 commits into from
Apr 21, 2025
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@datadog/browser-logs": "^5.23.3",
"@dydxprotocol/v4-abacus": "1.13.39",
"@dydxprotocol/v4-client-js": "1.21.3",
"@dydxprotocol/v4-localization": "^1.1.278",
"@dydxprotocol/v4-localization": "^1.1.280",
"@dydxprotocol/v4-proto": "^7.0.0-dev.0",
"@emotion/is-prop-valid": "^1.3.0",
"@funkit/connect": "^5.0.1",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,69 @@ type Chain = {
name: string;
icon: string;
walletNetworkType: WalletNetworkType;
gasDenom: string;
};

export const CHAIN_INFO: { [chainId: string]: Chain } = {
[mainnet.id]: {
name: 'Ethereum',
icon: '/chains/ethereum.png',
walletNetworkType: WalletNetworkType.Evm,
gasDenom: 'ETH',
},
[arbitrum.id]: {
name: 'Arbitrum',
icon: '/chains/arbitrum.png',
walletNetworkType: WalletNetworkType.Evm,
gasDenom: 'ETH',
},
[optimism.id]: {
name: 'Optimism',
icon: '/chains/optimism.png',
walletNetworkType: WalletNetworkType.Evm,
gasDenom: 'ETH',
},
[base.id]: {
name: 'Base',
icon: '/chains/base.png',
walletNetworkType: WalletNetworkType.Evm,
gasDenom: 'ETH',
},
[polygon.id]: {
name: 'Polygon',
icon: '/chains/polygon.png',
walletNetworkType: WalletNetworkType.Evm,
gasDenom: 'POL',
},
[avalanche.id]: {
name: 'Avalanche',
icon: '/chains/avalanche.png',
walletNetworkType: WalletNetworkType.Evm,
gasDenom: 'AVAX',
},
[SOLANA_MAINNET_ID]: {
name: 'Solana',
icon: '/chains/solana.png',
walletNetworkType: WalletNetworkType.Solana,
gasDenom: 'SOL',
},
[CosmosChainId.Neutron]: {
name: 'Neutron',
icon: '/chains/neutron.png',
walletNetworkType: WalletNetworkType.Cosmos,
gasDenom: 'NTRN',
},
[CosmosChainId.Noble]: {
name: 'Noble',
icon: '/chains/noble.png',
walletNetworkType: WalletNetworkType.Cosmos,
gasDenom: 'USDC',
},
[CosmosChainId.Osmosis]: {
name: 'Osmosis',
icon: '/chains/osmosis.png',
walletNetworkType: WalletNetworkType.Cosmos,
gasDenom: 'OSMO',
},
};

Expand Down
25 changes: 25 additions & 0 deletions src/constants/skip.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { arbitrum, avalanche, base, mainnet, optimism, polygon } from 'viem/chains';

export type RouteStatusSummary = 'success' | 'ongoing' | undefined;

export type RouteStatus = {
Expand Down Expand Up @@ -37,3 +39,26 @@ export type SkipStatusResponse = {
};

export const SKIP_EST_TIME_DEFAULT_MINUTES = 30;

/**
* @url https://docs.skip.build/go/advanced-transfer/go-fast
* @description The maximum amount that can be transferred using the Go Fast route. All chains currently (4/15/2025) have the same limit.
*/
export const SKIP_GO_FAST_TRANSFER_LIMIT = 17_500; // hardcoded on Skip's end

export const SKIP_GO_BPS_FEE = 0.1; // hardcoded to 10bps on Skip's end

export const SKIP_GO_DESTINATION_FEE = 0.01; // $0.01 since the only destination is Osmosis chain to fulfill the go fast route.

/**
* @description The fee for the source chain to fulfill the go fast route.
* @note The fee is hardcoded on Skip's end.
*/
export const SKIP_GO_FAST_SOURCE_FEE_MAP: Record<string, number> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we strongly type this so that if we add another supported chain we remember to add here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fast follow with this

[mainnet.id]: 5,
[arbitrum.id]: 0.05,
[optimism.id]: 0.01,
[polygon.id]: 0.01,
[avalanche.id]: 0.1,
[base.id]: 0.01,
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useWalletClient } from 'wagmi';

import { AnalyticsEvents } from '@/constants/analytics';
import { ButtonAction, ButtonType } from '@/constants/buttons';
import { CHAIN_INFO } from '@/constants/chains';
import { STRING_KEYS } from '@/constants/localization';
import { MIN_DEPOSIT_AMOUNT, NumberSign } from '@/constants/numbers';
import { TokenForTransfer, USDC_DECIMALS } from '@/constants/tokens';
Expand Down Expand Up @@ -293,16 +292,6 @@ export const DepositForm = ({
}
};

const chainName =
selectedRoute?.sourceAssetChainID && CHAIN_INFO[selectedRoute.sourceAssetChainID]?.name;

const gasFeeAdjustment =
selectedSpeed === 'slow' && chainName ? (
<span tw="text-color-text-0 font-mini-book">
{` - ${stringGetter({ key: STRING_KEYS.CHAIN_GAS_FEES, params: { CHAIN: chainName } })}`}
</span>
) : null;

const receipt = selectedRoute && (
<Details
tw="font-small-book"
Expand All @@ -316,7 +305,6 @@ export const DepositForm = ({
type={OutputType.Fiat}
isLoading={isFetching}
value={formatUnits(BigInt(selectedRoute.amountOut), USDC_DECIMALS)}
slotRight={gasFeeAdjustment}
/>
),
},
Expand Down Expand Up @@ -356,15 +344,17 @@ export const DepositForm = ({
disabled={!amount || parseUnits(amount, token.decimals) === BigInt(0)}
selectedSpeed={selectedSpeed}
>
chainId={token.chainId}
type="deposit"
/>
</div>
<div tw="flex flex-col gap-0.75">
{!depositSteps?.length && (
<div tw="mt-2 flex flex-col gap-0.375">
<div tw="mt-0.5 flex flex-col gap-0.5">
{currentStepError && (
<div tw="text-center text-small text-color-error">{currentStepError}</div>
)}
{receipt}
<Button
tw="w-full"
>
Expand All @@ -390,7 +380,6 @@ export const DepositForm = ({
/>
</div>
)}
{receipt}
</div>
{!depositSteps?.length && !awaitingWalletAction && (
<OtherDepositOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,22 @@ export const OtherDepositOptions = ({
type={ButtonType.Button}
tw="flex items-center border border-solid border-color-border bg-color-layer-4 px-2 py-1 font-medium"
>
<div tw="inline-flex gap-[0.5ch]">
{stringGetter({
key: STRING_KEYS.DEPOSIT_WITH,
params: {
TARGET: (
<div tw="inline text-color-text-1">
<CoinbaseBrandIcon />
</div>
),
},
})}{' '}
<div tw="row w-full justify-between gap-[0.5ch]">
<span tw="row gap-[0.5ch]">
{stringGetter({
key: STRING_KEYS.DEPOSIT_WITH,
params: {
TARGET: (
<div tw="row mb-[1px] text-color-text-1">
<CoinbaseBrandIcon />
</div>
),
},
})}
</span>
<span tw="text-color-text-0 font-small-book">
{stringGetter({ key: STRING_KEYS.FREE_AND_INSTANT })}
</span>
<span tw="sr-only">Coinbase</span>
</div>
</Button>
Expand Down
45 changes: 32 additions & 13 deletions src/views/dialogs/TransferDialogs/RouteOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import tw from 'twin.macro';
import { CHAIN_INFO } from '@/constants/chains';
import { STRING_KEYS } from '@/constants/localization';
import { USD_DECIMALS } from '@/constants/numbers';
import {
SKIP_GO_BPS_FEE,
SKIP_GO_DESTINATION_FEE,
SKIP_GO_FAST_SOURCE_FEE_MAP,
SKIP_GO_FAST_TRANSFER_LIMIT,
} from '@/constants/skip';

import { SkipRouteSpeed } from '@/hooks/transfers/skipClient';
import { useLocaleSeparators } from '@/hooks/useLocaleSeparators';
Expand All @@ -23,6 +29,7 @@ import { BIG_NUMBERS } from '@/lib/numbers';
import { getStringsForDateTimeDiff } from '@/lib/timeUtils';

type Props = {
chainId?: string;
routes?: { slow?: RouteResponse; fast?: RouteResponse };
isLoading: boolean;
disabled: boolean;
Expand All @@ -32,6 +39,7 @@ type Props = {
};

export const TransferRouteOptions = ({
chainId,
routes,
isLoading,
selectedSpeed,
Expand All @@ -42,7 +50,7 @@ export const TransferRouteOptions = ({
const stringGetter = useStringGetter();
const selectedLocale = useAppSelector(getSelectedLocale);
const { decimal, group } = useLocaleSeparators();
const limitAmount = formatNumberOutput(10_000, OutputType.CompactNumber, {
const limitAmount = formatNumberOutput(SKIP_GO_FAST_TRANSFER_LIMIT, OutputType.CompactNumber, {
selectedLocale,
decimalSeparator: decimal,
groupSeparator: group,
Expand All @@ -58,13 +66,24 @@ export const TransferRouteOptions = ({
}, [routes?.fast]);

const fastRouteDescription = useMemo(() => {
if (!routes || disabled)
if (!routes || disabled) {
const sourceFee = SKIP_GO_FAST_SOURCE_FEE_MAP[chainId ?? ''];
const bpsFee = formatNumberOutput(SKIP_GO_BPS_FEE, OutputType.Percent, {
selectedLocale,
decimalSeparator: decimal,
groupSeparator: group,
fractionDigits: 0,
});

const estimatedFee = sourceFee ? `${sourceFee + SKIP_GO_DESTINATION_FEE} + ${bpsFee}` : '$';

return type === 'deposit'
? stringGetter({
key: STRING_KEYS.SKIP_FAST_ROUTE_DESC,
params: { LIMIT_AMOUNT: limitAmount },
key: STRING_KEYS.SKIP_FAST_ROUTE_DESC_1,
params: { FEE: estimatedFee, LIMIT_AMOUNT: limitAmount },
})
: '-';
}
if (!routes.fast || !goFastOperation) return stringGetter({ key: STRING_KEYS.UNAVAILABLE });

const fastOperationFee = routes.fast.estimatedFees.reduce(
Expand All @@ -87,7 +106,7 @@ export const TransferRouteOptions = ({
)}
</span>
);
}, [goFastOperation, routes, disabled, stringGetter, isLoading, type, limitAmount]);
}, [chainId, goFastOperation, routes, disabled, stringGetter, isLoading, type, limitAmount]);

const slowRouteDescription = useMemo(() => {
const slowOperationFee = routes?.slow?.estimatedFees.reduce(
Expand All @@ -96,16 +115,16 @@ export const TransferRouteOptions = ({
);

if (!routes || disabled)
return type === 'deposit' ? stringGetter({ key: STRING_KEYS.SKIP_SLOW_ROUTE_DESC }) : '-';
return type === 'deposit' ? stringGetter({ key: STRING_KEYS.SKIP_SLOW_ROUTE_DESC_1 }) : '-';
if (!routes.slow) return stringGetter({ key: STRING_KEYS.UNAVAILABLE });

const chainName =
routes.slow.sourceAssetChainID && CHAIN_INFO[routes.slow.sourceAssetChainID]?.name;
const gasDenom =
routes.slow.sourceAssetChainID && CHAIN_INFO[routes.slow.sourceAssetChainID]?.gasDenom;

const gasFeeAdjustment =
type === 'deposit' && chainName ? (
type === 'deposit' && gasDenom ? (
<span tw="text-color-text-0 font-mini-book">
{` + ${stringGetter({ key: STRING_KEYS.CHAIN_GAS_FEES, params: { CHAIN: chainName } })}`}
{` + ${stringGetter({ key: STRING_KEYS.CHAIN_GAS_FEES_SHORT, params: { CHAIN: gasDenom } })}`}
</span>
) : null;

Expand Down Expand Up @@ -198,7 +217,7 @@ const RouteOption = ({
return (
<button
type="button"
tw="box-border flex min-w-0 flex-1 items-center gap-0.75 rounded-1 border-2 border-solid p-1"
tw="box-border flex min-w-0 flex-1 items-center gap-0.75 rounded-1 border-2 border-solid px-1 py-0.75"
disabled={disabled}
>
style={{
Expand All @@ -210,14 +229,14 @@ const RouteOption = ({
{icon}
<div tw="flex flex-col items-start gap-0.125 text-left">
<div
tw="text-medium"
tw="text-base"
style={{
color: selected && !disabled ? 'var(--color-text-2)' : undefined,
}}
>
{title}
</div>
<div tw="text-small text-color-text-1">{description}</div>
<div tw="text-tiny text-color-text-1">{description}</div>
</div>
</button>
);
Expand Down
Loading
0