feat(wallet-bonding): create context wip

This commit is contained in:
Mark Sinclair
2022-06-14 11:02:57 +01:00
committed by fmtabbara
parent 47f7a5f795
commit b6448691ce
5 changed files with 128 additions and 0 deletions
@@ -0,0 +1 @@
// TODO
+112
View File
@@ -0,0 +1,112 @@
import { TransactionExecuteResult } from '@nymproject/types';
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
import type { Network } from 'src/types';
import { TBondGatewayArgs, TBondMixNodeArgs } from 'src/types';
import {
bondGateway as bondGatewayRequest,
bondMixNode as bondMixNodeRequest,
claimOperatorRewards,
compoundOperatorRewards,
unbondGateway as unbondGatewayRequest,
unbondMixNode as unbondMixNodeRequest,
} from '../requests';
export type TBondingContext = {
isLoading: boolean;
error?: string;
bondedMixnode?: any; // TODO fix up type
bondedGateway?: any; // TODO fix up type
refresh: () => Promise<void>;
bondMixnode: (data: TBondMixNodeArgs) => Promise<TransactionExecuteResult>;
bondGateway: (data: TBondGatewayArgs) => Promise<TransactionExecuteResult>;
unbondMixnode: () => Promise<TransactionExecuteResult>;
unbondGateway: () => Promise<TransactionExecuteResult>;
redeemRewards: () => Promise<TransactionExecuteResult>;
compoundRewards: () => Promise<TransactionExecuteResult>;
};
export const BondingContext = createContext<TBondingContext>({
isLoading: true,
refresh: async () => undefined,
bondMixnode: async () => {
throw new Error('Not implemented');
},
bondGateway: async () => {
throw new Error('Not implemented');
},
unbondMixnode: async () => {
throw new Error('Not implemented');
},
unbondGateway: async () => {
throw new Error('Not implemented');
},
redeemRewards: async () => {
throw new Error('Not implemented');
},
compoundRewards: async () => {
throw new Error('Not implemented');
},
});
export const BondingContextProvider = ({
network,
children,
}: {
network?: Network;
children?: React.ReactNode;
}): JSX.Element => {
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string>();
const refresh = async () => {
throw new Error('Not implemented');
};
useEffect(() => {
refresh();
}, [network]);
const bondMixnode = async (data: TBondMixNodeArgs) => {
// TODO some logic
return bondMixNodeRequest(data);
};
const bondGateway = async (data: TBondGatewayArgs) => {
// TODO some logic
return bondGatewayRequest(data);
};
const unbondMixnode = async () => {
// TODO some logic
return unbondMixNodeRequest();
};
const unbondGateway = async () => {
// TODO some logic
return unbondGatewayRequest();
};
const redeemRewards = async () => {
// TODO some logic
return claimOperatorRewards();
};
const compoundRewards = async () => {
// TODO some logic
return compoundOperatorRewards();
};
const memoizedValue = useMemo(
() => ({
isLoading,
error,
bondMixnode,
bondGateway,
unbondMixnode,
unbondGateway,
refresh,
redeemRewards,
compoundRewards,
}),
[isLoading, error],
);
return <BondingContext.Provider value={memoizedValue}>{children}</BondingContext.Provider>;
};
export const useBondingContext = () => useContext<TBondingContext>(BondingContext);
+1
View File
@@ -0,0 +1 @@
// TODO
@@ -0,0 +1,13 @@
import * as React from 'react';
import { BondingPage } from './index';
import { MockBondingContextProvider } from '../../context/mocks/delegations';
export default {
title: 'Bonding/Flows/Mock',
};
export const Default = () => (
<MockBondingContextProvider>
<BondingPage />
</MockBondingContextProvider>
);
+1
View File
@@ -0,0 +1 @@
// TODO