Skip to content

Commit 46ba65b

Browse files
Merge pull request #28 from phantom/maxim/dx-wallet-state-import
chore: Allow wallet state import
2 parents fc7b8b6 + d6e04ef commit 46ba65b

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

.changeset/cuddly-clouds-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@phantom/synpress': patch
3+
---
4+
5+
Ability to import wallet state

commands/phantom.js

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,53 @@ module.exports = {
282282
await switchToCypressIfNotActive();
283283
return walletAddress;
284284
},
285+
286+
/**
287+
*
288+
* @param {ChromiumBrowser} playwrightInstance The playwright instance
289+
* @param {Object} walletState The wallet local storage state of the extension
290+
* @param {Object} options Options
291+
* @returns
292+
*/
293+
async initialSetupFromWalletState(
294+
playwrightInstance,
295+
walletState,
296+
{ password },
297+
) {
298+
await playwright.init(playwrightInstance);
299+
await playwright.assignWindows(PROVIDER);
300+
await playwright.assignActiveTabName(PROVIDER);
301+
await module.exports.getExtensionDetails();
302+
await playwright.fixBlankPage(
303+
PROVIDER,
304+
playwright.windows(PROVIDER),
305+
app.root,
306+
);
307+
308+
await playwright.switchToWindow(PROVIDER);
309+
310+
await playwright.windows(PROVIDER).evaluate(walletState => {
311+
// eslint-disable-next-line no-undef
312+
chrome.storage.local.set(walletState);
313+
}, walletState);
314+
315+
await playwright
316+
.windows(PROVIDER)
317+
.goto(playwright.windows(PROVIDER).url().replace('onboarding', 'popup'));
318+
319+
await module.exports.unlock(password);
320+
walletAddress = await module.exports.getWalletAddress();
321+
322+
// interstitials are triggered after locking/unlocking
323+
324+
// 1. lock the extension
325+
await module.exports.lock();
326+
327+
// 3. unlock the extension
328+
await module.exports.unlock(password);
329+
330+
return true;
331+
},
285332
async initialSetup(
286333
playwrightInstance,
287334
{
@@ -304,12 +351,6 @@ module.exports = {
304351

305352
await playwright.switchToWindow(PROVIDER);
306353

307-
if (process.env.DEBUG != null) {
308-
await playwright
309-
.windows(PROVIDER)
310-
.on('console', msg => console.log(msg.text()));
311-
}
312-
313354
const isImportButtonVisible = await playwright
314355
.windows(PROVIDER)
315356
.locator(firstTimeFlowPageElements.importWalletButton)

0 commit comments

Comments
 (0)