Skip to content

Commit

Permalink
don't show usage indicator for offchain bundles (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
doerfli committed Jan 13, 2023
1 parent 7ff751a commit c35d06e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/backend/staking_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import stakingApiMock from "./staking_api_mock";
import { StakingApiSmartContract } from "./staking_api_smartcontract";

export interface StakingApi {

getChainId(): Promise<number>;
currency(): string;
currencyDecimals(): number;
minStakedAmount(): BigNumber;
Expand Down
1 change: 1 addition & 0 deletions src/backend/staking_api_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default function stakingApiMock(
enqueueSnackbar: (message: SnackbarMessage, options?: OptionsObject) => SnackbarKey)
: StakingApi {
return {
getChainId: () => Promise.resolve(1234),
currency: (): string => { return "DIP"; },
currencyDecimals: (): number => { return 18; },
minStakedAmount: (): BigNumber => { return parseEther("1000"); },
Expand Down
4 changes: 4 additions & 0 deletions src/backend/staking_api_smartcontract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export class StakingApiSmartContract implements StakingApi {
this.dipDecimals = decimals;
}

async getChainId(): Promise<number> {
return (await this.signer.getChainId());
}

currency(): string {
if (this.dipSymbol === undefined) {
this.initializeDip();
Expand Down
18 changes: 12 additions & 6 deletions src/components/bundle_stakes/bundle_stakes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ export default function BundleStakes(props: BundleStakesProps) {
// retrieve the stake usage data for each bundle (when the props define that stake usage should be displayed)
useEffect(() => {
async function updateStakeUsageData() {
if (props.showStakeLevel && props.bundles.length > 0) {
for (const bundle of props.bundles) {
if (bundle.stakeUsage === undefined) {
const stakeUsage = await props.stakingApi.getStakeUsage(bundle);
dispatch(updateStakeUsage({ bundleId: bundle.bundleId, stakeUsage}));
}
if (!props.showStakeLevel || props.bundles.length == 0) {
return;
}

for (const bundle of props.bundles) {
if (bundle.chainId !== await props.stakingApi.getChainId()) {
continue;
}
if (bundle.stakeUsage !== undefined) {
continue;
}
const stakeUsage = await props.stakingApi.getStakeUsage(bundle);
dispatch(updateStakeUsage({ bundleId: bundle.bundleId, stakeUsage}));
}
}
updateStakeUsageData();
Expand Down

0 comments on commit c35d06e

Please sign in to comment.