Skip to content

Commit

Permalink
move gas drop off amounts to SDK amount.Amount
Browse files Browse the repository at this point in the history
  • Loading branch information
artursapek committed Oct 21, 2024
1 parent 174c7fc commit 0adb5b5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions wormhole-connect/src/utils/sdkv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export interface TransferInfo {
relayerFee?: RelayerFee;

// Amount of native gas being received, in destination gas token units
// For example 1.0 is 1.0 ETH, not 1 wei
receiveNativeAmount?: number;
receiveNativeAmount?: amount.Amount;

// ETA for the route this transfer was initiated on
eta?: number;
Expand Down Expand Up @@ -248,8 +247,9 @@ const parseTokenBridgeReceipt = async (
txData.receivedTokenKey = tokenV1.key;
txData.receiveAmount = txData.amount;
if (payload.payload?.toNativeTokenAmount) {
txData.receiveNativeAmount = Number(
amount.fmt(payload.payload.toNativeTokenAmount, Math.min(8, decimals)),
txData.receiveNativeAmount = amount.fromBaseUnits(
payload.payload.toNativeTokenAmount,
Math.min(8, decimals),
);
}
if (payload.payload?.targetRelayerFee) {
Expand Down
5 changes: 4 additions & 1 deletion wormhole-connect/src/views/v2/Bridge/AmountInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ const AmountInput = (props: Props) => {
const { sending: sendingWallet } = useSelector(
(state: RootState) => state.wallet,
);
const { amount } = useSelector((state: RootState) => state.transferInput);

const [amountInput, setAmountInput] = useState('');
const [amountInput, setAmountInput] = useState(
amount ? sdkAmount.display(amount) : '',
);

const { fromChain: sourceChain, token: sourceToken } = useSelector(
(state: RootState) => state.transferInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import Stack from '@mui/material/Stack';
import Switch from '@mui/material/Switch';
import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import { amount } from '@wormhole-foundation/sdk';

import config from 'config';
import { getDisplayName, calculateUSDPrice } from 'utils';
import { RootState } from 'store';
import { setToNativeToken } from 'store/relay';

import { toFixedDecimals } from 'utils/balance';

const useStyles = makeStyles()(() => ({
card: {
width: '100%',
Expand Down Expand Up @@ -83,7 +82,7 @@ const StyledSwitch = styled(Switch)(({ theme }) => ({
}));

const GasSlider = (props: {
destinationGasDrop: number;
destinationGasDrop: amount.Amount;
disabled: boolean;
}) => {
const { classes } = useStyles();
Expand Down Expand Up @@ -115,10 +114,10 @@ const GasSlider = (props: {
return null;
}

const tokenAmount = toFixedDecimals(
props.destinationGasDrop?.toString() || '0',
6,
const tokenAmount = amount.display(
amount.truncate(props.destinationGasDrop, 6),
);
console.log(tokenAmount);

const tokenPrice = calculateUSDPrice(
props.destinationGasDrop,
Expand Down
10 changes: 5 additions & 5 deletions wormhole-connect/src/views/v2/Bridge/ReviewTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ const ReviewTransaction = (props: Props) => {
const quoteResult = props.quotes[route ?? ''];
const quote = quoteResult?.success ? quoteResult : undefined;

const receiveNativeAmount = quote?.destinationNativeGas
? sdkAmount.whole(quote.destinationNativeGas)
: undefined;
const receiveNativeAmount = quote?.destinationNativeGas;

const send = async () => {
setSendError(undefined);
Expand Down Expand Up @@ -340,7 +338,7 @@ const ReviewTransaction = (props: Props) => {
!destChain ||
!destToken ||
!route ||
!(Number(amount) > 0)
!amount
) {
return null;
}
Expand Down Expand Up @@ -411,7 +409,9 @@ const ReviewTransaction = (props: Props) => {
{showGasSlider && (
<Collapse in={showGasSlider}>
<GasSlider
destinationGasDrop={receiveNativeAmount || 0}
destinationGasDrop={
receiveNativeAmount || sdkAmount.fromBaseUnits(0n, 8)
}
disabled={isGasSliderDisabled}
/>
</Collapse>
Expand Down
14 changes: 6 additions & 8 deletions wormhole-connect/src/views/v2/Bridge/Routes/SingleRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {

import type { RouteData } from 'config/routes';
import type { RootState } from 'store';
import { toFixedDecimals } from 'utils/balance';
import { TokenConfig } from 'config/types';
import FastestRoute from 'icons/FastestRoute';
import CheapestRoute from 'icons/CheapestRoute';
Expand Down Expand Up @@ -68,7 +67,7 @@ type Props = {
route: RouteData;
isSelected: boolean;
error?: string;
destinationGasDrop?: number;
destinationGasDrop?: amount.Amount;
isFastest?: boolean;
isCheapest?: boolean;
isOnlyChoice?: boolean;
Expand Down Expand Up @@ -139,9 +138,9 @@ const SingleRoute = (props: Props) => {

const feePriceFormatted = getUSDFormat(feePrice);

let feeValue = `${amount.display(quote!.relayFee!.amount, 4)} ${
feeTokenConfig.symbol
} (${feePriceFormatted})`;
let feeValue = `${amount.display(
amount.truncate(quote!.relayFee!.amount, 6),
)} ${feeTokenConfig.symbol} (${feePriceFormatted})`;

// Wesley made me do it
// Them PMs :-/
Expand Down Expand Up @@ -180,9 +179,8 @@ const SingleRoute = (props: Props) => {
gasTokenConfig,
);

const gasTokenAmount = toFixedDecimals(
props.destinationGasDrop?.toString() || '0',
4,
const gasTokenAmount = amount.display(
amount.truncate(props.destinationGasDrop, 6),
);

return (
Expand Down
2 changes: 1 addition & 1 deletion wormhole-connect/src/views/v2/Bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ const Bridge = () => {
destToken &&
sendingWallet.address &&
receivingWallet.address &&
Number(amount) > 0 &&
amount &&
!hasError;

const supportedRouteSelected = useMemo(
Expand Down

0 comments on commit 0adb5b5

Please sign in to comment.