Skip to content

Commit

Permalink
Merge pull request #153 from novasamatech/fix/max_amount
Browse files Browse the repository at this point in the history
Fix: Max amount
  • Loading branch information
tuul-wq authored Jul 9, 2024
2 parents 43a5b85 + d09299c commit 004be49
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
14 changes: 5 additions & 9 deletions app/common/_temp_hooks/useAmountLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { useAssetHub } from '@/common/utils/hooks/useAssetHub.ts';

type AmountLogicParams = {
selectedAsset?: TransferAsset;
isGift: boolean;
};

// TODO: Use BN to operate with amount and fee
export const useAmountLogic = ({ selectedAsset }: AmountLogicParams) => {
export const useAmountLogic = ({ selectedAsset, isGift }: AmountLogicParams) => {
const { getAssetHubFee } = useAssetHub();
const { getTransactionFee } = useExtrinsic();
const { getExistentialDeposit, getExistentialDepositStatemine } = useQueryService();
Expand All @@ -27,12 +28,7 @@ export const useAmountLogic = ({ selectedAsset }: AmountLogicParams) => {

const getFeeAmount = (selectedAsset: TransferAsset, transferAmount: string): Promise<number> => {
if (isStatemineAsset(selectedAsset.asset.type)) {
return getAssetHubFee(
selectedAsset.chainId,
selectedAsset.asset.typeExtras!.assetId,
transferAmount,
selectedAsset.isGift,
);
return getAssetHubFee(selectedAsset.chainId, selectedAsset.asset.typeExtras!.assetId, transferAmount, isGift);
}

return getTransactionFee(selectedAsset.chainId, TransactionType.TRANSFER, transferAmount);
Expand Down Expand Up @@ -74,15 +70,15 @@ export const useAmountLogic = ({ selectedAsset }: AmountLogicParams) => {

useEffect(() => {
setPending(true);
getTransferDetails(selectedAsset as TransferAsset, fee?.toString() ?? '0')
getTransferDetails(selectedAsset as TransferAsset, amount || '0')
.then(({ fee, formattedDeposit }) => {
setFee(fee);
setDeposit(formattedDeposit);
})
.finally(() => {
setPending(false);
});
}, [fee]);
}, [amount]);

useEffect(() => {
if (!selectedAsset) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Page = () => {
fee,
maxAmountToSend,
isAmountValid,
} = useAmountLogic({ selectedAsset });
} = useAmountLogic({ selectedAsset, isGift: false });

// Set amount from query params (/exchange/widget Mercurio page does this)
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion app/routes/transfer/gift/$chainId.$assetId/amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Page = () => {
maxAmountToSend,
isAmountValid,
touched,
} = useAmountLogic({ selectedAsset });
} = useAmountLogic({ selectedAsset, isGift: true });

const handleMaxGiftSend = () => {
handleMaxSend();
Expand Down

0 comments on commit 004be49

Please sign in to comment.