Skip to content

Commit

Permalink
fix: solve faucet modal bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasgabrielgsp committed Oct 16, 2024
1 parent e5e743f commit 3c06903
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion source/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const Home = () => {
const handleOnCloseFaucetModal = useCallback(() => {
controllerEmitter(
['wallet', 'setFaucetModalState'],
[{ chainId: activeNetwork.chainId, state: false }]
[{ chainId: activeNetwork.chainId, isOpen: false }]
);
}, [activeNetwork]);

Expand Down
6 changes: 4 additions & 2 deletions source/scripts/Background/controllers/MigrationController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable camelcase */
import paliData from '../../../../package.json';
import v3_0_1 from '../migration/v3_0_1';
import { loadState } from 'state/paliStorage';
import { getIsMigratedVersion, loadState } from 'state/paliStorage';

const MigrationController = async () => {
const state = await loadState(); // get state from Storage API
Expand All @@ -12,11 +12,13 @@ const MigrationController = async () => {
return;
}

const isMigratedVersion = await getIsMigratedVersion(currentPaliVersion);

/**
* version < 3.0.1
* Description: add faucet feature
*/
if (currentPaliVersion === '3.0.1') {
if (currentPaliVersion === '3.0.1' && !isMigratedVersion) {
await v3_0_1(state);
}
};
Expand Down
6 changes: 4 additions & 2 deletions source/scripts/Background/migration/v3_0_1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable camelcase */

import { saveState } from 'state/paliStorage';
import { saveState, setMigratedVersions } from 'state/paliStorage';
import { initialState as initialVaultState } from 'state/vault';
import { IVaultState } from 'state/vault/types';

Expand All @@ -17,7 +17,9 @@ const MigrateRunner = async (oldState: any) => {
shouldShowFaucetModal: initialVaultState.shouldShowFaucetModal,
},
};
await saveState(newState);

await Promise.all([saveState(newState), setMigratedVersions('3.0.1')]);

console.log('Migrate to <v3.0.1> successfully!');
} catch (error) {
console.log('<v3.0.1> Migration Error');
Expand Down
25 changes: 25 additions & 0 deletions source/state/paliStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,28 @@ export const loadState = async () => {
return null;
}
};

export const getIsMigratedVersion = async (version: string) => {
if (!version) {
console.warn('getMigratedVersion ---> Invalid version');
return;
}

const serializedState = await chromeStorage.getItem(version);

return serializedState !== null;
};

export const setMigratedVersions = async (version: string) => {
if (!version) {
console.warn('setMigratedVersions ---> Invalid version');
return;
}

try {
await chromeStorage.setItem(version, 'migrated');
console.log(`${version} ---> implemented`);
} catch (err) {
console.log({ err });
}
};

0 comments on commit 3c06903

Please sign in to comment.