Skip to content

Commit

Permalink
fix option from taquito
Browse files Browse the repository at this point in the history
  • Loading branch information
Digberi committed Jan 5, 2024
1 parent 938719c commit 1be0e5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/modules/farming/pages/item/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { ZERO_ADDRESS } from '@config/constants';
import { FarmingItemV1Model } from '@modules/farming/models';
import { isTezosToken } from '@shared/helpers';
import { Optional, WhitelistedBaker } from '@shared/types';
import { isTezosToken, unpackOption } from '@shared/helpers';
import { Option, WhitelistedBaker } from '@shared/types';

export const makeBaker = (delegateAddress: Option<string> | string, knownBakers: WhitelistedBaker[]) => {
if (typeof delegateAddress === 'object' && delegateAddress != null && 'Some' in delegateAddress) {
delegateAddress = unpackOption(delegateAddress);
}

export const makeBaker = (delegateAddress: Optional<string>, knownBakers: WhitelistedBaker[]) => {
if (typeof delegateAddress === 'string' && delegateAddress !== ZERO_ADDRESS) {
return knownBakers.find(({ address }) => address === delegateAddress) ?? { address: delegateAddress };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useDexTwoPoolCurrentBaker = () => {
const error = errorData ? new Error(errorData) : null;

return {
currentBaker: { data: makeBaker(bakerAddress, bakers), loading: bakersLoading || bakerAddressLoading, error },
currentBaker: { data: makeBaker(bakerAddress!, bakers), loading: bakersLoading || bakerAddressLoading, error },
canHaveBaker
};
};
12 changes: 9 additions & 3 deletions src/modules/voting/helpers/get-candidate-info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FoundDex } from '@quipuswap/sdk';

import { Nullable, WhitelistedBaker } from '@shared/types';

import { unpackOption } from '@shared/helpers';
import { Nullable, WhitelistedBaker, Option } from '@shared/types';
export interface CandidateInfo {
currentCandidate: Nullable<WhitelistedBaker>;
secondCandidate: Nullable<WhitelistedBaker>;
Expand All @@ -14,7 +14,13 @@ export const getCandidateInfo = (dex: Nullable<FoundDex>, bakers: Array<Whitelis
secondCandidate: null
};
}
const { current_delegated, current_candidate } = dex.storage.storage;
const { current_delegated: _current_delegated, current_candidate: _current_candidate } = dex.storage.storage as {
current_delegated: Option<string>;
current_candidate: Option<string>;
};

const current_delegated = unpackOption(_current_delegated)!;
const current_candidate = unpackOption(_current_candidate)!;

const emptyCurrentDelegated = { address: current_delegated };
const emptyCurrentCandidate = { address: current_candidate };
Expand Down

0 comments on commit 1be0e5f

Please sign in to comment.