Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: select chains using array in import wallet flow #32

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions commands/keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const keplr = {
password,
newAccount,
walletName,
selectedChains,
) {
await module.exports.goToRegistration();
await playwright.waitAndClickByText(
Expand Down Expand Up @@ -158,7 +159,7 @@ const keplr = {
await playwright.keplrWindow(),
);

await module.exports.handleSelectChain();
await module.exports.handleSelectChain(selectedChains);

await playwright.waitForByText(
onboardingElements.phraseAccountCreated,
Expand All @@ -167,20 +168,22 @@ const keplr = {

return true;
},
async handleSelectChain() {
const chainNameExists = await playwright.waitForAndCheckElementExistence(
onboardingElements.chainNameSelector,
);

if (chainNameExists) {
async handleSelectChain(selectedChains) {
for (const chain of selectedChains) {
await playwright.waitAndClickByText(
onboardingElements.chainName,
playwright.keplrWindow(),
);
await playwright.waitAndClick(
onboardingElements.submitChainButton,
chain,
playwright.keplrWindow(),
true,
);
}

await playwright.waitAndClick(
onboardingElements.submitChainButton,
playwright.keplrWindow(),
);

// eslint-disable-next-line no-unused-vars
for (const _ of selectedChains) {
const importButtonExists =
await playwright.waitForAndCheckElementExistence(
onboardingElements.importButtonSelector,
Expand All @@ -191,12 +194,9 @@ const keplr = {
onboardingElements.importButtonSelector,
playwright.keplrWindow(),
);
} else {
break;
}
} else {
await playwright.waitAndClick(
onboardingElements.submitChainButton,
playwright.keplrWindow(),
);
}
},
async importWalletWithPhrase(secretWords) {
Expand Down Expand Up @@ -291,7 +291,13 @@ const keplr = {

async initialSetup(
playwrightInstance,
{ secretWordsOrPrivateKey, password, newAccount, walletName },
{
secretWordsOrPrivateKey,
password,
newAccount,
walletName,
selectedChains,
},
) {
if (playwrightInstance) {
await playwright.init(playwrightInstance);
Expand All @@ -307,6 +313,7 @@ const keplr = {
password,
newAccount,
walletName,
selectedChains,
);
await playwright.switchToCypressWindow();
},
Expand Down
4 changes: 0 additions & 4 deletions pages/keplr/first-time-flow-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ const phraseAccountCreated = 'Account Created!';
const finishButton = 'button[type="button"]';
const textAreaSelector = 'textbox';
const submitPhraseButton = 'button[type="submit"]';
const chainName = 'Agoric local';
const chainNameSelector = 'text=Agoric local';
const importButtonSelector = 'button:has-text("Import")';

module.exports.onboardingElements = {
existingWalletButton,
createWalletButton,
importRecoveryPhraseButton,
useRecoveryPhraseButton,
chainNameSelector,
importButtonSelector,
phraseCount24,
phrasePrivateKey,
Expand All @@ -37,5 +34,4 @@ module.exports.onboardingElements = {
finishButton,
textAreaSelector,
submitPhraseButton,
chainName,
};
2 changes: 2 additions & 0 deletions plugins/keplr-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ module.exports = (on, config) => {
password,
newAccount,
walletName,
selectedChains,
}) => {
await keplr.initialSetup(null, {
secretWordsOrPrivateKey,
password,
newAccount,
walletName,
selectedChains,
});
return true;
},
Expand Down
2 changes: 2 additions & 0 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ Cypress.Commands.add('setupWallet', (args = {}) => {
password = 'Test1234',
newAccount = false,
walletName = 'My Wallet',
selectedChains = [],
} = args;
return cy.task('setupWallet', {
secretWordsOrPrivateKey:
Expand All @@ -426,6 +427,7 @@ Cypress.Commands.add('setupWallet', (args = {}) => {
password,
newAccount,
walletName,
selectedChains,
});
});

Expand Down
1 change: 1 addition & 0 deletions support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ declare namespace Cypress {
password?: string;
newAccount?: boolean;
walletName?: string;
selectedChains?: Array<string>;
}): Chainable<Subject>;
}
}
2 changes: 2 additions & 0 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('Keplr', () => {
password: 'Test1234',
newAccount: true,
walletName: 'My Wallet 2',
selectedChains: ['Agoric localhost', 'Secret Network'],
}).then(setupFinished => {
expect(setupFinished).to.be.true;
});
Expand All @@ -71,6 +72,7 @@ describe('Keplr', () => {
privateKey:
'A9C09B6E4AF70DE1F1B621CB1AA66CFD0B4AA977E4C18497C49132DD9E579485',
walletName: 'My wallet 3',
selectedChains: ['Agoric localhost'],
}).then(setupFinished => {
expect(setupFinished).to.be.true;
});
Expand Down
Loading