diff --git a/.github/actions/install-vega-binaries/action.yml b/.github/actions/install-vega-binaries/action.yml index c88ae7660..eec73d5fe 100644 --- a/.github/actions/install-vega-binaries/action.yml +++ b/.github/actions/install-vega-binaries/action.yml @@ -15,14 +15,3 @@ runs: run: | wget 'https://github.com/vegaprotocol/vega/releases/download/${{ inputs.version }}/vega-linux-amd64.zip' -q unzip vega-linux-amd64.zip -d ${{ inputs.gobin }} - - - name: Checkout vegawallet-dummy - uses: actions/checkout@v3 - with: - repository: 'vegaprotocol/vegawallet-dummy' - path: './dummy' - - - name: Install vegawallet-dummy binaries - shell: bash - run: go install - working-directory: ./dummy diff --git a/.github/actions/setup-vegawallet-docker/action.yml b/.github/actions/setup-vegawallet-docker/action.yml index 9dfd40fbe..88274eff3 100644 --- a/.github/actions/setup-vegawallet-docker/action.yml +++ b/.github/actions/setup-vegawallet-docker/action.yml @@ -1,6 +1,10 @@ inputs: passphrase: description: 'Wallet password' +outputs: + token: + description: 'api-token of wallet' + value: ${{ steps.generate-api-token.outputs.api-token }} runs: using: 'composite' steps: @@ -20,6 +24,15 @@ runs: shell: bash run: vega wallet network import --force --from-file ./frontend-monorepo/vegacapsule/wallet-config.toml --home ~/.vegacapsule/testnet/wallet + - name: Init api-token + shell: bash + run: vega wallet api-token init --home ~/.vegacapsule/testnet/wallet --passphrase-file passphrase + + - name: Generate api-token + id: generate-api-token + shell: bash + run: echo api-token=$(vega wallet api-token generate --wallet-name capsule_wallet --tokens-passphrase-file passphrase --wallet-passphrase-file passphrase --home ~/.vegacapsule/testnet/wallet | grep -Eo '[a-zA-Z0-9]{64}') >> $GITHUB_OUTPUT + - name: Start service using capsule network shell: bash - run: vegawallet-dummy service run --network DV --wallet capsule_wallet --passphrase-file ./passphrase --home ~/.vegacapsule/testnet/wallet & + run: vega wallet service run -n DV --load-tokens --tokens-passphrase-file passphrase --no-version-check --automatic-consent --home ~/.vegacapsule/testnet/wallet & diff --git a/.github/actions/setup-vegawallet/action.yml b/.github/actions/setup-vegawallet/action.yml index d4e87d8d2..796fbce44 100644 --- a/.github/actions/setup-vegawallet/action.yml +++ b/.github/actions/setup-vegawallet/action.yml @@ -3,6 +3,10 @@ inputs: description: 'Recovery phrase' passphrase: description: 'Wallet password' +outputs: + token: + description: 'api-token of wallet' + value: ${{ steps.generate-api-token.outputs.api-token }} runs: using: 'composite' steps: @@ -30,6 +34,15 @@ runs: shell: bash run: vega wallet network import --from-url="https://raw.githubusercontent.com/vegaprotocol/networks-internal/main/stagnet3/vegawallet-stagnet3.toml" --force --home ~/.vegacapsule/testnet/wallet + - name: Init api-token + shell: bash + run: vega wallet api-token init --home ~/.vegacapsule/testnet/wallet --passphrase-file passphrase + + - name: Generate api-token + id: generate-api-token + shell: bash + run: echo api-token=$(vega wallet api-token generate --wallet-name UI_Trading_Test --tokens-passphrase-file passphrase --wallet-passphrase-file passphrase --home ~/.vegacapsule/testnet/wallet | grep -Eo '[a-zA-Z0-9]{64}') >> $GITHUB_OUTPUT + - name: Start service using stagnet3 network shell: bash - run: vegawallet-dummy service run --network stagnet3 --wallet UI_Trading_Test --passphrase-file ./passphrase --home ~/.vegacapsule/testnet/wallet & + run: vega wallet service run -n stagnet3 --load-tokens --tokens-passphrase-file passphrase --no-version-check --automatic-consent --home ~/.vegacapsule/testnet/wallet & diff --git a/.github/workflows/capsule-cypress-manual-trigger.yml b/.github/workflows/capsule-cypress-manual-trigger.yml index 7d256c4c4..50c07126c 100644 --- a/.github/workflows/capsule-cypress-manual-trigger.yml +++ b/.github/workflows/capsule-cypress-manual-trigger.yml @@ -28,7 +28,7 @@ on: default: false env: GOBIN: /home/runner/go/bin - VEGA_VERSION: 'v0.62.1' + VEGA_VERSION: 'v0.63.1' jobs: manual: diff --git a/.github/workflows/capsule-cypress-night-run.yml b/.github/workflows/capsule-cypress-night-run.yml index 644fea74a..bdcf149b5 100644 --- a/.github/workflows/capsule-cypress-night-run.yml +++ b/.github/workflows/capsule-cypress-night-run.yml @@ -13,7 +13,7 @@ jobs: secrets: inherit with: project: '[console-lite-e2e, explorer-e2e, liquidity-provision-dashboard-e2e, stats-e2e, token-e2e, trading-e2e]' - vega-version: 'v0.62.1' + vega-version: 'v0.63.1' gobin: /home/runner/go/bin tags: --env.grepTags '[ @smoke, @regression, @slow ]' night-run: true diff --git a/.github/workflows/capsule-cypress.yml b/.github/workflows/capsule-cypress.yml index 011bb4464..468e0361b 100644 --- a/.github/workflows/capsule-cypress.yml +++ b/.github/workflows/capsule-cypress.yml @@ -14,7 +14,7 @@ on: env: GOBIN: /home/runner/go/bin - VEGA_VERSION: 'v0.62.1' + VEGA_VERSION: 'v0.63.1' jobs: pr: diff --git a/.github/workflows/cypress-console-lite-e2e.yml b/.github/workflows/cypress-console-lite-e2e.yml index cbc6e09c0..4d32785a0 100644 --- a/.github/workflows/cypress-console-lite-e2e.yml +++ b/.github/workflows/cypress-console-lite-e2e.yml @@ -66,6 +66,7 @@ jobs: ###### - name: Set up Vegawallet + id: setup-vega uses: ./frontend-monorepo/.github/actions/setup-vegawallet with: recovery: ${{ secrets.TRADING_TEST_VEGA_WALLET_RECOVERY }} @@ -83,3 +84,4 @@ jobs: CYPRESS_TRADING_TEST_VEGA_WALLET_PASSPHRASE: ${{ secrets.CYPRESS_TRADING_TEST_VEGA_WALLET_PASSPHRASE }} CYPRESS_SLACK_WEBHOOK: ${{ secrets.CYPRESS_SLACK_WEBHOOK }} CYPRESS_ETH_WALLET_MNEMONIC: ${{ secrets.CYPRESS_ETH_WALLET_MNEMONIC }} + CYPRESS_VEGA_WALLET_API_TOKEN: ${{ steps.setup-vega.outputs.token }} diff --git a/.github/workflows/cypress-explorer-e2e.yml b/.github/workflows/cypress-explorer-e2e.yml index e10b16c63..3abeebe19 100644 --- a/.github/workflows/cypress-explorer-e2e.yml +++ b/.github/workflows/cypress-explorer-e2e.yml @@ -76,6 +76,7 @@ jobs: ###### - name: Set up Vegawallet for docker + id: setup-vega uses: ./frontend-monorepo/.github/actions/setup-vegawallet-docker with: passphrase: ${{ secrets.CYPRESS_TRADING_TEST_VEGA_WALLET_PASSPHRASE }} @@ -97,6 +98,7 @@ jobs: CYPRESS_SLACK_WEBHOOK: ${{ secrets.CYPRESS_SLACK_WEBHOOK }} CYPRESS_ETH_WALLET_MNEMONIC: ${{ secrets.CYPRESS_ETH_WALLET_MNEMONIC }} CYPRESS_NIGHTLY_RUN: ${{ inputs.night-run }} + CYPRESS_VEGA_WALLET_API_TOKEN: ${{ steps.setup-vega.outputs.token }} ###### ## Upload logs diff --git a/.github/workflows/cypress-token-e2e.yml b/.github/workflows/cypress-token-e2e.yml index af442ad0d..5976fed5c 100644 --- a/.github/workflows/cypress-token-e2e.yml +++ b/.github/workflows/cypress-token-e2e.yml @@ -72,6 +72,7 @@ jobs: ###### - name: Set up Vegawallet for docker + id: setup-vega uses: ./frontend-monorepo/.github/actions/setup-vegawallet-docker with: passphrase: ${{ secrets.CYPRESS_TRADING_TEST_VEGA_WALLET_PASSPHRASE }} @@ -92,6 +93,7 @@ jobs: CYPRESS_TRADING_TEST_VEGA_WALLET_PASSPHRASE: ${{ secrets.CYPRESS_TRADING_TEST_VEGA_WALLET_PASSPHRASE }} CYPRESS_SLACK_WEBHOOK: ${{ secrets.CYPRESS_SLACK_WEBHOOK }} CYPRESS_ETH_WALLET_MNEMONIC: ${{ secrets.CYPRESS_ETH_WALLET_MNEMONIC }} + CYPRESS_VEGA_WALLET_API_TOKEN: ${{ steps.setup-vega.outputs.token }} ###### ## Upload logs diff --git a/.github/workflows/cypress-trading-e2e.yml b/.github/workflows/cypress-trading-e2e.yml index 3f33a3c49..a278748c3 100644 --- a/.github/workflows/cypress-trading-e2e.yml +++ b/.github/workflows/cypress-trading-e2e.yml @@ -67,6 +67,7 @@ jobs: ###### - name: Set up Vegawallet + id: setup-vega uses: ./frontend-monorepo/.github/actions/setup-vegawallet with: recovery: ${{ secrets.TRADING_TEST_VEGA_WALLET_RECOVERY }} @@ -84,3 +85,4 @@ jobs: CYPRESS_TRADING_TEST_VEGA_WALLET_PASSPHRASE: ${{ secrets.CYPRESS_TRADING_TEST_VEGA_WALLET_PASSPHRASE }} CYPRESS_SLACK_WEBHOOK: ${{ secrets.CYPRESS_SLACK_WEBHOOK }} CYPRESS_ETH_WALLET_MNEMONIC: ${{ secrets.CYPRESS_ETH_WALLET_MNEMONIC }} + CYPRESS_VEGA_WALLET_API_TOKEN: ${{ steps.setup-vega.outputs.token }} diff --git a/README.md b/README.md index 906f21243..885ad1549 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Run `nx test my-app` to execute the unit tests with [Jest](https://jestjs.io), o ### Using wallet -To run tests locally using your own wallets make sure you have generated at least two public keys and update the following environment variables in `cypress.config.js` to match your wallet. You should also use [vegawallet-dummy](https://github.com/vegaprotocol/vegawallet-dummy) to avoid being prompted in CLI during test execution. +To run tests locally using your own wallets make sure you have generated at least two public keys and update the following environment variables in `cypress.config.js` to match your wallet. 1. Set `VEGA_PUBLIC_KEY` and `TRUNCATED_VEGA_PUBLIC_KEY` to your first public key. 2. Set `VEGA_PUBLIC_KEY2` and `TRUNCATED_VEGA_PUBLIC_KEY2` to your second public key. diff --git a/apps/console-lite-e2e/.env b/apps/console-lite-e2e/.env index 06fb8b153..e99c2a8c3 100644 --- a/apps/console-lite-e2e/.env +++ b/apps/console-lite-e2e/.env @@ -7,3 +7,4 @@ NX_ETHERSCAN_URL=https://sepolia.etherscan.io NX_VEGA_EXPLORER_URL=https://stagnet3.explorer.vega.xyz NX_VEGA_WALLET_URL=http://localhost:1789 CYPRESS_VEGA_ENV=STAGNET3 +CYPRESS_VEGA_WALLET_API_TOKEN= diff --git a/apps/explorer-e2e/.env b/apps/explorer-e2e/.env index 27605548f..7971c46e4 100644 --- a/apps/explorer-e2e/.env +++ b/apps/explorer-e2e/.env @@ -16,3 +16,5 @@ NX_EXPLORER_TXS_LIST=0 NX_EXPLORER_NETWORK_PARAMETERS=1 NX_EXPLORER_PARTIES=1 NX_EXPLORER_VALIDATORS=1 + +CYPRESS_VEGA_WALLET_API_TOKEN= diff --git a/apps/explorer-e2e/src/integration/asset.cy.js b/apps/explorer-e2e/src/integration/asset.cy.js index 90e9da744..90aaad358 100644 --- a/apps/explorer-e2e/src/integration/asset.cy.js +++ b/apps/explorer-e2e/src/integration/asset.cy.js @@ -47,34 +47,37 @@ context('Asset page', { tags: '@regression' }, function () { .then((assetsListedInJson) => { const assetInfo = this.assetsInfo[assetName]; - assert.equal(assetsListedInJson.name, assetInfo.name); - assert.equal(assetsListedInJson.id, assetInfo.id); - assert.equal(assetsListedInJson.decimals, assetInfo.decimals); - assert.equal(assetsListedInJson.symbol, assetInfo.symbol); + assert.equal(assetsListedInJson.name, assetInfo.node.name); + assert.equal(assetsListedInJson.id, assetInfo.node.id); + assert.equal( + assetsListedInJson.decimals, + assetInfo.node.decimals + ); + assert.equal(assetsListedInJson.symbol, assetInfo.node.symbol); assert.equal( assetsListedInJson.source.__typename, - assetInfo.source.__typename + assetInfo.node.source.__typename ); - if (assetInfo.source.__typename == 'ERC20') { + if (assetInfo.node.source.__typename == 'ERC20') { assert.equal( assetsListedInJson.source.contractAddress, - assetInfo.source.contractAddress + assetInfo.node.source.contractAddress ); } - if (assetInfo.source.__typename == 'BuiltinAsset') { + if (assetInfo.node.source.__typename == 'BuiltinAsset') { assert.equal( assetsListedInJson.source.maxFaucetAmountMint, - assetInfo.source.maxFaucetAmountMint + assetInfo.node.source.maxFaucetAmountMint ); } let knownAssetTypes = ['BuiltinAsset', 'ERC20']; assert.include( knownAssetTypes, - assetInfo.source.__typename, - `Checking that current asset type of ${assetInfo.source.__typename} / + assetInfo.node.source.__typename, + `Checking that current asset type of ${assetInfo.node.source.__typename} / is one of: ${knownAssetTypes}: / If fail then we need to add extra tests for un-encountered asset types` ); diff --git a/apps/explorer-e2e/src/integration/home.cy.js b/apps/explorer-e2e/src/integration/home.cy.js index 7d77acb38..5389d184b 100644 --- a/apps/explorer-e2e/src/integration/home.cy.js +++ b/apps/explorer-e2e/src/integration/home.cy.js @@ -50,7 +50,7 @@ context('Home Page', function () { .invoke('text') .should('match', /\d+d \d+h \d+m \d+s/i); cy.get(statsValue).eq(3).should('have.text', '2'); - cy.get(statsValue).eq(4).should('have.text', '0'); + cy.get(statsValue).eq(4).should('have.text', '2'); cy.get(statsValue) .eq(5) .invoke('text') diff --git a/apps/explorer-e2e/src/integration/validator.cy.js b/apps/explorer-e2e/src/integration/validator.cy.js index 1cd396fa2..4b0a44266 100644 --- a/apps/explorer-e2e/src/integration/validator.cy.js +++ b/apps/explorer-e2e/src/integration/validator.cy.js @@ -279,9 +279,9 @@ context('Validator page', { tags: '@smoke' }, function () { Cypress.Commands.add('get_nodes', () => { const mutation = - '{nodes { id name infoUrl avatarUrl pubkey tmPubkey ethereumAddress \ + '{nodesConnection { edges { node { id name infoUrl avatarUrl pubkey tmPubkey ethereumAddress \ location stakedByOperator stakedByDelegates stakedTotal pendingStake \ - epochData { total offline online __typename } status name __typename}}'; + epochData { total offline online __typename } status name __typename}}}}'; cy.request({ method: 'POST', url: `http://localhost:3028/query`, @@ -290,7 +290,7 @@ context('Validator page', { tags: '@smoke' }, function () { }, headers: { 'content-type': 'application/json' }, }) - .its(`body.data.nodes`) + .its(`body.data.nodesConnection.edges`) .then(function (response) { let nodes = []; response.forEach((node) => { diff --git a/apps/token-e2e/.env b/apps/token-e2e/.env index f3f47f675..a10606598 100644 --- a/apps/token-e2e/.env +++ b/apps/token-e2e/.env @@ -15,3 +15,4 @@ NX_VEGA_DOCS_URL=https://docs.vega.xyz/mainnet #Test configuration variables CYPRESS_FAIRGROUND=false +CYPRESS_VEGA_WALLET_API_TOKEN= diff --git a/apps/token-e2e/src/integration/flow/governance-flow.cy.js b/apps/token-e2e/src/integration/flow/governance-flow.cy.js index c857246b3..53e4cfa90 100644 --- a/apps/token-e2e/src/integration/flow/governance-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/governance-flow.cy.js @@ -130,7 +130,7 @@ context( beforeEach('visit governance tab', function () { cy.reload(); cy.wait_for_spinner(); - cy.vega_wallet_connect(); + cy.connectVegaWallet(); cy.ethereum_wallet_connect(); cy.navigate_to('governance'); cy.wait_for_spinner(); @@ -427,82 +427,78 @@ context( }); // 3001-VOTE-080 3001-VOTE-090 - it( - 'Newly created proposal details - ability to vote for and against proposal - with minimum required tokens associated', - { tags: '@smoke' }, - function () { - createRawProposal(this.minProposerBalance); - cy.get('@rawProposal').then((rawProposal) => { - cy.get_submitted_proposal_from_proposal_list( - rawProposal.rationale.title - ).within(() => cy.get(viewProposalButton).click()); - }); - // 3001-VOTE-080 - cy.get(voteButtons).contains('against').should('be.visible'); - cy.get(voteButtons).contains('for').should('be.visible'); - cy.vote_for_proposal('for'); - cy.get_governance_proposal_date_format_for_specified_days( - '0', - 'shortMonth' - ).then((votedDate) => { - // 3001-VOTE-051 - // 3001-VOTE-093 - cy.contains('You voted:') - .siblings() - .contains('For') - .siblings() - .contains(votedDate) - .should('be.visible'); - }); - cy.get(proposalVoteProgressForPercentage) - .contains('100.00%') - .and('be.visible'); - cy.get(proposalVoteProgressAgainstPercentage) - .contains('0.00%') - .and('be.visible'); - cy.get(proposalVoteProgressForTokens) - .contains('1.00') - .and('be.visible'); - cy.get(proposalVoteProgressAgainstTokens) - .contains('0.00') - .and('be.visible'); - cy.get_proposal_information_from_table('Tokens for proposal') - .should('have.text', parseFloat(this.minProposerBalance).toFixed(2)) - .and('be.visible'); - cy.get_proposal_information_from_table('Tokens against proposal') - .should('have.text', '0.00') - .and('be.visible'); - // 3001-VOTE-061 - cy.get_proposal_information_from_table('Participation required') - .contains(`${this.requiredParticipation}%`) + it('Newly created proposal details - ability to vote for and against proposal - with minimum required tokens associated', function () { + createRawProposal(this.minProposerBalance); + cy.get('@rawProposal').then((rawProposal) => { + cy.get_submitted_proposal_from_proposal_list( + rawProposal.rationale.title + ).within(() => cy.get(viewProposalButton).click()); + }); + // 3001-VOTE-080 + cy.get(voteButtons).contains('against').should('be.visible'); + cy.get(voteButtons).contains('for').should('be.visible'); + cy.vote_for_proposal('for'); + cy.get_governance_proposal_date_format_for_specified_days( + '0', + 'shortMonth' + ).then((votedDate) => { + // 3001-VOTE-051 + // 3001-VOTE-093 + cy.contains('You voted:') + .siblings() + .contains('For') + .siblings() + .contains(votedDate) .should('be.visible'); - // 3001-VOTE-066 - cy.get_proposal_information_from_table('Majority Required') - .contains(`${parseFloat(this.requiredMajority).toFixed(2)}%`) - .should('be.visible'); - cy.get_proposal_information_from_table('Number of voting parties') - .should('have.text', '1') - .and('be.visible'); - cy.get(changeVoteButton).should('be.visible').click(); - cy.vote_for_proposal('for'); - // 3001-VOTE-064 - cy.get_proposal_information_from_table('Tokens for proposal') - .should('have.text', parseFloat(this.minProposerBalance).toFixed(2)) - .and('be.visible'); - cy.wait_for_spinner(); - cy.get(changeVoteButton).should('be.visible').click(); - cy.vote_for_proposal('against'); - cy.get(proposalVoteProgressAgainstPercentage) - .contains('100.00%') - .and('be.visible'); - cy.get_proposal_information_from_table('Tokens against proposal') - .should('have.text', parseFloat(this.minProposerBalance).toFixed(2)) - .and('be.visible'); - cy.get_proposal_information_from_table('Number of voting parties') - .should('have.text', '1') - .and('be.visible'); - } - ); + }); + cy.get(proposalVoteProgressForPercentage) + .contains('100.00%') + .and('be.visible'); + cy.get(proposalVoteProgressAgainstPercentage) + .contains('0.00%') + .and('be.visible'); + cy.get(proposalVoteProgressForTokens) + .contains('1.00') + .and('be.visible'); + cy.get(proposalVoteProgressAgainstTokens) + .contains('0.00') + .and('be.visible'); + cy.get_proposal_information_from_table('Tokens for proposal') + .should('have.text', parseFloat(this.minProposerBalance).toFixed(2)) + .and('be.visible'); + cy.get_proposal_information_from_table('Tokens against proposal') + .should('have.text', '0.00') + .and('be.visible'); + // 3001-VOTE-061 + cy.get_proposal_information_from_table('Participation required') + .contains(`${this.requiredParticipation}%`) + .should('be.visible'); + // 3001-VOTE-066 + cy.get_proposal_information_from_table('Majority Required') + .contains(`${parseFloat(this.requiredMajority).toFixed(2)}%`) + .should('be.visible'); + cy.get_proposal_information_from_table('Number of voting parties') + .should('have.text', '1') + .and('be.visible'); + cy.get(changeVoteButton).should('be.visible').click(); + cy.vote_for_proposal('for'); + // 3001-VOTE-064 + cy.get_proposal_information_from_table('Tokens for proposal') + .should('have.text', parseFloat(this.minProposerBalance).toFixed(2)) + .and('be.visible'); + cy.wait_for_spinner(); + cy.get(changeVoteButton).should('be.visible').click(); + cy.vote_for_proposal('against'); + cy.get(proposalVoteProgressAgainstPercentage) + .contains('100.00%') + .and('be.visible'); + cy.get_proposal_information_from_table('Tokens against proposal') + .should('have.text', parseFloat(this.minProposerBalance).toFixed(2)) + .and('be.visible'); + cy.get_proposal_information_from_table('Number of voting parties') + .should('have.text', '1') + .and('be.visible'); + }); // 3001-VOTE-042, 3001-VOTE-057, 3001-VOTE-058, 3001-VOTE-059, 3001-VOTE-060 it('Newly created proposal details - ability to increase associated tokens - by voting again after association', function () { @@ -738,42 +734,38 @@ context( }); // 1005-PROP-009 - it( - 'Unable to vote on a freeform proposal - when some but not enough vega associated', - { tags: '@smoke' }, - function () { - const proposalTitle = generateProposalTitle(); + it('Unable to vote on a freeform proposal - when some but not enough vega associated', function () { + const proposalTitle = generateProposalTitle(); - cy.ensure_specified_unstaked_tokens_are_associated( - this.minProposerBalance + cy.ensure_specified_unstaked_tokens_are_associated( + this.minProposerBalance + ); + cy.go_to_make_new_proposal(governanceProposalType.FREEFORM); + cy.enter_unique_freeform_proposal_body('50', proposalTitle); + cy.get(newProposalSubmitButton).should('be.visible').click(); + cy.wait_for_proposal_submitted(); + cy.wait_for_proposal_sync(); + cy.staking_page_disassociate_tokens('0.0001'); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + '0.9999' ); - cy.go_to_make_new_proposal(governanceProposalType.FREEFORM); - cy.enter_unique_freeform_proposal_body('50', proposalTitle); - cy.get(newProposalSubmitButton).should('be.visible').click(); - cy.wait_for_proposal_submitted(); - cy.wait_for_proposal_sync(); - cy.staking_page_disassociate_tokens('0.0001'); - cy.get(vegaWallet).within(() => { - cy.get(vegaWalletAssociatedBalance, txTimeout).should( - 'contain', - '0.9999' - ); - }); - cy.navigate_to('governance'); - cy.wait_for_spinner(); - cy.get_submitted_proposal_from_proposal_list(proposalTitle).within( - () => cy.get(viewProposalButton).click() - ); - cy.contains('Vote breakdown').should('be.visible', { - timeout: 10000, - }); - cy.get(voteButtons).should('not.exist'); - cy.getByTestId('min-proposal-requirements').should( - 'have.text', - `You must have at least ${this.minVoterBalance} VEGA associated to vote on this proposal` - ); - } - ); + }); + cy.navigate_to('governance'); + cy.wait_for_spinner(); + cy.get_submitted_proposal_from_proposal_list(proposalTitle).within(() => + cy.get(viewProposalButton).click() + ); + cy.contains('Vote breakdown').should('be.visible', { + timeout: 10000, + }); + cy.get(voteButtons).should('not.exist'); + cy.getByTestId('min-proposal-requirements').should( + 'have.text', + `You must have at least ${this.minVoterBalance} VEGA associated to vote on this proposal` + ); + }); it('Unable to vote on a proposal - when vega wallet disconnected - option to connect from within', function () { createRawProposal(this.minProposerBalance); diff --git a/apps/token-e2e/src/integration/flow/governance-forms-flow.cy.js b/apps/token-e2e/src/integration/flow/governance-forms-flow.cy.js index 3acc0a44a..a4699ac12 100644 --- a/apps/token-e2e/src/integration/flow/governance-forms-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/governance-forms-flow.cy.js @@ -48,7 +48,7 @@ context( beforeEach('visit governance tab', function () { cy.reload(); cy.wait_for_spinner(); - cy.vega_wallet_connect(); + cy.connectVegaWallet(); cy.ethereum_wallet_connect(); cy.navigate_to('governance'); cy.wait_for_spinner(); diff --git a/apps/token-e2e/src/integration/flow/staking-flow.cy.js b/apps/token-e2e/src/integration/flow/staking-flow.cy.js index b644cc5ab..c63b54627 100644 --- a/apps/token-e2e/src/integration/flow/staking-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/staking-flow.cy.js @@ -43,7 +43,7 @@ context( function () { cy.reload(); cy.wait_for_spinner(); - cy.vega_wallet_connect(); + cy.connectVegaWallet(); cy.ethereum_wallet_connect(); cy.vega_wallet_teardown(); cy.navigate_to('staking'); @@ -285,72 +285,68 @@ context( }); // 2001-STKE-041 - it( - 'Able to remove part of a stake against a validator', - { tags: '@smoke' }, - function () { - cy.staking_page_associate_tokens('4'); + it('Able to remove part of a stake against a validator', function () { + cy.staking_page_associate_tokens('4'); - cy.get(vegaWalletUnstakedBalance, txTimeout).should( - 'contain', - 4.0, - txTimeout - ); + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 4.0, + txTimeout + ); - cy.get('button').contains('Select a validator to nominate').click(); + cy.get('button').contains('Select a validator to nominate').click(); - cy.click_on_validator_from_list(0); + cy.click_on_validator_from_list(0); - cy.staking_validator_page_add_stake('3'); + cy.staking_validator_page_add_stake('3'); - cy.get(stakeNextEpochValue, epochTimeout) - .contains(3.0, epochTimeout) - .should('be.visible'); + cy.get(stakeNextEpochValue, epochTimeout) + .contains(3.0, epochTimeout) + .should('be.visible'); - cy.get(vegaWalletUnstakedBalance, txTimeout).should( - 'contain', - 1.0, - txTimeout - ); + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 1.0, + txTimeout + ); - cy.navigate_to('staking'); - // 2001-STKE-040 - cy.click_on_validator_from_list(0); + cy.navigate_to('staking'); + // 2001-STKE-040 + cy.click_on_validator_from_list(0); - // 2001-STKE-044, 2001-STKE-048 - cy.staking_validator_page_remove_stake('1'); + // 2001-STKE-044, 2001-STKE-048 + cy.staking_validator_page_remove_stake('1'); - // 2001-STKE-049 - cy.get(stakeNextEpochValue, epochTimeout).contains(2.0, epochTimeout); + // 2001-STKE-049 + cy.get(stakeNextEpochValue, epochTimeout).contains(2.0, epochTimeout); - cy.get(vegaWalletUnstakedBalance, txTimeout).should( - 'contain', - 2.0, - txTimeout - ); + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 2.0, + txTimeout + ); - cy.get(vegaWalletStakedBalances, txTimeout).should( - 'contain', - 2.0, - txTimeout - ); + cy.get(vegaWalletStakedBalances, txTimeout).should( + 'contain', + 2.0, + txTimeout + ); - cy.get(stakeNextEpochValue, epochTimeout) - .contains(2.0, epochTimeout) - .should('be.visible'); + cy.get(stakeNextEpochValue, epochTimeout) + .contains(2.0, epochTimeout) + .should('be.visible'); - cy.get(stakeThisEpochValue, epochTimeout) - .contains(2.0, epochTimeout) - .should('be.visible'); + cy.get(stakeThisEpochValue, epochTimeout) + .contains(2.0, epochTimeout) + .should('be.visible'); - cy.get(totalStake, epochTimeout).should('contain.text', '2'); - cy.get(stakeShare, epochTimeout).should('have.text', '100%'); + cy.get(totalStake, epochTimeout).should('contain.text', '2'); + cy.get(stakeShare, epochTimeout).should('have.text', '100%'); - cy.navigate_to('staking'); + cy.navigate_to('staking'); - cy.validate_validator_list_total_stake_and_share('0', '2.00', '100%'); - } - ); + cy.validate_validator_list_total_stake_and_share('0', '2.00', '100%'); + }); // 2001-STKE-045 it('Able to remove a full stake against a validator', function () { diff --git a/apps/token-e2e/src/integration/flow/token-association-flow.cy.js b/apps/token-e2e/src/integration/flow/token-association-flow.cy.js index bcc41c754..01b4e2fe3 100644 --- a/apps/token-e2e/src/integration/flow/token-association-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/token-association-flow.cy.js @@ -37,7 +37,7 @@ context( function () { cy.reload(); cy.wait_for_spinner(); - cy.vega_wallet_connect(); + cy.connectVegaWallet(); cy.ethereum_wallet_connect(); cy.vega_wallet_teardown(); cy.navigate_to('staking'); diff --git a/apps/token-e2e/src/integration/flow/withdrawal-flow.cy.js b/apps/token-e2e/src/integration/flow/withdrawal-flow.cy.js index 69c4b8184..86a917307 100644 --- a/apps/token-e2e/src/integration/flow/withdrawal-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/withdrawal-flow.cy.js @@ -35,7 +35,7 @@ context( cy.visit('/'); cy.navigate_to('withdrawals'); cy.wait_for_spinner(); - cy.vega_wallet_connect(); + cy.connectVegaWallet(); cy.ethereum_wallet_connect(); cy.vega_wallet_teardown(); }); diff --git a/apps/token-e2e/src/integration/view/staking.cy.js b/apps/token-e2e/src/integration/view/staking.cy.js index 6a9bdaa60..8a7d95f64 100644 --- a/apps/token-e2e/src/integration/view/staking.cy.js +++ b/apps/token-e2e/src/integration/view/staking.cy.js @@ -104,10 +104,10 @@ context('Staking Page - verify elements on page', function () { // 2001-STKE-050 describe( 'Should be able to see static information about a validator', - { tags: '@smoke' }, + { tags: '@slow' }, function () { before('connect wallets and click on validator', function () { - cy.vega_wallet_connect(); + cy.connectVegaWallet(); cy.click_on_validator_from_list(0); }); diff --git a/apps/token-e2e/src/integration/view/wallet-vega.cy.js b/apps/token-e2e/src/integration/view/wallet-vega.cy.js index 0d0e139c3..27f589e9f 100644 --- a/apps/token-e2e/src/integration/view/wallet-vega.cy.js +++ b/apps/token-e2e/src/integration/view/wallet-vega.cy.js @@ -2,7 +2,7 @@ import { truncateByChars } from '@vegaprotocol/react-helpers'; const walletContainer = '[data-testid="vega-wallet"]'; const walletHeader = '[data-testid="wallet-header"] h1'; -const connectButton = '[data-testid="connect-vega"]'; +const connectButton = '[data-testid="connect-vega-wallet"]'; const getVegaLink = '[data-testid="link"]'; const dialog = '[role="dialog"]'; const dialogHeader = '[data-testid="dialog-title"]'; @@ -150,7 +150,7 @@ context( describe('when vega wallet connected', function () { before('connect vega wallet', function () { cy.visit('/'); - cy.vega_wallet_connect(); + cy.connectVegaWallet(); cy.vega_wallet_teardown(); }); @@ -288,7 +288,7 @@ context( }); // 2002-SINC-016 - describe('when assets exist in vegawallet', function () { + describe.skip('when assets exist in vegawallet', function () { before('send-faucet assets to connected vega wallet', function () { cy.vega_wallet_faucet_assets_without_check( faucetAssets.USDCFake, @@ -310,7 +310,7 @@ context( '200000', vegaWalletPublicKey ); - cy.vega_wallet_connect(); + cy.connectVegaWallet(); cy.ethereum_wallet_connect(); }); diff --git a/apps/token-e2e/src/support/wallet-vega.functions.js b/apps/token-e2e/src/support/wallet-vega.functions.js index bb2badb99..59f2e9e3e 100644 --- a/apps/token-e2e/src/support/wallet-vega.functions.js +++ b/apps/token-e2e/src/support/wallet-vega.functions.js @@ -1,20 +1,3 @@ -const vegaWalletContainer = '[data-testid="vega-wallet"]'; -const vegaWalletNameElement = '[data-testid="wallet-name"]'; - -Cypress.Commands.add('vega_wallet_connect', () => { - cy.highlight('Connecting Vega Wallet'); - cy.get(vegaWalletContainer, { timeout: 6000 }).within(() => { - cy.get('button') - .contains('Connect Vega wallet to use associated $VEGA') - .should('be.enabled') - .and('be.visible') - .click({ force: true }); - }); - cy.getByTestId('connector-jsonRpc').click(); - cy.get(vegaWalletNameElement).should('be.visible'); - cy.getByTestId('wallet-dialog-title').should('not.exist'); -}); - Cypress.Commands.add( 'vega_wallet_faucet_assets_without_check', function (asset, amount, vegaWalletPublicKey) { diff --git a/apps/token/src/components/vega-wallet/vega-wallet.tsx b/apps/token/src/components/vega-wallet/vega-wallet.tsx index affe842a2..4cec59561 100644 --- a/apps/token/src/components/vega-wallet/vega-wallet.tsx +++ b/apps/token/src/components/vega-wallet/vega-wallet.tsx @@ -84,7 +84,7 @@ const VegaWalletNotConnected = () => { openVegaWalletDialog(); }} fill={true} - data-testid="connect-vega" + data-testid="connect-vega-wallet" > {t('connectVegaWalletToUseAssociated')} diff --git a/apps/trading-e2e/.env b/apps/trading-e2e/.env index 9a945af97..69bb96cdb 100644 --- a/apps/trading-e2e/.env +++ b/apps/trading-e2e/.env @@ -13,3 +13,4 @@ NX_VEGA_DOCS_URL=https://docs.vega.xyz/testnet CYPRESS_VEGA_URL=https://api.stagnet3.vega.xyz/graphql CYPRESS_EXPLORER_URL=https://stagnet3.explorer.vega.xyz CYPRESS_VEGA_ENV=STAGNET3 +CYPRESS_VEGA_WALLET_API_TOKEN= diff --git a/apps/trading-e2e/src/integration/global.cy.ts b/apps/trading-e2e/src/integration/global.cy.ts index 074e7865e..388b711be 100644 --- a/apps/trading-e2e/src/integration/global.cy.ts +++ b/apps/trading-e2e/src/integration/global.cy.ts @@ -1,4 +1,4 @@ -import { aliasQuery } from '@vegaprotocol/cypress'; +import { aliasQuery, mockConnectWallet } from '@vegaprotocol/cypress'; import { generateNetworkParameters } from '../support/mocks/generate-network-parameters'; const connectEthWalletBtn = 'connect-eth-wallet-btn'; @@ -18,12 +18,14 @@ describe('vega wallet v1', { tags: '@smoke' }, () => { it('can connect', () => { cy.getByTestId(connectVegaBtn).click(); + mockConnectWallet(); cy.contains('Connect Vega wallet'); cy.contains('Hosted Fairground wallet'); cy.getByTestId('connectors-list') .find('[data-testid="connector-jsonRpc"]') .click(); + cy.wait('@walletGQL'); cy.getByTestId(manageVegaBtn).should('exist'); }); @@ -66,10 +68,12 @@ describe('vega wallet v2', { tags: '@smoke' }, () => { }); it('can connect', () => { + mockConnectWallet(); cy.getByTestId(connectVegaBtn).click(); cy.getByTestId('connectors-list') .find('[data-testid="connector-jsonRpc"]') .click(); + cy.wait('@walletGQL'); cy.getByTestId(dialogContent).should('not.exist'); cy.getByTestId(manageVegaBtn).should('exist'); }); diff --git a/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts b/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts index 8c7df8ceb..7f6ff28a5 100644 --- a/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts +++ b/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts @@ -4,7 +4,7 @@ import { Schema, } from '@vegaprotocol/types'; import { generateEstimateOrder } from '../support/mocks/generate-fees'; -import { aliasQuery } from '@vegaprotocol/cypress'; +import { aliasQuery, mockConnectWallet } from '@vegaprotocol/cypress'; import { testOrder } from '../support/deal-ticket-transaction'; import type { OrderSubmission } from '@vegaprotocol/wallet'; @@ -393,6 +393,7 @@ describe('deal ticket validation', { tags: '@smoke' }, () => { }); it('order connect vega wallet button should connect', () => { + mockConnectWallet(); cy.getByTestId(toggleLimit).click(); cy.getByTestId(orderPriceField).clear().type('101'); cy.getByTestId('order-connect-wallet').click(); @@ -400,6 +401,7 @@ describe('deal ticket validation', { tags: '@smoke' }, () => { cy.getByTestId('connectors-list') .find('[data-testid="connector-jsonRpc"]') .click(); + cy.wait('@walletGQL'); cy.getByTestId(placeOrderBtn).should('be.visible'); cy.getByTestId(toggleLimit).children('input').should('be.checked'); cy.getByTestId(orderPriceField).should('have.value', '101'); diff --git a/apps/trading-e2e/src/support/mocks/generate-chain-id.ts b/apps/trading-e2e/src/support/mocks/generate-chain-id.ts index 146c452f1..2c41996fc 100644 --- a/apps/trading-e2e/src/support/mocks/generate-chain-id.ts +++ b/apps/trading-e2e/src/support/mocks/generate-chain-id.ts @@ -8,7 +8,6 @@ export const generateChainId = ( const defaultResult = { statistics: { __typename: 'Statistics', - // this needs to match the network set up for vegawallet-dummy in .github/actions/setup-vegawallet/action.yml chainId: 'stagnet3', }, }; diff --git a/apps/trading-e2e/src/support/mocks/generate-statistics.ts b/apps/trading-e2e/src/support/mocks/generate-statistics.ts index 752331be9..1642516a6 100644 --- a/apps/trading-e2e/src/support/mocks/generate-statistics.ts +++ b/apps/trading-e2e/src/support/mocks/generate-statistics.ts @@ -8,7 +8,6 @@ export const generateStatistics = ( const defaultResult = { statistics: { __typename: 'Statistics', - // this needs to match the network set up for vegawallet-dummy in .github/actions/setup-vegawallet/action.yml chainId: 'stagnet3', blockHeight: '11', }, diff --git a/libs/cypress/src/index.ts b/libs/cypress/src/index.ts index d5e1a9531..40379bea4 100644 --- a/libs/cypress/src/index.ts +++ b/libs/cypress/src/index.ts @@ -2,6 +2,7 @@ import { addGetTestIdcommand } from './lib/commands/get-by-test-id'; import { addMockGQLCommand, addMockGQLSubscriptionCommand, + addMockWalletGQLCommand, } from './lib/commands/mock-gql'; import { addMockWeb3ProviderCommand } from './lib/commands/mock-web3-provider'; import { addSlackCommand } from './lib/commands/slack'; @@ -18,6 +19,7 @@ addGetTestIdcommand(); addSlackCommand(); addMockGQLCommand(); addMockGQLSubscriptionCommand(); +addMockWalletGQLCommand(); addMockWeb3ProviderCommand(); addHighlightLog(); addVegaWalletReceiveFaucetedAsset(); @@ -29,6 +31,7 @@ addVegaWalletConnect(); addMockTransactionResponse(); export * from './lib/graphql-test-utils'; +export { mockConnectWallet } from './lib/commands/vega-wallet-connect'; export type { onMessage } from './lib/commands/mock-gql'; Cypress.on( diff --git a/libs/cypress/src/lib/commands/get-asset-information.ts b/libs/cypress/src/lib/commands/get-asset-information.ts index 26ad63fd4..fa24cd533 100644 --- a/libs/cypress/src/lib/commands/get-asset-information.ts +++ b/libs/cypress/src/lib/commands/get-asset-information.ts @@ -12,11 +12,11 @@ export function addGetAssetInformation() { // @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command Cypress.Commands.add('get_asset_information', () => { const mutation = - '{ assets {name id symbol decimals source{__typename \ + '{ assetsConnection{edges{node{name id symbol decimals source{__typename \ ... on ERC20{contractAddress} \ ... on BuiltinAsset{maxFaucetAmountMint}} \ infrastructureFeeAccount{__typename type balance} \ - globalRewardPoolAccount {balance}}}'; + globalRewardPoolAccount {balance}}}}}'; cy.request({ method: 'POST', url: `http://localhost:3028/query`, @@ -25,11 +25,11 @@ export function addGetAssetInformation() { }, headers: { 'content-type': 'application/json' }, }) - .its(`body.data.assets`) + .its('body.data.assetsConnection.edges') .then(function (response) { // @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command const object = response.reduce(function (assets, entry) { - assets[entry.name] = entry; + assets[entry.node.name] = entry; return assets; }, {}); return object; diff --git a/libs/cypress/src/lib/commands/mock-gql.ts b/libs/cypress/src/lib/commands/mock-gql.ts index f831955b3..23f7ed357 100644 --- a/libs/cypress/src/lib/commands/mock-gql.ts +++ b/libs/cypress/src/lib/commands/mock-gql.ts @@ -12,10 +12,17 @@ declare global { interface Chainable { mockGQL(handler: RouteHandler): void; mockGQLSubscription(mocks?: Record): void; + mockWalletGQL(handler: RouteHandler): void; } } } +export function addMockWalletGQLCommand() { + Cypress.Commands.add('mockWalletGQL', (handler: RouteHandler): void => { + cy.intercept('POST', '**/api/v2/requests', handler).as('walletGQL'); + }); +} + export function addMockGQLCommand() { Cypress.Commands.add('mockGQL', (handler: RouteHandler) => { cy.intercept('POST', '**/graphql', handler).as('GQL'); diff --git a/libs/cypress/src/lib/commands/vega-wallet-connect.ts b/libs/cypress/src/lib/commands/vega-wallet-connect.ts index a6517360d..b28ae0fd7 100644 --- a/libs/cypress/src/lib/commands/vega-wallet-connect.ts +++ b/libs/cypress/src/lib/commands/vega-wallet-connect.ts @@ -1,3 +1,5 @@ +import { aliasWalletQuery } from '../graphql-test-utils'; + declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Cypress { @@ -8,14 +10,26 @@ declare global { } } +export const mockConnectWallet = () => { + const data = { + token: Cypress.env('VEGA_WALLET_API_TOKEN'), + }; + console.log('mockConnectWallet', data); + cy.mockWalletGQL((req) => { + aliasWalletQuery(req, 'client.connect_wallet', data); + }); +}; + export function addVegaWalletConnect() { // @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command Cypress.Commands.add('connectVegaWallet', () => { + mockConnectWallet(); cy.highlight(`Connecting Vega Wallet`); cy.get('[data-testid=connect-vega-wallet]').click(); cy.get('[data-testid=connectors-list]') .find('[data-testid="connector-jsonRpc"]') .click(); + cy.wait('@walletGQL'); cy.get('[data-testid=dialog-content]').should( 'contain.text', 'Successfully connected' diff --git a/libs/cypress/src/lib/graphql-test-utils.ts b/libs/cypress/src/lib/graphql-test-utils.ts index a28489aef..d14192ac2 100644 --- a/libs/cypress/src/lib/graphql-test-utils.ts +++ b/libs/cypress/src/lib/graphql-test-utils.ts @@ -25,3 +25,31 @@ export const aliasQuery = ( } } }; + +const hasMethod = (req: CyHttpMessages.IncomingHttpRequest, method: string) => { + const { body } = req; + return 'method' in body && body.method === method; +}; + +// Alias wallet query if method matches +export const aliasWalletQuery = ( + req: CyHttpMessages.IncomingHttpRequest, + method: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data?: any +) => { + const body = { + jsonrpc: '2.0', + id: '0', + result: data, + }; + if (hasMethod(req, method)) { + req.alias = method; + if (data !== undefined) { + req.reply({ + statusCode: 200, + body: body, + }); + } + } +}; diff --git a/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx b/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx index 6c034aead..f3080b852 100644 --- a/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx +++ b/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx @@ -205,8 +205,6 @@ describe('VegaConnectDialog', () => { let spyOnGetChainId: jest.SpyInstance; let spyOnConnectWallet: jest.SpyInstance; let spyOnConnect: jest.SpyInstance; - let spyOnGetPermissions: jest.SpyInstance; - let spyOnRequestPermissions: jest.SpyInstance; beforeEach(() => { spyOnCheckCompat = jest @@ -218,24 +216,6 @@ describe('VegaConnectDialog', () => { spyOnConnectWallet = jest .spyOn(connectors.jsonRpc, 'connectWallet') .mockImplementation(() => delayedResolve({ token: 'token' })); - spyOnGetPermissions = jest - .spyOn(connectors.jsonRpc, 'getPermissions') - .mockImplementation(() => - delayedResolve({ - permissions: { - public_keys: 'none', - }, - }) - ); - spyOnRequestPermissions = jest - .spyOn(connectors.jsonRpc, 'requestPermissions') - .mockImplementation(() => - delayedResolve({ - permissions: { - public_keys: 'read', - }, - }) - ); spyOnConnect = jest .spyOn(connectors.jsonRpc, 'connect') .mockImplementation(() => @@ -277,19 +257,6 @@ describe('VegaConnectDialog', () => { jest.advanceTimersByTime(delay); }); - // Perms check - expect(spyOnGetPermissions).toHaveBeenCalled(); - await act(async () => { - jest.advanceTimersByTime(delay); - }); - - // Await user perms update - expect(screen.getByText('Update permissions')).toBeInTheDocument(); - expect(spyOnRequestPermissions).toHaveBeenCalled(); - await act(async () => { - jest.advanceTimersByTime(delay); - }); - // Connect (list keys) expect(spyOnConnect).toHaveBeenCalled(); await act(async () => { diff --git a/libs/wallet/src/connect-dialog/json-rpc-connector-form.tsx b/libs/wallet/src/connect-dialog/json-rpc-connector-form.tsx index cfe35075b..bb248bfaf 100644 --- a/libs/wallet/src/connect-dialog/json-rpc-connector-form.tsx +++ b/libs/wallet/src/connect-dialog/json-rpc-connector-form.tsx @@ -2,7 +2,6 @@ import capitalize from 'lodash/capitalize'; import { createDocsLinks, t } from '@vegaprotocol/react-helpers'; import { ButtonLink, - Cross, Diamond, Link, Loader, @@ -127,21 +126,6 @@ const Connecting = ({ ); } - if (status === Status.RequestingPerms) { - return ( - <> - {t('Update permissions')} -
- -
-

- {t(`${window.location.host} now has access to your Wallet, however you don't - have sufficient permissions to retrieve your public keys. Go to your wallet to approve new permissions.`)} -

- - ); - } - return null; }; diff --git a/libs/wallet/src/connectors/json-rpc-connector.ts b/libs/wallet/src/connectors/json-rpc-connector.ts index 0ffdc57e5..330b55972 100644 --- a/libs/wallet/src/connectors/json-rpc-connector.ts +++ b/libs/wallet/src/connectors/json-rpc-connector.ts @@ -10,8 +10,6 @@ const VERSION = 'v2'; enum Methods { ConnectWallet = 'client.connect_wallet', DisconnectWallet = 'client.disconnect_wallet', - GetPermissions = 'client.get_permissions', - RequestPermisssions = 'client.request_permissions', ListKeys = 'client.list_keys', SendTransaction = 'client.send_transaction', GetChainId = 'client.get_chain_id', @@ -45,22 +43,6 @@ const GetChainIdSchema = BaseSchema.extend({ }), }); -const GetPermissionsSchema = BaseSchema.extend({ - result: z.object({ - permissions: z.object({ - public_keys: z.enum(['none', 'read', 'write']), - }), - }), -}); - -const RequestPermissionsSchema = BaseSchema.extend({ - result: z.object({ - permissions: z.object({ - public_keys: z.enum(['none', 'read', 'write']), - }), - }), -}); - const SendTransactionSchema = BaseSchema.extend({ result: z.object({ receivedAt: z.string(), @@ -84,8 +66,6 @@ type Response = | z.infer | z.infer | z.infer - | z.infer - | z.infer | z.infer | { error: JsonRpcError }; @@ -155,47 +135,6 @@ export class JsonRpcConnector implements VegaConnector { } } - async getPermissions() { - const cfg = getConfig(); - if (!cfg?.token) { - throw ClientErrors.NO_TOKEN; - } - const result = await this.request(Methods.GetPermissions, { - token: cfg.token, - }); - if ('error' in result) { - throw this.wrapError(result.error); - } - const parseResult = GetPermissionsSchema.safeParse(result); - if (parseResult.success) { - return parseResult.data.result; - } else { - throw ClientErrors.INVALID_RESPONSE; - } - } - - async requestPermissions() { - const cfg = getConfig(); - if (!cfg?.token) { - throw ClientErrors.NO_TOKEN; - } - const result = await this.request(Methods.RequestPermisssions, { - token: cfg.token, - requestedPermissions: { - public_keys: 'read', - }, - }); - if ('error' in result) { - throw this.wrapError(result.error); - } - const parseResult = RequestPermissionsSchema.safeParse(result); - if (parseResult.success) { - return parseResult.data.result; - } else { - throw ClientErrors.INVALID_RESPONSE; - } - } - // connect actually calling list_keys here, not to be confused with connect_wallet // which retrieves the session token async connect() { diff --git a/libs/wallet/src/provider.tsx b/libs/wallet/src/provider.tsx index fc5188223..ed6625138 100644 --- a/libs/wallet/src/provider.tsx +++ b/libs/wallet/src/provider.tsx @@ -9,6 +9,7 @@ import type { } from './connectors/vega-connector'; import { VegaWalletContext } from './context'; import { WALLET_KEY } from './storage'; +import { WalletError } from './connectors/vega-connector'; interface VegaWalletProviderProps { children: ReactNode; @@ -50,6 +51,9 @@ export const VegaWalletProvider = ({ children }: VegaWalletProviderProps) => { return null; } } catch (err) { + if (err instanceof WalletError) { + throw err; + } return null; } }, []); diff --git a/libs/wallet/src/use-json-rpc-connect.ts b/libs/wallet/src/use-json-rpc-connect.ts index c4d2756af..0246ab23c 100644 --- a/libs/wallet/src/use-json-rpc-connect.ts +++ b/libs/wallet/src/use-json-rpc-connect.ts @@ -10,7 +10,6 @@ export enum Status { GettingChainId = 'GettingChainId', Connecting = 'Connecting', GettingPerms = 'GettingPerms', - RequestingPerms = 'RequestingPerms', ListingKeys = 'ListingKeys', Connected = 'Connected', Error = 'Error', @@ -48,15 +47,7 @@ export const useJsonRpcConnect = (onConnect: () => void) => { setStatus(Status.Connecting); await connector.connectWallet(); - // Check wallet is permitted to reveal its public keys setStatus(Status.GettingPerms); - const permsResult = await connector.getPermissions(); - if (permsResult.permissions.public_keys === 'none') { - // Automatically request new perms. User will again be prompted to permit this change - // and enter their password - setStatus(Status.RequestingPerms); - await connector.requestPermissions(); - } // Call connect in the wallet provider. The connector will be stored for // future actions such as sending transactions