Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Fix e2e and autoconnect (#1870)
Browse files Browse the repository at this point in the history
* Fix tests

* Fix auto-connect for tests
  • Loading branch information
anxolin authored Nov 17, 2021
1 parent 2d48388 commit 7d5c81a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
31 changes: 18 additions & 13 deletions cypress-custom/integration/swap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
// GP doesn't use ETH, so we need to test for this

describe('Swap (custom)', () => {
beforeEach(() => {
cy.visit('/swap')
})

// uses WETH instead of ETH
// it('can swap ETH for DAI', () => {
it('can swap WETH for DAI', () => {
// select DAI
cy.get('#swap-currency-output .open-currency-select-button').click()
cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').should('be.visible')
cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').click({ force: true })
// TODO: Define our command, so it search by name and select the input
// cy.get('#swap-currency-output .open-currency-select-button').click()

// cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').should('be.visible')
// cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').click({ force: true })

cy.visit(
'/swap?inputCurrency=0xc778417E063141139Fce010982780140Aa0cD5Ab&outputCurrency=0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa'
)

// input amounts
cy.get('#swap-currency-input .token-amount-input').should('be.visible')
cy.get('#swap-currency-input .token-amount-input').type('0.5', { force: true, delay: 200 })
Expand All @@ -24,14 +27,16 @@ describe('Swap (custom)', () => {

// ETH should be tradable but show Switch to Weth
it('Swap ETH for DAI - shows Switch to WETH ', () => {
cy.visit('/swap?inputCurrency=ETH&outputCurrency=0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa')

// select ETH
cy.get('#swap-currency-input .open-currency-select-button').click()
cy.get('.token-item-ETHER').should('be.visible')
cy.get('.token-item-ETHER').click({ force: true })
// cy.get('#swap-currency-input .open-currency-select-button').click()
// cy.get('.token-item-ETHER').should('be.visible')
// cy.get('.token-item-ETHER').click({ force: true })
// select DAI
cy.get('#swap-currency-output .open-currency-select-button').click()
cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').should('be.visible')
cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').click({ force: true })
// cy.get('#swap-currency-output .open-currency-select-button').click()
// cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').should('be.visible')
// cy.get('.token-item-0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735').click({ force: true })
// input amounts
cy.get('#swap-currency-input .token-amount-input').should('be.visible')
cy.get('#swap-currency-input .token-amount-input').type('0.001', { force: true, delay: 400 })
Expand Down
11 changes: 6 additions & 5 deletions src/custom/hooks/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export function useEagerConnect() {

// if there is no last saved provider set tried state to true
if (!latestProvider) {
setTried(true)
}

// check if the last saved provider is Metamask
if (latestProvider === WalletProvider.INJECTED) {
// Try to auto-connect to the injected wallet
activate(injected, undefined, true).catch(() => {
setTried(true)
})
} else if (latestProvider === WalletProvider.INJECTED) {
// check if the last saved provider is Metamask
// check if the our application is authorized/connected with Metamask
injected.isAuthorized().then((isAuthorized) => {
if (isAuthorized) {
Expand Down

0 comments on commit 7d5c81a

Please sign in to comment.