Skip to content

Commit

Permalink
fix: transfer modal close (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmadek authored and stepanLav committed Sep 18, 2023
1 parent 71bd61b commit a551f41
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
2 changes: 0 additions & 2 deletions src/renderer/entities/transaction/lib/transactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,6 @@ export const useTransaction = (): ITransactionService => {
const getTransactionHash = (transaction: Transaction, api: ApiPromise): HashData => {
const extrinsic = getExtrinsic[transaction.type](transaction.args, api);

console.log('xcmMethod', extrinsic.method.toJSON());

return {
callData: extrinsic.method.toHex(),
callHash: extrinsic.method.hash.toHex(),
Expand Down
6 changes: 1 addition & 5 deletions src/renderer/pages/Assets/SendAsset/SendAsset.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { useNavigate } from 'react-router-dom';

import { AssetRouteGuard } from '@renderer/features/assets';
import { Paths } from '@renderer/app/providers';
import { SendAssetModal } from '@renderer/widgets';

export const SendAsset = () => {
const navigate = useNavigate();

return (
<AssetRouteGuard redirectPath={Paths.ASSETS}>
{(chain, asset) => <SendAssetModal chain={chain} asset={asset} onClose={() => navigate(Paths.ASSETS)} />}
{(chain, asset) => <SendAssetModal chain={chain} asset={asset} />}
</AssetRouteGuard>
);
};
18 changes: 12 additions & 6 deletions src/renderer/widgets/SendAssetModal/ui/SendAssetModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useState, useEffect } from 'react';
import { UnsignedTransaction } from '@substrate/txwrapper-polkadot';
import { useStore, useGate } from 'effector-react';
import { useNavigate } from 'react-router-dom';

import { useI18n, useNetworkContext } from '@renderer/app/providers';
import { Paths, useI18n, useNetworkContext } from '@renderer/app/providers';
import { HexString } from '@renderer/domain/shared-kernel';
import { Transaction, useTransaction, validateBalance } from '@renderer/entities/transaction';
import { Account, MultisigAccount } from '@renderer/entities/account';
Expand All @@ -12,7 +13,6 @@ import { Signing } from '@renderer/features/operation';
import { Asset, useBalance } from '@renderer/entities/asset';
import { OperationTitle } from '@renderer/components/common';
import { Chain } from '@renderer/entities/chain';
import { DEFAULT_TRANSITION } from '@renderer/shared/lib/utils';
import { useToggle } from '@renderer/shared/lib/hooks';
import * as sendAssetModel from '../model/send-asset';

Expand All @@ -26,11 +26,12 @@ const enum Step {
type Props = {
chain: Chain;
asset: Asset;
onClose: () => void;
};

export const SendAssetModal = ({ chain, asset, onClose }: Props) => {
export const SendAssetModal = ({ chain, asset }: Props) => {
const { t } = useI18n();
const navigate = useNavigate();

const { getBalance } = useBalance();
const { getTransactionFee } = useTransaction();
const { connections } = useNetworkContext();
Expand Down Expand Up @@ -92,7 +93,12 @@ export const SendAssetModal = ({ chain, asset, onClose }: Props) => {

const closeSendModal = () => {
toggleIsModalOpen();
setTimeout(onClose, DEFAULT_TRANSITION);
// TODO: rework to context-free solution
navigate(Paths.ASSETS);
};

const closeSendModalFromSubmit = () => {
toggleIsModalOpen();
};

const commonProps = { explorers, addressPrefix };
Expand All @@ -107,7 +113,7 @@ export const SendAssetModal = ({ chain, asset, onClose }: Props) => {
signature={signature}
description={description}
api={api}
onClose={closeSendModal}
onClose={closeSendModalFromSubmit}
{...commonProps}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const InitOperation = ({

const reserveChainId =
reserveAsset && config && toHexChainId(config.assetsLocation[reserveAsset.assetLocation].chainId);
const reserveApi = reserveChainId && connections[reserveChainId].api;
const reserveApi = reserveChainId && connections[reserveChainId]?.api;

return (
<div className="flex flex-col gap-y-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const Submit = ({ api, tx, multisigTx, account, unsignedTx, signature, de

if (isMultisig(account) && successMessage) {
navigate(Paths.OPERATIONS);
} else {
// TODO: rework to context-free solution

navigate(Paths.ASSETS);
}
};

Expand All @@ -62,6 +66,10 @@ export const Submit = ({ api, tx, multisigTx, account, unsignedTx, signature, de

if (isMultisig(account)) {
navigate(Paths.OPERATIONS);
} else {
// TODO: rework to context-free solution

navigate(Paths.ASSETS);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export const TransferForm = ({
const validateBalanceForFee = (amount: string): boolean => {
const balance = isMultisig(account) ? signerBalance : accountBalance;
const nativeTokenBalance = isMultisig(account) ? signerNativeTokenBalance : accountNativeTokenBalance;

const amountBN = new BN(formatAmount(amount, asset.precision));
const xcmFeeBN = new BN(xcmParams.fee || 0);

Expand All @@ -332,7 +333,7 @@ export const TransferForm = ({
}

if (isMultisig(account)) {
return new BN(fee).add(amountBN).add(xcmFeeBN).lte(new BN(balance));
return new BN(fee).lte(new BN(balance));
}

return new BN(fee).add(amountBN).add(xcmFeeBN).lte(new BN(balance));
Expand Down

0 comments on commit a551f41

Please sign in to comment.