Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Apr 29, 2021
1 parent 67027bd commit 60cb1cf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
30 changes: 15 additions & 15 deletions react-delegationdashboard/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@ 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
);
};

const getAgencyMetaDataType = (value: QueryResponse) => {
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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion react-delegationdashboard/src/pages/Owner/Nodes/NodeRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const getAllNodesStatus = (dapp: DappState, delegationContract?: string)
.queryContract(query)
.then(value => {
let nodes = new Array<NodeType>();
mapNodes(value.outputUntyped(), nodes, []);
const untypedResponse = value.outputUntyped();
mapNodes(untypedResponse, nodes, []);
return resolve(nodes);
})
.catch(e => console.error('GetAllNodesStatus error ', e));
Expand All @@ -39,8 +40,8 @@ export const getBlsKeysStatus = (dapp: DappState, queued: any[], delegationContr
.queryContract(query)
.then(value => {
let nodes = new Array<NodeType>();
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));
Expand Down Expand Up @@ -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));
});
Expand Down

0 comments on commit 60cb1cf

Please sign in to comment.