Compare commits

...

1 Commits

Author SHA1 Message Date
fmtabbara dbc68d7426 fix unbond bug 2022-03-29 16:01:40 +01:00
+18 -6
View File
@@ -1,9 +1,10 @@
import React, { useContext, useEffect, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
import { Alert, Box, Button, CircularProgress } from '@mui/material'; import { Alert, Box, Button, CircularProgress } from '@mui/material';
import { useSnackbar } from 'notistack';
import { Fee, NymCard } from '../../components'; import { Fee, NymCard } from '../../components';
import { useCheckOwnership } from '../../hooks/useCheckOwnership'; import { useCheckOwnership } from '../../hooks/useCheckOwnership';
import { ClientContext } from '../../context/main'; import { ClientContext } from '../../context/main';
import { unbond } from '../../requests'; import { unbond, vestingUnbond } from '../../requests';
import { PageLayout } from '../../layouts'; import { PageLayout } from '../../layouts';
export const Unbond = () => { export const Unbond = () => {
@@ -11,6 +12,8 @@ export const Unbond = () => {
const { checkOwnership, ownership } = useCheckOwnership(); const { checkOwnership, ownership } = useCheckOwnership();
const { userBalance, getBondDetails } = useContext(ClientContext); const { userBalance, getBondDetails } = useContext(ClientContext);
const { enqueueSnackbar } = useSnackbar();
useEffect(() => { useEffect(() => {
const initialiseForm = async () => { const initialiseForm = async () => {
await checkOwnership(); await checkOwnership();
@@ -32,11 +35,20 @@ export const Unbond = () => {
disabled={isLoading} disabled={isLoading}
onClick={async () => { onClick={async () => {
setIsLoading(true); setIsLoading(true);
await unbond(ownership.nodeType!); try {
await userBalance.fetchBalance(); if (ownership.vestingPledge) {
await getBondDetails(); await vestingUnbond(ownership.nodeType!);
await checkOwnership(); } else {
setIsLoading(false); await unbond(ownership.nodeType!);
}
} catch (e) {
enqueueSnackbar(`Failed to unbond ${ownership.nodeType}}`, { variant: 'error' });
} finally {
await getBondDetails();
await checkOwnership();
await userBalance.fetchBalance();
setIsLoading(false);
}
}} }}
color="inherit" color="inherit"
> >