finish migrate vested bonded node work
This commit is contained in:
@@ -127,6 +127,7 @@ export const BondedMixnode = ({
|
||||
<BondedMixnodeActions
|
||||
onActionSelect={onActionSelect}
|
||||
disabledRedeemAndCompound={(operatorRewards && Number(operatorRewards.amount) === 0) || false}
|
||||
disabledUpdateBond={Boolean(mixnode.proxy)}
|
||||
/>
|
||||
),
|
||||
id: 'actions-cell',
|
||||
|
||||
@@ -9,8 +9,9 @@ import DialogTitle from '@mui/material/DialogTitle';
|
||||
export const VestingWarningModal: FC<{
|
||||
kind: 'delegations' | 'bond';
|
||||
isVisible: boolean;
|
||||
handleClose: (result: 'yes' | 'no') => void;
|
||||
}> = ({ kind, isVisible, handleClose }) => (
|
||||
handleClose: () => void;
|
||||
handleMigrate: () => Promise<void>;
|
||||
}> = ({ kind, isVisible, handleClose, handleMigrate }) => (
|
||||
<Dialog open={isVisible} onClose={handleClose}>
|
||||
<DialogTitle>Migrate your {kind}?</DialogTitle>
|
||||
<DialogContent>
|
||||
@@ -23,8 +24,8 @@ export const VestingWarningModal: FC<{
|
||||
</DialogContentText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={() => handleClose('yes')}>Yes</Button>
|
||||
<Button onClick={() => handleClose('no')} autoFocus>
|
||||
<Button onClick={handleMigrate}>Yes</Button>
|
||||
<Button onClick={handleClose} autoFocus>
|
||||
No
|
||||
</Button>
|
||||
</DialogActions>
|
||||
|
||||
@@ -53,6 +53,7 @@ import {
|
||||
generateGatewayMsgPayload as generateGatewayMsgPayloadReq,
|
||||
updateBond as updateBondReq,
|
||||
vestingUpdateBond as vestingUpdateBondReq,
|
||||
migrateVestedMixnode as tauriMigrateVestedMixnode,
|
||||
} from '../requests';
|
||||
import { useCheckOwnership } from '../hooks/useCheckOwnership';
|
||||
import { AppContext } from './main';
|
||||
@@ -128,6 +129,7 @@ export type TBondingContext = {
|
||||
generateMixnodeMsgPayload: (data: TBondMixnodeSignatureArgs) => Promise<string | undefined>;
|
||||
generateGatewayMsgPayload: (data: TBondGatewaySignatureArgs) => Promise<string | undefined>;
|
||||
isVestingAccount: boolean;
|
||||
migrateVestedMixnode: () => Promise<TransactionExecuteResult | undefined>;
|
||||
};
|
||||
|
||||
export const BondingContext = createContext<TBondingContext>({
|
||||
@@ -157,6 +159,9 @@ export const BondingContext = createContext<TBondingContext>({
|
||||
generateGatewayMsgPayload: async () => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
migrateVestedMixnode: async () => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
isVestingAccount: false,
|
||||
});
|
||||
|
||||
@@ -599,6 +604,13 @@ export const BondingContextProvider: FCWithChildren = ({ children }): JSX.Elemen
|
||||
return message;
|
||||
};
|
||||
|
||||
const migrateVestedMixnode = async () => {
|
||||
setIsLoading(true);
|
||||
const tx = await tauriMigrateVestedMixnode();
|
||||
setIsLoading(false);
|
||||
return tx;
|
||||
};
|
||||
|
||||
const memoizedValue = useMemo(
|
||||
() => ({
|
||||
isLoading: isLoading || isOwnershipLoading,
|
||||
@@ -613,6 +625,7 @@ export const BondingContextProvider: FCWithChildren = ({ children }): JSX.Elemen
|
||||
updateBondAmount,
|
||||
generateMixnodeMsgPayload,
|
||||
generateGatewayMsgPayload,
|
||||
migrateVestedMixnode,
|
||||
isVestingAccount,
|
||||
}),
|
||||
[isLoading, isOwnershipLoading, error, bondedNode, isVestingAccount],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { FeeDetails } from '@nymproject/types';
|
||||
import { Box } from '@mui/material';
|
||||
import { Alert, AlertTitle, Box, Button, Typography } from '@mui/material';
|
||||
import { TPoolOption } from 'src/components';
|
||||
import { Bond } from 'src/components/Bonding/Bond';
|
||||
import { BondedMixnode } from 'src/components/Bonding/BondedMixnode';
|
||||
@@ -17,15 +17,16 @@ import { AppContext, urls } from 'src/context/main';
|
||||
import { isGateway, isMixnode, TBondGatewayArgs, TBondMixNodeArgs, TUpdateBondArgs } from 'src/types';
|
||||
import { BondedGateway } from 'src/components/Bonding/BondedGateway';
|
||||
import { RedeemRewardsModal } from 'src/components/Bonding/modals/RedeemRewardsModal';
|
||||
import { VestingWarningModal } from 'src/components/VestingWarningModal';
|
||||
import { BondingContextProvider, useBondingContext } from '../../context';
|
||||
|
||||
const Bonding = () => {
|
||||
export const Bonding = () => {
|
||||
const [showModal, setShowModal] = useState<
|
||||
'bond-mixnode' | 'bond-gateway' | 'update-bond' | 'update-bond-oversaturated' | 'unbond' | 'redeem'
|
||||
>();
|
||||
const [confirmationDetails, setConfirmationDetails] = useState<ConfirmationDetailProps>();
|
||||
const [uncappedSaturation, setUncappedSaturation] = useState<number | undefined>();
|
||||
|
||||
const [showMigrationModal, setShowMigrationModal] = useState(false);
|
||||
const {
|
||||
network,
|
||||
clientDetails,
|
||||
@@ -34,8 +35,17 @@ const Bonding = () => {
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { bondedNode, bondMixnode, bondGateway, redeemRewards, isLoading, updateBondAmount, error, refresh } =
|
||||
useBondingContext();
|
||||
const {
|
||||
bondedNode,
|
||||
bondMixnode,
|
||||
bondGateway,
|
||||
redeemRewards,
|
||||
isLoading,
|
||||
updateBondAmount,
|
||||
error,
|
||||
refresh,
|
||||
migrateVestedMixnode,
|
||||
} = useBondingContext();
|
||||
|
||||
useEffect(() => {
|
||||
if (bondedNode && isMixnode(bondedNode) && bondedNode.uncappedStakeSaturation) {
|
||||
@@ -43,6 +53,18 @@ const Bonding = () => {
|
||||
}
|
||||
}, [bondedNode]);
|
||||
|
||||
const handleMigrateVestedMixnode = async () => {
|
||||
setShowMigrationModal(false);
|
||||
const tx = await migrateVestedMixnode();
|
||||
if (tx) {
|
||||
setConfirmationDetails({
|
||||
status: 'success',
|
||||
title: 'Migration successful',
|
||||
txUrl: `${urls(network).blockExplorer}/transaction/${tx?.transaction_hash}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleCloseModal = async () => {
|
||||
setShowModal(undefined);
|
||||
refresh();
|
||||
@@ -138,6 +160,33 @@ const Bonding = () => {
|
||||
|
||||
return (
|
||||
<Box sx={{ mt: 4 }}>
|
||||
{bondedNode?.proxy && (
|
||||
<Alert severity="warning" sx={{ mb: 3 }}>
|
||||
<AlertTitle sx={{ fontWeight: 600 }}>Your bonded node is using tokens from the vesting contract!</AlertTitle>
|
||||
<Typography>
|
||||
In order to claim your rewards, you will need to migrate it out of the vesting contract.{' '}
|
||||
</Typography>
|
||||
<Typography mt={1}>
|
||||
<strong>Never fear</strong>, if you do not migrate them, <strong>you will continue to get rewards</strong>.
|
||||
However, please migrate your bonded node as soon as possible.
|
||||
</Typography>
|
||||
<Button variant="contained" size="small" sx={{ mt: 1 }} onClick={() => setShowMigrationModal(true)}>
|
||||
Migrate now
|
||||
</Button>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<VestingWarningModal
|
||||
kind="bond"
|
||||
isVisible={showMigrationModal}
|
||||
handleClose={() => {
|
||||
setShowMigrationModal(false);
|
||||
}}
|
||||
handleMigrate={async () => {
|
||||
await handleMigrateVestedMixnode();
|
||||
}}
|
||||
/>
|
||||
|
||||
{!bondedNode && <Bond disabled={isLoading} onBond={() => setShowModal('bond-mixnode')} />}
|
||||
|
||||
{bondedNode && isMixnode(bondedNode) && (
|
||||
|
||||
@@ -352,12 +352,8 @@ export const Delegation: FC<{ isStorybook?: boolean }> = ({ isStorybook }) => {
|
||||
<VestingWarningModal
|
||||
kind="delegations"
|
||||
isVisible={showVestingWarningModal}
|
||||
handleClose={(result) => {
|
||||
setShowVestingWarningModal(false);
|
||||
if (result === 'yes') {
|
||||
doMigrateNow();
|
||||
}
|
||||
}}
|
||||
handleMigrate={doMigrateNow}
|
||||
handleClose={() => setShowVestingWarningModal(false)}
|
||||
/>
|
||||
{showVestingMigrationProgressModal && <LoadingModal text="Migrating delegations, please wait..." />}
|
||||
</>
|
||||
|
||||
@@ -52,3 +52,5 @@ export const unbond = async (type: EnumNodeType) => {
|
||||
|
||||
export const updateBond = async (args: TUpdateBondArgs) =>
|
||||
invokeWrapper<TransactionExecuteResult>('update_pledge', args);
|
||||
|
||||
export const migrateVestedMixnode = async () => invokeWrapper<TransactionExecuteResult>('migrate_vested_mixnode');
|
||||
|
||||
Reference in New Issue
Block a user