Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

persist catalyst round info for better UX #2989

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/yoroi-extension/app/api/localStorage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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',
};
Expand Down Expand Up @@ -370,3 +372,14 @@ export async function saveAnalyticsInstanceId(id: string): Promise<void> {
await setLocalItem(storageKeys.ANALYTICS_INSTANCE_ID, id);
}

export async function loadCatalystRoundInfo(): Promise<?CatalystRoundInfoResponse> {
const json = await getLocalItem(storageKeys.CATALYST_ROUND_INFO);
if (!json) {
return undefined;
}
return JSON.parse(json);
}

export async function saveCatalystRoundInfo(data: CatalystRoundInfoResponse): Promise<void> {
await setLocalItem(storageKeys.CATALYST_ROUND_INFO, JSON.stringify(data));
}
21 changes: 18 additions & 3 deletions packages/yoroi-extension/app/stores/ada/VotingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -114,14 +118,23 @@ export default class VotingStore extends Store<StoresMap, ActionsMap> {
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<void> = async () => {
_loadCatalystRoundInfo: void => Promise<void> = async () => {
const data = await loadCatalystRoundInfo();
runInAction(() => {
this.catalystRoundInfo = data;
});
}

@action _updateCatalystRoundInfo: void => Promise<void> = async () => {
runInAction(() => {
this.loadingCatalystRoundInfo = true
})
Expand All @@ -139,7 +152,9 @@ export default class VotingStore extends Store<StoresMap, ActionsMap> {
this.catalystRoundInfo = res
this.loadingCatalystRoundInfo = false
})

if (res) {
await saveCatalystRoundInfo(res);
}
}

@action _goBackToRegister: void => void = () => {
Expand Down