Skip to content

Commit

Permalink
merge switch wallet PR and resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Mar 5, 2024
2 parents 9ff28d3 + 1638199 commit 7c1c89e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
37 changes: 31 additions & 6 deletions commands/keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let extensionVersion;
let registrationUrl;
let permissionsUrl;
let popupUrl;
let walletsPageUrl;
let switchBackToCypressWindow;
let walletAddress;

Expand All @@ -24,9 +25,11 @@ const keplr = {
permissionsUrl = undefined;
popupUrl = undefined;
walletAddress = undefined;
walletsPageUrl = undefined;
},
walletAddress: () => {
return walletAddress;

},
extensionId: () => {
return extensionId;
Expand Down Expand Up @@ -54,6 +57,9 @@ const keplr = {
async goToHome() {
await module.exports.goTo(popupUrl);
},
async goToWalletsPage() {
await module.exports.goTo(walletsPageUrl);
},
async switchToKeplrIfNotActive() {
if (playwright.isCypressWindowActive()) {
await playwright.switchToKeplrWindow();
Expand All @@ -69,13 +75,15 @@ const keplr = {
registrationUrl = `chrome-extension://${extensionId}/register.html`;
permissionsUrl = `chrome-extension://${extensionId}/popup.html#/setting/security/permission`;
popupUrl = `chrome-extension://${extensionId}/popup.html`;
walletsPageUrl = `chrome-extension://${extensionId}/popup.html#/wallet/select`;

return {
extensionId,
extensionVersion,
registrationUrl,
permissionsUrl,
popupUrl,
walletsPageUrl,
};
},
async disconnectWalletFromDapp() {
Expand All @@ -86,7 +94,12 @@ const keplr = {
);
return true;
},
async importWallet(secretWordsOrPrivateKey, password, newAccount) {
async importWallet(
secretWordsOrPrivateKey,
password,
newAccount,
walletName,
) {
await module.exports.goToRegistration();
await playwright.waitAndClickByText(
newAccount
Expand Down Expand Up @@ -120,10 +133,7 @@ const keplr = {
);
}

await playwright.waitAndType(
onboardingElements.walletInput,
onboardingElements.walletName,
);
await playwright.waitAndType(onboardingElements.walletInput, walletName);

const passwordFieldExists =
await playwright.waitForAndCheckElementExistence(
Expand Down Expand Up @@ -242,7 +252,7 @@ const keplr = {

async initialSetup(
playwrightInstance,
{ secretWordsOrPrivateKey, password, newAccount },
{ secretWordsOrPrivateKey, password, newAccount, walletName },
) {
if (playwrightInstance) {
await playwright.init(playwrightInstance);
Expand All @@ -257,9 +267,24 @@ const keplr = {
secretWordsOrPrivateKey,
password,
newAccount,
walletName,
);
await playwright.switchToCypressWindow();
},

async switchWallet({ walletName }) {
await module.exports.switchToKeplrIfNotActive();
await module.exports.goToWalletsPage();

await playwright.waitAndClickByText(
walletName,
playwright.keplrWindow(),
true,
);
await playwright.switchToCypressWindow();

return true;
},
};

module.exports = keplr;
7 changes: 2 additions & 5 deletions pages/keplr/first-time-flow-page.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const createWalletButton = 'Create a new wallet';
const existingWalletButton = 'Import an existing wallet';
const importRecoveryPhraseButton = 'Import existing recovery phrase';
const importRecoveryPhraseButton = 'Import existing recovery phrase';
const useRecoveryPhraseButton = 'Use recovery phrase or private key';
const phraseCount24 = '24 words';
const phrasePrivateKey = 'Private key';
const walletInput = 'input[name="name"]:focus';
const passwordInput = 'input[name="password"]';
const confirmPasswordInput = 'input[name="confirmPassword"]';
const walletName = 'My wallet';
const submitWalletDataButton = 'button[type="submit"]';
const phraseSelectChain = 'Select Chains';
const submitChainButton = 'button[type="button"]';
Expand All @@ -24,7 +23,6 @@ module.exports.onboardingElements = {
phraseCount24,
phrasePrivateKey,
walletInput,
walletName,
passwordInput,
confirmPasswordInput,
submitWalletDataButton,
Expand All @@ -33,6 +31,5 @@ module.exports.onboardingElements = {
phraseAccountCreated,
finishButton,
textAreaSelector,
submitChainButton,
submitPhraseButton,
};
};
9 changes: 8 additions & 1 deletion plugins/keplr-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,21 @@ module.exports = (on, config) => {
confirmTransaction: keplr.confirmTransaction,
rejectTransaction: keplr.rejectTransaction,
disconnectWalletFromDapp: keplr.disconnectWalletFromDapp,
setupWallet: async ({ secretWordsOrPrivateKey, password, newAccount }) => {
setupWallet: async ({
secretWordsOrPrivateKey,
password,
newAccount,
walletName,
}) => {
await keplr.initialSetup(null, {
secretWordsOrPrivateKey,
password,
newAccount,
walletName,
});
return true;
},
switchWallet: keplr.switchWallet,
});

return config;
Expand Down
7 changes: 6 additions & 1 deletion support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,13 @@ Cypress.Commands.add(
secretWordsOrPrivateKey = 'orbit bench unit task food shock brand bracket domain regular warfare company announce wheel grape trust sphere boy doctor half guard ritual three ecology',
password = 'Test1234',
newAccount = false,
walletName = 'My Wallet',
) => {
return cy.task('setupWallet', {
secretWordsOrPrivateKey,
password,
newAccount,
walletName,
});
},
);
Expand Down Expand Up @@ -457,4 +459,7 @@ Cypress.Commands.add('getWalletAddress', () => {
cy.task('getWalletAddress').then(address => {
return address;
});
});
});
Cypress.Commands.add('switchWallet', walletName => {
return cy.task('switchWallet', { walletName });
});
10 changes: 10 additions & 0 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,27 @@ describe('Keplr', () => {
'orbit bench unit task food shock brand bracket domain regular warfare company announce wheel grape trust sphere boy doctor half guard ritual three ecology',
'Test1234',
true,
'My Wallet 2',
).then(setupFinished => {
expect(setupFinished).to.be.true;
});
});
it(`should complete Keplr setup by importing the wallet using private key`, () => {
cy.setupWallet(
'A9C09B6E4AF70DE1F1B621CB1AA66CFD0B4AA977E4C18497C49132DD9E579485',
null,
false,
'My wallet 3',
).then(setupFinished => {
expect(setupFinished).to.be.true;
});
});
it(`should switch to new wallet by name`, () => {
cy.switchWallet('My Wallet 2').then(taskCompleted => {
expect(taskCompleted).to.be.true;
});
// TODO: Add some more robust check later
});
it(`should disconnect the wallet from all the connected DAPPs`, () => {
cy.disconnectWalletFromDapp().then(taskCompleted => {
expect(taskCompleted).to.be.true;
Expand Down

0 comments on commit 7c1c89e

Please sign in to comment.