Skip to content
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

Fix rounding issue with max amounts #79

Merged
merged 1 commit into from
Nov 13, 2023
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hyperlane-xyz/warp-ui-template",
"description": "A web app template for building Hyperlane Warp Route UIs",
"version": "3.1.0-beta3",
"version": "3.1.0-beta4",
"author": "J M Rossy",
"dependencies": {
"@chakra-ui/next-js": "^2.1.5",
Expand All @@ -16,8 +16,8 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@headlessui/react": "^1.7.14",
"@hyperlane-xyz/sdk": "^3.1.0-beta3",
"@hyperlane-xyz/utils": "^3.1.0-beta3",
"@hyperlane-xyz/sdk": "^3.1.0-beta4",
"@hyperlane-xyz/utils": "^3.1.0-beta4",
"@hyperlane-xyz/widgets": "^1.5.0",
"@metamask/jazzicon": "https://github.com/jmrossy/jazzicon#7a8df28974b4e81129bfbe3cab76308b889032a6",
"@rainbow-me/rainbowkit": "0.12.16",
Expand Down
4 changes: 2 additions & 2 deletions src/components/toast/IgpDetailsToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { toast } from 'react-toastify';

import { links } from '../../consts/links';

export function toastIgpDetails(igpFee: number, tokenName = 'native token') {
export function toastIgpDetails(igpFee: string, tokenName = 'native token') {
toast.error(<IgpDetailsToast tokenName={tokenName} igpFee={igpFee} />, {
autoClose: 5000,
});
}

export function IgpDetailsToast({ tokenName, igpFee }) {
export function IgpDetailsToast({ tokenName, igpFee }: { tokenName: string; igpFee: string }) {
return (
<div>
Cross-chain transfers require a small fee of {igpFee} {tokenName} to fund delivery transaction
Expand Down
3 changes: 0 additions & 3 deletions src/consts/values.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export const MIN_ROUNDED_VALUE = 0.00001;
export const DISPLAY_DECIMALS = 4;
export const STANDARD_TOKEN_DECIMALS = 18;
export const SOL_ZERO_ADDRESS = '00000000000000000000000000000000000000000000';
export const COSMOS_ZERO_ADDRESS = 'cosmos100000000000000000000000000000000000000';
// Strangely, this is not included in any of the Solana packages
Expand Down
8 changes: 5 additions & 3 deletions src/features/transfer/TransferTokenForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function TokenBalance({
balance?: string | null;
decimals?: number;
}) {
const value = !decimals ? fromWei(balance, decimals) : fromWeiRounded(balance, decimals, false);
const value = !decimals ? fromWei(balance, decimals) : fromWeiRounded(balance, decimals);
return <div className="text-xs text-gray-500 text-right">{`${label}: ${value}`}</div>;
}

Expand Down Expand Up @@ -420,7 +420,7 @@ function ReviewDetails({ visible, tokenRoutes }: { visible: boolean; tokenRoutes
tokenRoutes,
) as WarpRoute;
const isNft = tokenCaip19Id && isNonFungibleToken(tokenCaip19Id);
const sendValueWei = isNft ? amount.toString() : toWei(amount, route?.originDecimals).toFixed(0);
const sendValueWei = isNft ? amount.toString() : toWei(amount, route?.originDecimals);
const originProtocol = getProtocolType(originCaip2Id);
const originUnitName =
originProtocol !== ProtocolType.Cosmos
Expand Down Expand Up @@ -534,7 +534,9 @@ function validateFormValues(
const parsedAmount = tryParseAmount(amount);
if (!parsedAmount || parsedAmount.lte(0))
return { amount: isNft ? 'Invalid Token Id' : 'Invalid amount' };
const sendValue = isNft ? parsedAmount : toWei(parsedAmount, route?.originDecimals);
const sendValue = isNft
? parsedAmount
: new BigNumber(toWei(parsedAmount, route?.originDecimals));

if (!isNft) {
// Validate balances for ERC20-like tokens
Expand Down
2 changes: 1 addition & 1 deletion src/features/transfer/useTokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function executeTransfer({
if (!tokenRoute) throw new Error('No token route found between chains');

const isNft = isNonFungibleToken(tokenCaip19Id);
const weiAmountOrId = isNft ? amount : toWei(amount, tokenRoute.originDecimals).toFixed(0);
const weiAmountOrId = isNft ? amount : toWei(amount, tokenRoute.originDecimals);
const activeAccountAddress = getAccountAddressForChain(
originCaip2Id,
activeAccounts.accounts[originProtocol],
Expand Down
3 changes: 2 additions & 1 deletion src/features/transfer/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BigNumber from 'bignumber.js';
import { providers } from 'ethers';
import { toast } from 'react-toastify';

Expand Down Expand Up @@ -33,7 +34,7 @@ export async function ensureSufficientCollateral(route: Route, weiAmount: string
route.originDecimals,
destinationBalance,
);
if (destinationBalanceInOriginDecimals.lt(weiAmount)) {
if (new BigNumber(destinationBalanceInOriginDecimals).lt(weiAmount)) {
toast.error('Collateral contract balance insufficient for transfer');
throw new Error('Insufficient collateral balance');
}
Expand Down
Loading