diff --git a/packages/yoroi-extension/app/api/localStorage/index.js b/packages/yoroi-extension/app/api/localStorage/index.js index d183008186..35e8192762 100644 --- a/packages/yoroi-extension/app/api/localStorage/index.js +++ b/packages/yoroi-extension/app/api/localStorage/index.js @@ -15,6 +15,7 @@ import { } from '../../utils/tabManager'; import type { ComplexityLevelType } from '../../types/complexityLevelType'; import type { WhitelistEntry } from '../../../chrome/extension/ergo-connector/types'; +import type { CatalystRoundInfoResponse } from '../ada/lib/state-fetch/types' const networkForLocalStorage = String(environment.getNetworkName()); const storageKeys = { @@ -33,6 +34,7 @@ const storageKeys = { WALLETS_NAVIGATION: networkForLocalStorage + '-WALLETS-NAVIGATION', SUBMITTED_TRANSACTIONS: 'submittedTransactions', ANALYTICS_INSTANCE_ID: networkForLocalStorage + '-ANALYTICS', + CATALYST_ROUND_INFO: networkForLocalStorage + '-CATALYST_ROUND_INFO', // ========== CONNECTOR ========== // ERGO_CONNECTOR_WHITELIST: 'connector_whitelist', }; @@ -370,3 +372,14 @@ export async function saveAnalyticsInstanceId(id: string): Promise { await setLocalItem(storageKeys.ANALYTICS_INSTANCE_ID, id); } +export async function loadCatalystRoundInfo(): Promise { + const json = await getLocalItem(storageKeys.CATALYST_ROUND_INFO); + if (!json) { + return undefined; + } + return JSON.parse(json); +} + +export async function saveCatalystRoundInfo(data: CatalystRoundInfoResponse): Promise { + await setLocalItem(storageKeys.CATALYST_ROUND_INFO, JSON.stringify(data)); +} diff --git a/packages/yoroi-extension/app/stores/ada/VotingStore.js b/packages/yoroi-extension/app/stores/ada/VotingStore.js index 36a4f2282a..5dcb328e06 100644 --- a/packages/yoroi-extension/app/stores/ada/VotingStore.js +++ b/packages/yoroi-extension/app/stores/ada/VotingStore.js @@ -46,6 +46,10 @@ import { derivePublicByAddressing } from '../../api/ada/lib/cardanoCrypto/utils' import type { ConceptualWallet } from '../../api/ada/lib/storage/models/ConceptualWallet' import type { CatalystRoundInfoResponse } from '../../api/ada/lib/state-fetch/types' import { trackCatalystRegistration } from '../../api/analytics'; +import { + loadCatalystRoundInfo, + saveCatalystRoundInfo, +} from '../../api/localStorage'; export const ProgressStep = Object.freeze({ GENERATE: 0, @@ -114,14 +118,23 @@ export default class VotingStore extends Store { votingActions.submitTransaction.listen(this._submitTransaction); votingActions.submitTransactionError.listen(this._submitTransactionError); votingActions.cancel.listen(this._cancel); - this.actions.wallets.setActiveWallet.listen(() => {this._getCatalystRoundInfo()}); + this.actions.wallets.setActiveWallet.listen(() => {this._updateCatalystRoundInfo()}); + this._loadCatalystRoundInfo(); + this._updateCatalystRoundInfo(); } get isActionProcessing(): boolean { return this.progressInfo.stepState === StepState.PROCESS; } - @action _getCatalystRoundInfo: void => Promise = async () => { + _loadCatalystRoundInfo: void => Promise = async () => { + const data = await loadCatalystRoundInfo(); + runInAction(() => { + this.catalystRoundInfo = data; + }); + } + + @action _updateCatalystRoundInfo: void => Promise = async () => { runInAction(() => { this.loadingCatalystRoundInfo = true }) @@ -139,7 +152,9 @@ export default class VotingStore extends Store { this.catalystRoundInfo = res this.loadingCatalystRoundInfo = false }) - + if (res) { + await saveCatalystRoundInfo(res); + } } @action _goBackToRegister: void => void = () => {