From 60cb1cf9232b994a8345b06c4373a1d8afcbf778 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 29 Apr 2021 12:01:15 +0300 Subject: [PATCH] Cleanup code --- .../src/components/Layout/index.tsx | 30 +++++++++---------- .../src/pages/Dashboard/Delegation/index.tsx | 14 ++++----- .../Dashboard/PendingUndelegated/index.tsx | 3 +- .../src/pages/Owner/Nodes/NodeRow.tsx | 3 +- .../Owner/Nodes/helpers/keysFunctions.ts | 10 ++++--- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/react-delegationdashboard/src/components/Layout/index.tsx b/react-delegationdashboard/src/components/Layout/index.tsx index b9725a62..2ee48b1d 100644 --- a/react-delegationdashboard/src/components/Layout/index.tsx +++ b/react-delegationdashboard/src/components/Layout/index.tsx @@ -45,23 +45,23 @@ const Layout = ({ children, page }: { children: React.ReactNode; page: string }) } = contractViews; const getContractOverviewType = (value: QueryResponse) => { - let response = value.outputUntyped(); + let untypedResponse = value.outputUntyped(); let initialOwnerFunds = denominate({ decimals, denomination, - input: decodeBigNumber(response[3]).toFixed(), + input: decodeBigNumber(untypedResponse[3]).toFixed(), }); return new ContractOverview( - response[0].toString('hex'), - (decodeUnsignedNumber(response[1]) / 100).toString(), - decodeBigNumber(response[2]).toFixed(), + untypedResponse[0].toString('hex'), + (decodeUnsignedNumber(untypedResponse[1]) / 100).toString(), + decodeBigNumber(untypedResponse[2]).toFixed(), initialOwnerFunds, - decodeString(response[4]), - decodeString(response[5]), - decodeString(response[6]), - decodeString(response[7]), - decodeString(response[8]), - decodeUnsignedNumber(response[9]) * 6 + decodeString(untypedResponse[4]), + decodeString(untypedResponse[5]), + decodeString(untypedResponse[6]), + decodeString(untypedResponse[7]), + decodeString(untypedResponse[8]), + decodeUnsignedNumber(untypedResponse[9]) * 6 ); }; @@ -69,11 +69,11 @@ const Layout = ({ children, page }: { children: React.ReactNode; page: string }) if (value && value.returnData && value.returnData.length === 0) { return emptyAgencyMetaData; } - const response = value.outputUntyped(); + const untypedResponse = value.outputUntyped(); return new AgencyMetadata( - decodeString(response[0]), - decodeString(response[1]), - decodeString(response[2]) + decodeString(untypedResponse[0]), + decodeString(untypedResponse[1]), + decodeString(untypedResponse[2]) ); }; React.useEffect(() => { diff --git a/react-delegationdashboard/src/pages/Dashboard/Delegation/index.tsx b/react-delegationdashboard/src/pages/Dashboard/Delegation/index.tsx index ffb3a1a9..eb58c123 100644 --- a/react-delegationdashboard/src/pages/Dashboard/Delegation/index.tsx +++ b/react-delegationdashboard/src/pages/Dashboard/Delegation/index.tsx @@ -24,31 +24,31 @@ const MyDelegation = () => { dispatch({ type: 'loading', loading: true }); getClaimableRewards(dapp, address, delegationContract) .then(value => { - const response = value.outputUntyped(); - if (response.length > 0 && decodeUnsignedNumber(response[0]) !== 0) { + const untypedResponse = value.outputUntyped(); + if (untypedResponse.length > 0 && decodeUnsignedNumber(untypedResponse[0]) !== 0) { setDisplayRewards(true); } setClaimableRewards( denominate({ denomination, decimals: 4, - input: decodeBigNumber(response[0]).toFixed(), + input: decodeBigNumber(untypedResponse[0]).toFixed(), }) || '' ); }) .catch(e => console.error('getClaimableRewards error', e)); getUserActiveStake(dapp, address, delegationContract) .then(value => { - const response = value.outputUntyped(); + const untypedResponse = value.outputUntyped(); setUserActiveStake( denominate({ denomination, decimals, - input: decodeBigNumber(response[0]).toFixed(), + input: decodeBigNumber(untypedResponse[0]).toFixed(), }) || '' ); - setUserActiveNominatedStake(decodeBigNumber(response[0]).toFixed()); - if (response.length > 0 && decodeUnsignedNumber(response[0]) !== 0) { + setUserActiveNominatedStake(decodeBigNumber(untypedResponse[0]).toFixed()); + if (untypedResponse.length > 0 && decodeUnsignedNumber(untypedResponse[0]) !== 0) { setDisplayUndelegate(true); } diff --git a/react-delegationdashboard/src/pages/Dashboard/PendingUndelegated/index.tsx b/react-delegationdashboard/src/pages/Dashboard/PendingUndelegated/index.tsx index 54697a37..fc61b8ef 100644 --- a/react-delegationdashboard/src/pages/Dashboard/PendingUndelegated/index.tsx +++ b/react-delegationdashboard/src/pages/Dashboard/PendingUndelegated/index.tsx @@ -22,10 +22,11 @@ const UndelegatedListView = () => { }; const getTimeLeft = (value: QueryResponse, index: number, timeLeft: number) => { + const untypedResponse = value.outputUntyped(); let roundsRemainingInEpoch = networkConfig.roundsPerEpoch - networkConfig.roundsPassedInCurrentEpoch; let roundEpochComplete = 0; - let epochsChangesRemaining = decodeUnsignedNumber(value.outputUntyped()[index + 1]); + let epochsChangesRemaining = decodeUnsignedNumber(untypedResponse[index + 1]); if (epochsChangesRemaining > 1) { roundEpochComplete = (epochsChangesRemaining - 1) * networkConfig.roundsPerEpoch; } else { diff --git a/react-delegationdashboard/src/pages/Owner/Nodes/NodeRow.tsx b/react-delegationdashboard/src/pages/Owner/Nodes/NodeRow.tsx index cd5ee5a8..eda5d647 100644 --- a/react-delegationdashboard/src/pages/Owner/Nodes/NodeRow.tsx +++ b/react-delegationdashboard/src/pages/Owner/Nodes/NodeRow.tsx @@ -57,10 +57,11 @@ const NodeRow = ({ blsKey: key }: { blsKey: NodeType; index: number }) => { args: [BytesValue.fromHex(key.blsKey)], }); if (key.status.key === 'unStaked') { + const untypedResponse = value.outputUntyped(); dapp.proxy .queryContract(query) .then(value => { - const remainingUnBondPeriod = decodeUnsignedNumber(value.outputUntyped()[0]); + const remainingUnBondPeriod = decodeUnsignedNumber(untypedResponse[0]); const newRemaining = remainingUnBondPeriod !== undefined ? remainingUnBondPeriod : 0; if (ref.current !== null) { diff --git a/react-delegationdashboard/src/pages/Owner/Nodes/helpers/keysFunctions.ts b/react-delegationdashboard/src/pages/Owner/Nodes/helpers/keysFunctions.ts index 2cc87402..c06ae698 100644 --- a/react-delegationdashboard/src/pages/Owner/Nodes/helpers/keysFunctions.ts +++ b/react-delegationdashboard/src/pages/Owner/Nodes/helpers/keysFunctions.ts @@ -21,7 +21,8 @@ export const getAllNodesStatus = (dapp: DappState, delegationContract?: string) .queryContract(query) .then(value => { let nodes = new Array(); - mapNodes(value.outputUntyped(), nodes, []); + const untypedResponse = value.outputUntyped(); + mapNodes(untypedResponse, nodes, []); return resolve(nodes); }) .catch(e => console.error('GetAllNodesStatus error ', e)); @@ -39,8 +40,8 @@ export const getBlsKeysStatus = (dapp: DappState, queued: any[], delegationContr .queryContract(query) .then(value => { let nodes = new Array(); - let responseValues = value.outputUntyped(); - mapNodes(responseValues.reverse(), nodes, queued); + let untypedResponse = value.outputUntyped(); + mapNodes(untypedResponse.reverse(), nodes, queued); return resolve(nodes); }) .catch(e => console.error('GetBlsKeysStatus error', e)); @@ -72,7 +73,8 @@ export const getQueueIndex = (blsKey: any, dapp: DappState) => { dapp.proxy .queryContract(query) .then(value => { - return resolve(decodeString(value.outputUntyped()[0])); + const untypedResponse = value.outputUntyped(); + return resolve(decodeString(untypedResponse[0])); }) .catch(e => console.error('getQueueIndex error', e)); });