This commit is contained in:
Gala
2022-12-01 11:46:58 +01:00
parent 1507938c65
commit a269bd8289
7 changed files with 92 additions and 18 deletions
@@ -114,7 +114,6 @@ export const BondedMixnode = ({
<BondedMixnodeActions
onActionSelect={onActionSelect}
disabledRedeemAndCompound={(operatorRewards && Number(operatorRewards.amount) === 0) || false}
disabledBondMore // TODO for now disable bond more feature until backend is ready
/>
),
id: 'actions-cell',
@@ -20,6 +20,7 @@ export const BondedMixnodeActions = ({
const handleClose = () => setIsOpen(false);
const handleActionClick = (action: TBondedMixnodeActions) => {
console.log({ action });
onActionSelect(action);
handleClose();
};
@@ -8,6 +8,7 @@ import { TokenPoolSelector, TPoolOption } from 'src/components/TokenPoolSelector
import { ConfirmTx } from 'src/components/ConfirmTX';
import { useGetFee } from 'src/hooks/useGetFee';
import { validateAmount, validateKey } from 'src/utils';
import { TBondedMixnode } from 'src/context';
export const BondMoreModal = ({
currentBond,
@@ -17,14 +18,15 @@ export const BondMoreModal = ({
onClose,
}: {
currentBond: DecCoin;
mixId: string;
userBalance?: string;
hasVestingTokens: boolean;
onConfirm: (args: { additionalBond: DecCoin; signature: string; tokenPool: TPoolOption }) => Promise<void>;
onConfirm: (args: { additionalBond: DecCoin; tokenPool: TPoolOption }) => Promise<void>;
onClose: () => void;
}) => {
const { fee, resetFeeState } = useGetFee();
const [additionalBond, setAdditionalBond] = useState<DecCoin>({ amount: '0', denom: currentBond.denom });
const [signature, setSignature] = useState<string>('');
// const [signature, setSignature] = useState<string>('');
const [tokenPool, setTokenPool] = useState<TPoolOption>('balance');
const [errorAmount, setErrorAmount] = useState(false);
const [errorSignature, setErrorSignature] = useState(false);
@@ -35,9 +37,9 @@ export const BondMoreModal = ({
signature: false,
};
if (!validateKey(signature || '', 64)) {
errors.signature = true;
}
// if (!validateKey(signature || '', 64)) {
// errors.signature = true;
// }
if (!additionalBond?.amount) {
errors.amount = true;
@@ -47,8 +49,8 @@ export const BondMoreModal = ({
errors.amount = true;
}
if (!errors.amount && !errors.signature) {
onConfirm({ additionalBond, signature, tokenPool });
if (!errors.amount) {
onConfirm({ additionalBond, tokenPool });
} else {
setErrorAmount(errors.amount);
setErrorSignature(errors.signature);
@@ -65,7 +67,7 @@ export const BondMoreModal = ({
header="Bond more details"
open
fee={fee}
onConfirm={async () => onConfirm({ additionalBond, signature, tokenPool })}
onConfirm={async () => onConfirm({ additionalBond, tokenPool })}
onPrev={resetFeeState}
>
<ModalListItem label="Current bond" value={`${currentBond.amount} ${currentBond.denom}`} divider />
@@ -98,7 +100,7 @@ export const BondMoreModal = ({
validationError={errorAmount ? 'Please enter a valid amount' : undefined}
/>
</Box>
{/*
<Box>
<TextField
fullWidth
@@ -108,7 +110,7 @@ export const BondMoreModal = ({
InputLabelProps={{ shrink: true }}
/>
{errorSignature && <FormHelperText sx={{ color: 'error.main' }}>Invalid signature</FormHelperText>}
</Box>
</Box> */}
<Box>
<ModalListItem label="Account balance" value={userBalance?.toUpperCase() || '-'} divider />
+44 -4
View File
@@ -100,7 +100,7 @@ export type TBondingContext = {
bondMixnode: (data: TBondMixNodeArgs, tokenPool: TokenPool) => Promise<TransactionExecuteResult | undefined>;
bondGateway: (data: TBondGatewayArgs, tokenPool: TokenPool) => Promise<TransactionExecuteResult | undefined>;
unbond: (fee?: FeeDetails) => Promise<TransactionExecuteResult | undefined>;
bondMore: (signature: string, amount: DecCoin, fee?: FeeDetails) => Promise<TransactionExecuteResult | undefined>;
bondMore: (amount: DecCoin, mixId: string) => Promise<TransactionExecuteResult | undefined>;
redeemRewards: (fee?: FeeDetails) => Promise<TransactionExecuteResult | undefined>;
updateMixnode: (pm: string, fee?: FeeDetails) => Promise<TransactionExecuteResult | undefined>;
checkOwnership: () => Promise<void>;
@@ -431,9 +431,49 @@ export const BondingContextProvider = ({ children }: { children?: React.ReactNod
return tx;
};
const bondMore = async (_signature: string, _additionalBond: DecCoin) =>
// TODO to implement
undefined;
const bondGatewayaa = async (data: TBondGatewayArgs, tokenPool: TokenPool) => {
let tx: TransactionExecuteResult | undefined;
setIsLoading(true);
try {
if (tokenPool === 'balance') {
tx = await bondGatewayRequest(data);
await userBalance.fetchBalance();
}
if (tokenPool === 'locked') {
tx = await vestingBondGateway(data);
await userBalance.fetchTokenAllocation();
}
return tx;
} catch (e: any) {
Console.warn(e);
setError(`an error occurred: ${e}`);
} finally {
setIsLoading(false);
}
return undefined;
};
const bondMore = async (amount: DecCoin, mixId: string) => {
let tx: TransactionExecuteResult | undefined;
setIsLoading(true);
try {
if (tokenPool === 'balance') {
tx = await bondGatewayRequest(data);
await userBalance.fetchBalance();
}
if (tokenPool === 'locked') {
tx = await vestingBondGateway(data);
await userBalance.fetchTokenAllocation();
}
return tx;
} catch (e: any) {
Console.warn(e);
setError(`an error occurred: ${e}`);
} finally {
setIsLoading(false);
}
return undefined;
};
const memoizedValue = useMemo(
() => ({
+26 -2
View File
@@ -1,6 +1,6 @@
import React, { useContext, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { FeeDetails } from '@nymproject/types';
import { FeeDetails, DecCoin } from '@nymproject/types';
import { Box } from '@mui/material';
import { TPoolOption } from 'src/components';
import { Bond } from 'src/components/Bonding/Bond';
@@ -8,6 +8,7 @@ import { BondedMixnode } from 'src/components/Bonding/BondedMixnode';
import { TBondedMixnodeActions } from 'src/components/Bonding/BondedMixnodeActions';
import { BondGatewayModal } from 'src/components/Bonding/modals/BondGatewayModal';
import { BondMixnodeModal } from 'src/components/Bonding/modals/BondMixnodeModal';
import { BondMoreModal } from 'src/components/Bonding/modals/BondMoreModal';
import { ConfirmationDetailProps, ConfirmationDetailsModal } from 'src/components/Bonding/modals/ConfirmationModal';
import { ErrorModal } from 'src/components/Modals/ErrorModal';
import { LoadingModal } from 'src/components/Modals/LoadingModal';
@@ -29,7 +30,8 @@ const Bonding = () => {
const navigate = useNavigate();
const { bondedNode, bondMixnode, bondGateway, redeemRewards, isLoading, checkOwnership } = useBondingContext();
const { bondedNode, bondMixnode, bondGateway, redeemRewards, isLoading, checkOwnership, bondMore } =
useBondingContext();
const handleCloseModal = async () => {
setShowModal(undefined);
@@ -66,6 +68,17 @@ const Bonding = () => {
});
};
const handleBondMore = async (args: { additionalBond: DecCoin; tokenPool: TPoolOption }) => {
const { additionalBond } = args;
setShowModal(undefined);
const tx = await bondMore(additionalBond, bondedNode.mixId);
setConfirmationDetails({
status: 'success',
title: 'Bond More successful',
txUrl: `${urls(network).blockExplorer}/transaction/${tx?.transaction_hash}`,
});
};
const handleRedeemReward = async (fee?: FeeDetails) => {
setShowModal(undefined);
const tx = await redeemRewards(fee);
@@ -77,6 +90,7 @@ const Bonding = () => {
};
const handleBondedMixnodeAction = (action: TBondedMixnodeActions) => {
console.log({ action });
switch (action) {
case 'bondMore': {
setShowModal('bond-more');
@@ -112,6 +126,7 @@ const Bonding = () => {
{bondedNode && isGateway(bondedNode) && (
<BondedGateway gateway={bondedNode} onActionSelect={handleBondedMixnodeAction} network={network} />
)}
{showModal === 'bond-mixnode' && (
<BondMixnodeModal
denom={clientDetails?.display_mix_denom || 'nym'}
@@ -134,6 +149,15 @@ const Bonding = () => {
/>
)}
{showModal === 'bond-more' && bondedNode && isMixnode(bondedNode) && (
<BondMoreModal
currentBond={bondedNode.bond}
hasVestingTokens={Boolean(originalVesting)}
onConfirm={handleBondMore}
onClose={() => setShowModal(undefined)}
/>
)}
{showModal === 'redeem' && bondedNode && isMixnode(bondedNode) && (
<RedeemRewardsModal
node={bondedNode}
+4 -1
View File
@@ -6,7 +6,7 @@ import {
MixNodeConfigUpdate,
MixNodeCostParams,
} from '@nymproject/types';
import { EnumNodeType, TBondGatewayArgs, TBondMixNodeArgs } from '../types';
import { EnumNodeType, TBondGatewayArgs, TBondMixNodeArgs, TBondMoreArgs } from '../types';
import { invokeWrapper } from './wrapper';
export const bondGateway = async (args: TBondGatewayArgs) =>
@@ -32,3 +32,6 @@ export const unbond = async (type: EnumNodeType) => {
if (type === EnumNodeType.mixnode) return unbondMixNode();
return unbondGateway();
};
export const bondMore = async (args: TBondMoreArgs) =>
invokeWrapper<TransactionExecuteResult>('bond_gateway', args);
+5
View File
@@ -49,6 +49,11 @@ export type TBondMixNodeArgs = {
fee?: Fee;
};
export type TBondMoreArgs = {
mixId: MixNode;
amount: string;
};
export type TNodeDescription = {
name: string;
description: string;