Skip to content

Commit

Permalink
chire: add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat committed Apr 22, 2024
1 parent 5c17a3a commit 5094365
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkadot-staking-dashboard",
"version": "1.4.2",
"version": "1.4.3",
"type": "module",
"license": "GPL-3.0-only",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
49 changes: 21 additions & 28 deletions src/contexts/Migrate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>(null);
Expand All @@ -22,42 +20,37 @@ export const MigrateProvider = ({ children }: { children: ReactNode }) => {
// Store whether the migration check has taken place.
const [done, setDone] = useState<boolean>(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,
//
Expand Down

0 comments on commit 5094365

Please sign in to comment.