-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { IAccountRaw, Migration } from '@/types'; | ||
import { ACCOUNT_HD_WALLET, PROTOCOLS } from '@/constants'; | ||
import { collectVuexState } from './migrationHelpers'; | ||
|
||
const migration: Migration<IAccountRaw[]> = async (restoredValue: IAccountRaw[]) => { | ||
if (!restoredValue?.length) { | ||
const accounts = (await collectVuexState())?.accounts?.list as any[] | undefined; | ||
if (accounts?.length) { | ||
return accounts.reduce( | ||
(list: IAccountRaw[], { protocol, type }: IAccountRaw) => { | ||
if (PROTOCOLS.includes(protocol) && type === ACCOUNT_HD_WALLET) { | ||
list.push({ | ||
isRestored: true, | ||
protocol, | ||
type, | ||
}); | ||
} | ||
return list; | ||
}, | ||
[], | ||
); | ||
} | ||
} | ||
return restoredValue; | ||
}; | ||
|
||
export default migration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { validateMnemonic } from '@aeternity/bip39'; | ||
import type { Migration } from '@/types'; | ||
import { collectVuexState } from './migrationHelpers'; | ||
|
||
const migration: Migration = async (restoredValue: string) => { | ||
if (!restoredValue) { | ||
const mnemonic = (await collectVuexState())?.mnemonic; | ||
if (mnemonic && validateMnemonic(mnemonic)) { | ||
return mnemonic; | ||
} | ||
} | ||
return restoredValue; | ||
}; | ||
|
||
export default migration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { watchUntilTruthy } from '@/utils'; | ||
import { ref } from 'vue'; | ||
|
||
/** | ||
* Before version 2.0.2 we were using Vuex and the whole state was kept as | ||
* one browser/local storage entry. | ||
*/ | ||
export const collectVuexState = (() => { | ||
let vuexState: Record<string, any> | null; | ||
const isCollecting = ref(false); | ||
return async () => { | ||
if (window?.browser) { | ||
if (isCollecting.value) { | ||
await watchUntilTruthy(isCollecting); | ||
} else if (!vuexState) { | ||
isCollecting.value = true; | ||
vuexState = (await window.browser.storage.local.get('state'))?.state as any; | ||
isCollecting.value = false; | ||
} | ||
} | ||
return vuexState; | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters