refresh state
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
import React from 'react';
|
||||
import { Box, Button } from '@mui/material';
|
||||
import { FeeDetails } from '@nymproject/types';
|
||||
import { useGetFee } from 'src/hooks/useGetFee';
|
||||
import { simulateUnbondGateway, simulateVestingUnbondGateway, unbondGateway, vestingUnbondGateway } from 'src/requests';
|
||||
import { EnumNodeType } from 'src/types';
|
||||
import { Console } from 'src/utils/console';
|
||||
import { ConfirmationModal } from './ConfirmationModal';
|
||||
import { simulateUnbondGateway, simulateVestingUnbondGateway } from 'src/requests';
|
||||
import { ConfirmTx } from 'src/components/ConfirmTX';
|
||||
|
||||
export const UnbondGateway = ({
|
||||
isWithVestingTokens,
|
||||
onConfirm,
|
||||
onError,
|
||||
onSuccess,
|
||||
}: {
|
||||
isWithVestingTokens: boolean;
|
||||
onError: () => void;
|
||||
onSuccess: () => void;
|
||||
onConfirm: (isWithVestingTokens: boolean, fee: FeeDetails) => Promise<void>;
|
||||
onError: (err?: string) => void;
|
||||
}) => {
|
||||
const { fee, getFee, resetFeeState } = useGetFee();
|
||||
|
||||
@@ -22,26 +21,24 @@ export const UnbondGateway = ({
|
||||
if (isWithVestingTokens) await getFee(simulateVestingUnbondGateway, {});
|
||||
if (!isWithVestingTokens) await getFee(simulateUnbondGateway, {});
|
||||
} catch (e) {
|
||||
Console.error(e);
|
||||
onError();
|
||||
}
|
||||
};
|
||||
|
||||
const handleConfirm = async () => {
|
||||
try {
|
||||
if (isWithVestingTokens) await vestingUnbondGateway(fee?.fee);
|
||||
if (!isWithVestingTokens) await unbondGateway(fee?.fee);
|
||||
onSuccess();
|
||||
} catch (e) {
|
||||
Console.error(e);
|
||||
onError();
|
||||
onError(e as string);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ p: 3, display: 'flex', justifyContent: 'flex-end' }}>
|
||||
{fee && (
|
||||
<ConfirmationModal fee={fee} nodeType={EnumNodeType.gateway} onPrev={resetFeeState} onConfirm={handleConfirm} />
|
||||
<ConfirmTx
|
||||
open
|
||||
fee={fee}
|
||||
header="Unbond gateway details"
|
||||
onPrev={resetFeeState}
|
||||
onClose={resetFeeState}
|
||||
onConfirm={async () => {
|
||||
onConfirm(isWithVestingTokens, fee);
|
||||
resetFeeState();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Button size="large" variant="contained" disableElevation onClick={handleGetFee}>
|
||||
Unbond gateway
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
import React from 'react';
|
||||
import { Box, Button } from '@mui/material';
|
||||
import { ConfirmTx } from 'src/components/ConfirmTX';
|
||||
import { useGetFee } from 'src/hooks/useGetFee';
|
||||
import { simulateUnbondMixnode, simulateVestingUnbondMixnode, vestingUnbondMixnode, unbondMixNode } from 'src/requests';
|
||||
import { EnumNodeType } from 'src/types';
|
||||
import { Console } from 'src/utils/console';
|
||||
import { ConfirmationModal } from './ConfirmationModal';
|
||||
import { simulateUnbondMixnode, simulateVestingUnbondMixnode } from 'src/requests';
|
||||
import { FeeDetails } from '@nymproject/types';
|
||||
|
||||
export const UnbondMixnode = ({
|
||||
isWithVestingTokens,
|
||||
onConfirm,
|
||||
onError,
|
||||
onSuccess,
|
||||
}: {
|
||||
isWithVestingTokens: boolean;
|
||||
onError: () => void;
|
||||
onSuccess: () => void;
|
||||
onConfirm: (isWithVestingTokens: boolean, fee: FeeDetails) => Promise<void>;
|
||||
onError: (err?: string) => void;
|
||||
}) => {
|
||||
const { fee, getFee, resetFeeState } = useGetFee();
|
||||
|
||||
@@ -22,26 +21,24 @@ export const UnbondMixnode = ({
|
||||
if (isWithVestingTokens) await getFee(simulateVestingUnbondMixnode, {});
|
||||
if (!isWithVestingTokens) await getFee(simulateUnbondMixnode, {});
|
||||
} catch (e) {
|
||||
Console.error(e);
|
||||
onError();
|
||||
}
|
||||
};
|
||||
|
||||
const handleConfirm = async () => {
|
||||
try {
|
||||
if (isWithVestingTokens) await vestingUnbondMixnode(fee?.fee);
|
||||
if (!isWithVestingTokens) await unbondMixNode(fee?.fee);
|
||||
onSuccess();
|
||||
} catch (e) {
|
||||
Console.error(e);
|
||||
onError();
|
||||
onError(e as string);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ p: 3, display: 'flex', justifyContent: 'flex-end' }}>
|
||||
{fee && (
|
||||
<ConfirmationModal fee={fee} nodeType={EnumNodeType.mixnode} onPrev={resetFeeState} onConfirm={handleConfirm} />
|
||||
<ConfirmTx
|
||||
open
|
||||
fee={fee}
|
||||
header="Unbond mixnode details"
|
||||
onPrev={resetFeeState}
|
||||
onClose={resetFeeState}
|
||||
onConfirm={async () => {
|
||||
onConfirm(isWithVestingTokens, fee);
|
||||
resetFeeState();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Button size="large" variant="contained" disableElevation onClick={handleGetFee}>
|
||||
Unbond mixnode
|
||||
|
||||
Reference in New Issue
Block a user