From 509436595d55d33a08d2db99f5ed04609bf18c72 Mon Sep 17 00:00:00 2001 From: Ross Bulat Date: Mon, 22 Apr 2024 19:20:25 +0700 Subject: [PATCH] chire: add migration --- package.json | 2 +- src/consts.ts | 2 +- src/contexts/Migrate/index.tsx | 49 +++++++++++++++------------------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 3ab19e4afb..23dac7d661 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "polkadot-staking-dashboard", - "version": "1.4.2", + "version": "1.4.3", "type": "module", "license": "GPL-3.0-only", "scripts": { diff --git a/src/consts.ts b/src/consts.ts index 8198b4fae9..8f2d74b0c7 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -6,7 +6,7 @@ import { stringToU8a } from '@polkadot/util'; /* * Global Constants */ -export const AppVersion = '1.4.2'; +export const AppVersion = '1.4.3'; export const DappName = 'Polkadot Staking Dashboard'; export const PolkadotUrl = 'https://polkadot.network/features/staking/'; export const ManualSigners = ['ledger', 'vault']; diff --git a/src/contexts/Migrate/index.tsx b/src/contexts/Migrate/index.tsx index 73d0a82b56..0338dad6c3 100644 --- a/src/contexts/Migrate/index.tsx +++ b/src/contexts/Migrate/index.tsx @@ -6,8 +6,6 @@ import { createContext, useState } from 'react'; import { AppVersion } from 'consts'; import { useApi } from 'contexts/Api'; import { useEffectIgnoreInitial } from '@w3ux/hooks'; -import { localStorageOrDefault } from '@w3ux/utils'; -import type { ExternalAccount } from '@w3ux/react-connect-kit/types'; import { useSyncing } from 'hooks/useSyncing'; export const MigrateContext = createContext(null); @@ -22,42 +20,37 @@ export const MigrateProvider = ({ children }: { children: ReactNode }) => { // Store whether the migration check has taken place. const [done, setDone] = useState(localAppVersion === AppVersion); - // Removes `system` added external accounts from local storage. - const removeSystemExternalAccounts = () => { - const current = localStorageOrDefault('external_accounts', [], true); - if (!current.length) { - return; - } - - const updated = - (current as ExternalAccount[])?.filter((a) => a.addedBy !== 'system') || - []; + // Removes local era stakers data and locale data. + const removeLocalErasAndLocales = () => { + console.log('fire update'); + // Remove local exposure and validator data. + localStorage.removeItem('polkadot_validators'); + localStorage.removeItem('polkadot_exposures'); + localStorage.removeItem('polkadot_era_exposures'); - if (!updated.length) { - localStorage.removeItem('external_accounts'); - } else { - localStorage.setItem('external_accounts', JSON.stringify(updated)); - } - }; + localStorage.removeItem('kusama_validators'); + localStorage.removeItem('kusama_exposures'); + localStorage.removeItem('kusama_era_exposures'); - // Removes `westend_era_exposures` from local storage. - const removeWestendEraExposures = () => { + localStorage.removeItem('westend_validators'); + localStorage.removeItem('westend_exposures'); localStorage.removeItem('westend_era_exposures'); + + // Remove locale data. + localStorage.removeItem('lng_resources'); }; useEffectIgnoreInitial(() => { if (isReady && !syncing && !done) { // Carry out migrations if local version is different to current version. if (localAppVersion !== AppVersion) { - // Added in 1.1.2 - // - // Remove local `system` external accounts. - removeSystemExternalAccounts(); - - // Added in 1.1.3 + // Added in 1.4.3 // - // Remove local `era_exposures`. - removeWestendEraExposures(); + // Remove local era stakers data and locale data. Paged rewards are now active and local + // exposure data is now stale. Over subscribed data has also been removed, so locale data + // pertaining to over subscribed validators is also stale and causes errors as keys point to + // undefined data now. + removeLocalErasAndLocales(); // Finally, //