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: Max amount #153

Merged
merged 1 commit into from
Jul 9, 2024
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
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
Loading