Skip to content

Commit

Permalink
Clean up baker version type predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenbf committed Oct 27, 2023
1 parent 2a29a76 commit 7a10da3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import React, { useContext, useEffect, useMemo } from 'react';
import { Link, Route, Routes, useNavigate } from 'react-router-dom';
import {
AccountBakerDetailsV1,
AccountInfo,
AccountInfoBaker,
AccountInfoType,
AccountTransactionType,
ConsensusStatus,
StakePendingChange,
Expand Down Expand Up @@ -34,6 +31,7 @@ import RegisterBaking from './RegisterBaking';
import RemoveBaking from './RemoveBaking';
import UpdateBaking from './UpdateBaking';
import { earnPageContext } from '../utils';
import { isBakerAccountV1 } from './utils';

const routes = {
register: 'register',
Expand Down Expand Up @@ -107,9 +105,6 @@ function DisplayPendingChange({ pendingChange }: DisplayPendingChangeProps) {
);
}

const isBakerAccountV1 = (accountInfo: AccountInfo): accountInfo is AccountInfoBaker =>
accountInfo.type === AccountInfoType.Baker && accountInfo.accountBaker.version === 1;

type BakingDetailsProps = {
bakerDetails: AccountBakerDetailsV1;
};
Expand Down Expand Up @@ -187,7 +182,7 @@ function BakingStatus() {
}
}, []);

if (isBakerAccountV1(accountInfo) && accountInfo.accountBaker.version === 1) {
if (isBakerAccountV1(accountInfo)) {
return <BakingDetails bakerDetails={accountInfo.accountBaker} />;
}
if (hasUpdate && transaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
OpenStatusText,
BakerKeysWithProofs,
AccountInfoType,
AccountInfoBaker,
AccountBakerDetailsV1,
} from '@concordium/web-sdk';
import { decimalToRewardFraction, fractionToPercentage } from '@popup/shared/utils/baking-helpers';
import { getConfigureBakerEnergyCost } from '@shared/utils/energy-helpers';
Expand Down Expand Up @@ -167,3 +169,10 @@ export function getCost(accountInfo: AccountInfo, formValues: Partial<ConfigureB

return getConfigureBakerEnergyCost(toPayload(getConfigureBakerChanges(formValuesFull, accountInfo)));
}

export interface AccountInfoBakerV1 extends AccountInfoBaker {
accountBaker: AccountBakerDetailsV1;
}

export const isBakerAccountV1 = (accountInfo: AccountInfo): accountInfo is AccountInfoBakerV1 =>
accountInfo.type === AccountInfoType.Baker && accountInfo.accountBaker.version === 1;

0 comments on commit 7a10da3

Please sign in to comment.