diff --git a/cypress/e2e/helpers/base/base.ts b/cypress/e2e/helpers/base/base.ts index fa15b13f..4f185f07 100644 --- a/cypress/e2e/helpers/base/base.ts +++ b/cypress/e2e/helpers/base/base.ts @@ -1,19 +1,11 @@ -import { - Avalanche, - AvalancheTestnet, - Binance, - BinanceTestnet, -} from './constants' +import { Binance, BinanceTestnet } from './constants' import { MetamaskNetwork } from './types' export default class Base { addSupportedNetwork() { // Mainnet this.addNetwork(Binance) - this.addNetwork(Avalanche) - // Avax this.addNetwork(BinanceTestnet) - this.addNetwork(AvalancheTestnet) } visit() { diff --git a/cypress/e2e/helpers/base/constants.ts b/cypress/e2e/helpers/base/constants.ts index de3a3e66..5cb3a866 100644 --- a/cypress/e2e/helpers/base/constants.ts +++ b/cypress/e2e/helpers/base/constants.ts @@ -9,15 +9,6 @@ export const Binance: MetamaskNetwork = { isTestnet: false, } -export const Avalanche: MetamaskNetwork = { - networkName: 'Avalanche Mainnet', - rpcUrl: 'https://api.avax.network/ext/bc/C/rpc', - chainId: '43114', - symbol: 'AVAX', - blockExplorer: 'https://snowtrace.io/', - isTestnet: false, -} - export const BinanceTestnet: MetamaskNetwork = { networkName: 'BNB Testnet', rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545', @@ -27,14 +18,6 @@ export const BinanceTestnet: MetamaskNetwork = { isTestnet: true, } -export const AvalancheTestnet: MetamaskNetwork = { - networkName: 'Avalanche Testnet', - rpcUrl: 'https://api.avax-test.network/ext/bc/C/rpc', - chainId: '43113', - symbol: 'AVAX', - blockExplorer: 'https://testnet.snowtrace.io/', - isTestnet: true, -} export const EthereumInfo: NetworkTestInfo = { networkName: 'Ethereum', networkAbbreviation: 'ETHEREUM', @@ -46,17 +29,7 @@ export const BinanceInfo: NetworkTestInfo = { isTestnet: false, } -export const AvalancheInfo: NetworkTestInfo = { - networkName: 'Avalanche Mainnet C-Chain', - networkAbbreviation: 'AVAX', - isTestnet: false, -} - -export const MainnetL1Networks: NetworkTestInfo[] = [ - EthereumInfo, - BinanceInfo, - AvalancheInfo, -] +export const MainnetL1Networks: NetworkTestInfo[] = [EthereumInfo, BinanceInfo] export const MainnetL2Networks: NetworkTestInfo[] = [ { @@ -69,11 +42,6 @@ export const MainnetL2Networks: NetworkTestInfo[] = [ networkAbbreviation: 'Boba BNB', isTestnet: false, }, - { - networkName: 'Boba Avalanche', - networkAbbreviation: 'Boba Avalanche', - isTestnet: false, - }, ] export const EthereumGoerliInfo: NetworkTestInfo = { @@ -89,11 +57,6 @@ export const TestnetL1Networks: NetworkTestInfo[] = [ networkAbbreviation: 'BNB', isTestnet: true, }, - { - networkName: 'Fuji Testnet', - networkAbbreviation: 'AVAX', - isTestnet: true, - }, ] export const TestnetL2Networks: NetworkTestInfo[] = [ @@ -107,9 +70,4 @@ export const TestnetL2Networks: NetworkTestInfo[] = [ networkAbbreviation: 'Boba BNB', isTestnet: true, }, - { - networkName: 'Boba Fuji Testnet', - networkAbbreviation: 'Boba Fuji', - isTestnet: true, - }, ] diff --git a/cypress/e2e/helpers/base/page.ts b/cypress/e2e/helpers/base/page.ts index c3da66ad..44b10bfa 100644 --- a/cypress/e2e/helpers/base/page.ts +++ b/cypress/e2e/helpers/base/page.ts @@ -61,7 +61,7 @@ export default class Page extends Base { cy.get('body').find('wcm-modal').should('exist') } - setNetworkTo(network: 'BNB' | 'AVAX' | 'ETH', type = 'Mainnet') { + setNetworkTo(network: 'BNB' | 'ETH', type = 'Mainnet') { const bnbConfig = { network: 'BNB', name: { @@ -73,17 +73,6 @@ export default class Page extends Base { networkType: type, } - const avaxConfig = { - network: 'AVAX', - name: { - l1: 'Avalanche Mainnet C-Chain', - l2: 'Boba Avalanche', - }, - networkIcon: 'avax', - chainIds: { L1: '43114', L2: '43288' }, - networkType: type, - } - const ethConfig = { network: 'ETHEREUM', name: { @@ -98,8 +87,6 @@ export default class Page extends Base { let payload = ethConfig if (network === 'BNB') { payload = bnbConfig - } else if (network === 'AVAX') { - payload = avaxConfig } cy.window().its('store').invoke('dispatch', { @@ -151,31 +138,6 @@ export default class Page extends Base { }) } - checkNaviagtionListAvalanche() { - this.header - .getNavigationLinks() - .should('not.be.empty') - .and(($p) => { - // should have found 3 elements for Avalanche - expect($p).to.have.length(3) - - // // use jquery's map to grab all of their classes - // // jquery's map returns a new jquery object - const links = $p.map((i, el) => { - return Cypress.$(el).attr('href') - }) - // call classes.get() to make this a plain array - expect(links.get()).to.deep.eq(['/bridge', '/bridge', '/history']) - - // get labels and verify - const labels = $p.map((i, el) => { - return Cypress.$(el).text() - }) - - expect(labels.get()).to.deep.eq(['', 'Bridge', 'History']) - }) - } - checkNavigationListEthereum() { this.header .getNavigationLinks() @@ -235,7 +197,6 @@ export default class Page extends Base { .click() .should('have.text', 'Ethereum (Goerli)') .should('have.text', 'BNB Testnet') - .should('have.text', 'Fuji Testnet') } // check theme switching functionality @@ -279,12 +240,6 @@ export default class Page extends Base { this.allowNetworkSwitch() this.checkNetworkSwitchSuccessful('BNB') - // switch to AVAX - this.header.switchNetwork('Avalanche Mainnet') - this.handleNetworkSwitchModals('AVAX', false) - this.allowNetworkSwitch() - this.checkNetworkSwitchSuccessful('AVAX') - // switch to Ethereum this.header.switchNetwork('Ethereum') this.handleNetworkSwitchModals('ETHEREUM', false) diff --git a/cypress/e2e/helpers/bridge.ts b/cypress/e2e/helpers/bridge.ts index d5ac4cc3..b78c54db 100644 --- a/cypress/e2e/helpers/bridge.ts +++ b/cypress/e2e/helpers/bridge.ts @@ -191,11 +191,11 @@ export default class Bridge extends Page { l2Networks: NetworkTestInfo[], accountConnected: boolean ) { - for (let i = 0; i < 3; i++) { + for (let i = 0; i < 2; i++) { this.withinPage().contains(l2Networks[i].networkName).should('exist') this.openNetworkModal(l1Networks[i].networkName) - const nextNetwork = l1Networks[(i + 1) % 3] + const nextNetwork = l1Networks[(i + 1) % 2] this.selectNetworkFromModal(nextNetwork.networkName) if (accountConnected) { this.handleNetworkSwitchModals( diff --git a/cypress/e2e/specs/layout.spec.cy.ts b/cypress/e2e/specs/layout.spec.cy.ts index 290cb70b..7fc8a4b1 100644 --- a/cypress/e2e/specs/layout.spec.cy.ts +++ b/cypress/e2e/specs/layout.spec.cy.ts @@ -13,8 +13,6 @@ describe('Page Layout', () => { page.checkNavigationListEthereum() page.setNetworkTo('BNB') page.checkNaviagtionListBinanace() - page.setNetworkTo('AVAX') - page.checkNaviagtionListAvalanche() }) it('Theme switcher should work', () => { diff --git a/src/actions/balanceAction.js b/src/actions/balanceAction.js deleted file mode 100644 index cd0a0c04..00000000 --- a/src/actions/balanceAction.js +++ /dev/null @@ -1,91 +0,0 @@ -/* - Varna - A Privacy-Preserving Marketplace - Varna uses Fully Homomorphic Encryption to make markets fair. - Copyright (C) 2021 Enya Inc. Palo Alto, CA - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -import networkService from 'services/networkService' -import { createAction } from './createAction' - -export function fetchL1LPBalance(address) { - return createAction('FETCH/L1LP/BALANCE', () => networkService.L1LPBalance(address)) -} - -export function fetchL2LPBalance(address) { - return createAction('FETCH/L2LP/BALANCE', () => networkService.L2LPBalance(address)) -} - -export function fetchL1LPPending(address) { - return createAction('FETCH/L1LP/PENDING', () => networkService.L1LPPending(address)) -} - -export function fetchL2LPPending(address) { - return createAction('FETCH/L2LP/PENDING', () => networkService.L2LPPending(address)) -} - -export function fetchL1LPLiquidity(address) { - return createAction('FETCH/L1LP/LIQUIDITY', () => networkService.L1LPLiquidity(address)) -} - -export function fetchL2LPLiquidity(address) { - return createAction('FETCH/L2LP/LIQUIDITY', () => networkService.L2LPLiquidity(address)) -} - -export function fetchL1TotalFeeRate() { return createAction('FETCH/L1TOTALFEERATE', ()=>{return networkService.getL1TotalFeeRate()}) } -export function fetchL2TotalFeeRate() { return createAction('FETCH/L2TOTALFEERATE', ()=>{return networkService.getL2TotalFeeRate()}) } - -export function fetchL1FeeRateN(tokenAddress) { return createAction('FETCH/L1FEERATE', ()=>{return networkService.getL1UserRewardFeeRate(tokenAddress)}) } -export function fetchL2FeeRateN(tokenAddress) { return createAction('FETCH/L2FEERATE', ()=>{return networkService.getL2UserRewardFeeRate(tokenAddress)}) } - -export function fetchFastExitCost(address) { - return createAction('FETCH/FASTEXIT/COST', () => networkService.getFastExitCost(address)) -} - -export function fetchClassicExitCost(address) { - return createAction('FETCH/CLASSICEXIT/COST', () => networkService.getExitCost(address)) -} - -export function fetchFastDepositCost(address) { - return createAction('FETCH/FASTDEPOSIT/COST', () => networkService.getFastDepositCost(address)) -} - -export function fetchAltL1DepositFee() { - return createAction('FETCH/ALTL1DEPOSIT/COST', () => networkService.getAltL1DepositFee()) -} - -export function fetchFastDepositBatchCost(tokenList) { - return createAction('FETCH/FASTDEPOSIT/BATCH/COST', () => networkService.getFastDepositBatchCost(tokenList)) -} - -export function fetchL1FeeBalance() { - return createAction('FETCH/L1FEE/BALANCE', () => networkService.getL1FeeBalance()) -} - -export function fetchL2BalanceETH() { - return createAction('FETCH/L2ETH/BALANCE', () => networkService.getL2BalanceETH()) -} - -export function fetchL2BalanceBOBA() { - return createAction('FETCH/L2BOBA/BALANCE', () => networkService.getL2BalanceBOBA()) -} - -export function fetchUserAndL2LPBalanceBatch(tokenList) { - return createAction('FETCH/USER/L2LP/BALANCE/BATCH', () => networkService.getL2UserAndLPBalanceBatch(tokenList)) -} - -export function fetchExitFee() { - return createAction('FETCH/EXITFEE', () => networkService.getExitFeeFromBillingContract()) -} diff --git a/src/actions/balanceAction.ts b/src/actions/balanceAction.ts new file mode 100644 index 00000000..c305b066 --- /dev/null +++ b/src/actions/balanceAction.ts @@ -0,0 +1,90 @@ +/* + Varna - A Privacy-Preserving Marketplace + Varna uses Fully Homomorphic Encryption to make markets fair. + Copyright (C) 2021 Enya Inc. Palo Alto, CA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import networkService from 'services/networkService' +import { createAction } from './createAction' + +export const fetchL1LPBalance = (address: string) => + createAction('FETCH/L1LP/BALANCE', () => networkService.L1LPBalance(address)) + +export const fetchL2LPBalance = (address: string) => + createAction('FETCH/L2LP/BALANCE', () => networkService.L2LPBalance(address)) + +export const fetchL1LPPending = (address: string) => + createAction('FETCH/L1LP/PENDING', () => networkService.L1LPPending(address)) + +export const fetchL2LPPending = (address: string) => + createAction('FETCH/L2LP/PENDING', () => networkService.L2LPPending(address)) + +export const fetchL1LPLiquidity = (address: string) => + createAction('FETCH/L1LP/LIQUIDITY', () => + networkService.L1LPLiquidity(address) + ) + +export const fetchL2LPLiquidity = (address: string) => + createAction('FETCH/L2LP/LIQUIDITY', () => + networkService.L2LPLiquidity(address) + ) + +export const fetchL1TotalFeeRate = () => + createAction('FETCH/L1TOTALFEERATE', () => { + return networkService.getL1TotalFeeRate() + }) +export const fetchL2TotalFeeRate = () => + createAction('FETCH/L2TOTALFEERATE', () => { + return networkService.getL2TotalFeeRate() + }) + +export const fetchL1FeeRateN = (tokenAddress: string) => + createAction('FETCH/L1FEERATE', () => { + return networkService.getL1UserRewardFeeRate(tokenAddress) + }) +export const fetchL2FeeRateN = (tokenAddress: string) => + createAction('FETCH/L2FEERATE', () => { + return networkService.getL2UserRewardFeeRate(tokenAddress) + }) + +export const fetchFastExitCost = (address: string) => + createAction('FETCH/FASTEXIT/COST', () => + networkService.getFastExitCost(address) + ) + +export const fetchClassicExitCost = (address: string) => + createAction('FETCH/CLASSICEXIT/COST', () => + networkService.getExitCost(address) + ) + +export const fetchFastDepositCost = (address: string) => + createAction('FETCH/FASTDEPOSIT/COST', () => + networkService.getFastDepositCost(address) + ) + +export const fetchL1FeeBalance = () => + createAction('FETCH/L1FEE/BALANCE', () => networkService.getL1FeeBalance()) + +export const fetchL2BalanceETH = () => + createAction('FETCH/L2ETH/BALANCE', () => networkService.getL2BalanceETH()) + +export const fetchL2BalanceBOBA = () => + createAction('FETCH/L2BOBA/BALANCE', () => networkService.getL2BalanceBOBA()) + +export const fetchExitFee = () => + createAction('FETCH/EXITFEE', () => + networkService.getExitFeeFromBillingContract() + ) diff --git a/src/actions/bridgeAction.js b/src/actions/bridgeAction.js deleted file mode 100644 index 24b864cd..00000000 --- a/src/actions/bridgeAction.js +++ /dev/null @@ -1,123 +0,0 @@ -/* -Copyright 2021-present Boba Network. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -import store from "store"; - -export function setToken(token) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/TOKEN/SELECT', payload: token }); - } -} - -export function resetToken() { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/TOKEN/RESET' }); - } -} - -export function removeToken(tokenIndex) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/TOKEN/REMOVE', payload: tokenIndex }); - } -} - -export function setTokenAmount(payload) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/TOKEN/AMOUNT/CHANGE', payload }); - } -} - -export function updateToken(payload) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/TOKEN/UPDATE', payload }); - } -} - -export function setBridgeType(type) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/TYPE/SELECT', payload: type }); - } -} - -export function setMultiBridgeMode(mode) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/MODE/CHANGE', payload: mode }); - } -} - -export function setBridgeDestinationAddress(payload) { - return function (dispatch) { - return dispatch({type: 'BRIDGE/DESTINATION_ADDRESS/SET', payload }) - } -} - -export function resetBridgeDestinationAddress() { - return function(dispatch) { - return dispatch({type: 'BRIDGE/DESTINATION_ADDRESS/RESET'}); - } -} - -// updates value indicating wether the 'to address' field should be available -export function setBridgeDestinationAddressAvailable(payload) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/DESTINATION_ADDRESS_AVAILABLE/SET', payload }); - } -} - -export function setBridgeAlert(payload) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/ALERT/SET', payload }); - } -} - -export function clearBridgeAlert(payload) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/ALERT/CLEAR', payload }); - } -} - -export function purgeBridgeAlert(payload) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/ALERT/PURGE', payload }); - } -} - -export function setAmountToBridge(payload) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/AMOUNT/SET', payload }); - } -} - -export function resetBridgeAmount() { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/AMOUNT/RESET'}); - } -} - -export function setTeleportationOfAssetSupported(payload) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/TELEPORTER/TOKEN_SUPPORTED', payload}) - } -} - -export function setTeleportationDestChainId(payload) { - return function (dispatch) { - return dispatch({ type: 'BRIDGE/TELEPORTER/DEST_CHAIN_ID', payload}) - } -} - -export function setFetchDepositTxBlock(payload) { - store.dispatch({ type: 'BRIDGE/DEPOSIT_TX/BLOCK', payload}) -} diff --git a/src/actions/bridgeAction.ts b/src/actions/bridgeAction.ts new file mode 100644 index 00000000..e92799e3 --- /dev/null +++ b/src/actions/bridgeAction.ts @@ -0,0 +1,82 @@ +/* +Copyright 2021-present Boba Network. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +import store from 'store' +import { BigNumberish } from 'ethers' + +export interface IBridgeAltert { + meta: string + type: string + text: string +} + +export const resetToken = () => (dispatch) => + dispatch({ type: 'BRIDGE/TOKEN/RESET' }) + +export const updateToken = (payload?) => (dispatch) => + dispatch({ type: 'BRIDGE/TOKEN/UPDATE', payload }) + +export const setBridgeType = (type) => (dispatch) => + dispatch({ type: 'BRIDGE/TYPE/SELECT', payload: type }) + +export const setBridgeDestinationAddress = (payload: string) => (dispatch) => + dispatch({ + type: 'BRIDGE/DESTINATION_ADDRESS/SET', + payload, + }) + +export const resetBridgeDestinationAddress = () => (dispatch) => + dispatch({ type: 'BRIDGE/DESTINATION_ADDRESS/RESET' }) + +// updates value indicating wether the 'to address' field should be available +export const setBridgeDestinationAddressAvailable = + (payload: boolean) => (dispatch) => + dispatch({ + type: 'BRIDGE/DESTINATION_ADDRESS_AVAILABLE/SET', + payload, + }) + +export const setBridgeAlert = (payload: IBridgeAltert) => (dispatch) => + dispatch({ type: 'BRIDGE/ALERT/SET', payload }) + +export const clearBridgeAlert = (payload: { keys: string[] }) => (dispatch) => + dispatch({ type: 'BRIDGE/ALERT/CLEAR', payload }) + +export const purgeBridgeAlert = (payload?) => (dispatch) => + dispatch({ type: 'BRIDGE/ALERT/PURGE', payload }) + +export const setAmountToBridge = (payload?) => (dispatch) => + dispatch({ type: 'BRIDGE/AMOUNT/SET', payload }) + +export const resetBridgeAmount = () => (dispatch) => + dispatch({ type: 'BRIDGE/AMOUNT/RESET' }) + +export const setTeleportationOfAssetSupported = + (payload: boolean) => (dispatch) => + dispatch({ + type: 'BRIDGE/TELEPORTER/TOKEN_SUPPORTED', + payload, + }) + +export const setTeleportationDestChainId = + (payload: BigNumberish) => (dispatch) => + dispatch({ + type: 'BRIDGE/TELEPORTER/DEST_CHAIN_ID', + payload, + }) + +export const setFetchDepositTxBlock = (payload?) => { + store.dispatch({ type: 'BRIDGE/DEPOSIT_TX/BLOCK', payload }) +} diff --git a/src/actions/createAction.js b/src/actions/createAction.js deleted file mode 100644 index 6b99479d..00000000 --- a/src/actions/createAction.js +++ /dev/null @@ -1,104 +0,0 @@ -/* -Copyright 2021-present Boba Network. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -import * as Sentry from '@sentry/react'; - -export function createAction (key, asyncAction) { - - return async function (dispatch) { - - dispatch({ type: `${key}/REQUEST` }) - - try { - const response = await asyncAction() - - if( response === false ) { - return false - } - - if(response && typeof(response) === 'string' && response?.includes('execution reverted: ERC20Permit')) { - let errorMessage = JSON.parse(response) - dispatch({ type: `UI/ERROR/UPDATE`, payload: errorMessage.error.message }) - dispatch({ type: `${key}/ERROR` }) - Sentry.captureMessage(errorMessage.error.message); - return false - } - - if(response && typeof(response) === 'string' && response?.includes('Insufficient balance')) { - //let errorMessage = JSON.parse(response) - dispatch({ type: `UI/ERROR/UPDATE`, payload: "Insufficient BOBA balance for emergency swap" }) - dispatch({ type: `${key}/ERROR` }) - Sentry.captureMessage("Insufficient BOBA balance for emergency swap"); - return false - } - - //deal with metamask errors - they will have a 'code' field so we can detect those - if(response && response.hasOwnProperty('message') && response.hasOwnProperty('code')) { - Sentry.captureMessage(response.reason) - if(response.hasOwnProperty('reason')) console.log("Error reason:", response.reason) - - // the basic error message - let errorMessage = response.message - - // provide more information in special cases - // MetaMask user rejected sig - throw up a banner - if ((response.code === 4001 || - response.hasOwnProperty('reason')) - && response?.reason?.includes('user rejected transaction') - ) { - console.log("MetaMask: user denied signature") - errorMessage = 'MetaMask: Transaction was rejected by user - signature denied' - } - // No internet case - throw up a banner - else if(response.hasOwnProperty('reason') && response?.reason?.includes('could not detect network')) { - console.log("Gateway error: No network") - errorMessage = 'Gateway: No internet' - } - // ethers error - else if(response.hasOwnProperty('reason') && response.reason?.includes('missing revert data in call exception')) { - console.log("Slow network or rate throttling - code 1") - // intercept error - return false - } - // ethers error - else if(response.hasOwnProperty('reason') && response.reason?.includes('resolver or addr is not configured for ENS name')) { - console.log("Slow network or rate throttling - code 2") - // intercept error - return false - } - // ethers error - else if(response.hasOwnProperty('reason') && response.reason?.includes('missing response')) { - console.log("Slow network or rate throttling - code 3") - // intercept error - return false - } - - dispatch({ type: `UI/ERROR/UPDATE`, payload: errorMessage }) - dispatch({ type: `${key}/ERROR` }) - - return false - } - - dispatch({ type: `${key}/SUCCESS`, payload: response }) - return response || true - - } catch (error) { - console.log("Unhandled error RAW:", { error, key, asyncAction }) - - Sentry.captureException(error); - return false - } - } -} diff --git a/src/actions/createAction.ts b/src/actions/createAction.ts new file mode 100644 index 00000000..9fe32ec6 --- /dev/null +++ b/src/actions/createAction.ts @@ -0,0 +1,135 @@ +/* +Copyright 2021-present Boba Network. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +import * as Sentry from '@sentry/react' + +export const createAction = + (key: string, asyncAction: () => any) => async (dispatch) => { + dispatch({ type: `${key}/REQUEST` }) + + try { + const response = await asyncAction() + + if (response === false) { + return false + } + + if ( + response && + typeof response === 'string' && + response?.includes('execution reverted: ERC20Permit') + ) { + const errorMessage = JSON.parse(response) + dispatch({ + type: `UI/ERROR/UPDATE`, + payload: errorMessage.error.message, + }) + dispatch({ type: `${key}/ERROR` }) + Sentry.captureMessage(errorMessage.error.message) + return false + } + + if ( + response && + typeof response === 'string' && + response?.includes('Insufficient balance') + ) { + //let errorMessage = JSON.parse(response) + dispatch({ + type: `UI/ERROR/UPDATE`, + payload: 'Insufficient BOBA balance for emergency swap', + }) + dispatch({ type: `${key}/ERROR` }) + Sentry.captureMessage('Insufficient BOBA balance for emergency swap') + return false + } + + //deal with metamask errors - they will have a 'code' field so we can detect those + if ( + response && + response.hasOwnProperty('message') && + response.hasOwnProperty('code') + ) { + Sentry.captureMessage(response.reason) + if (response.hasOwnProperty('reason')) { + console.log('Error reason:', response.reason) + } + + // the basic error message + let errorMessage = response.message + + // provide more information in special cases + // MetaMask user rejected sig - throw up a banner + if ( + (response.code === 4001 || response.hasOwnProperty('reason')) && + response?.reason?.includes('user rejected transaction') + ) { + console.log('MetaMask: user denied signature') + errorMessage = + 'MetaMask: Transaction was rejected by user - signature denied' + } + // No internet case - throw up a banner + else if ( + response.hasOwnProperty('reason') && + response?.reason?.includes('could not detect network') + ) { + console.log('Gateway error: No network') + errorMessage = 'Gateway: No internet' + } + // ethers error + else if ( + response.hasOwnProperty('reason') && + response.reason?.includes('missing revert data in call exception') + ) { + console.log('Slow network or rate throttling - code 1') + // intercept error + return false + } + // ethers error + else if ( + response.hasOwnProperty('reason') && + response.reason?.includes( + 'resolver or addr is not configured for ENS name' + ) + ) { + console.log('Slow network or rate throttling - code 2') + // intercept error + return false + } + // ethers error + else if ( + response.hasOwnProperty('reason') && + response.reason?.includes('missing response') + ) { + console.log('Slow network or rate throttling - code 3') + // intercept error + return false + } + + dispatch({ type: `UI/ERROR/UPDATE`, payload: errorMessage }) + dispatch({ type: `${key}/ERROR` }) + + return false + } + + dispatch({ type: `${key}/SUCCESS`, payload: response }) + return response || true + } catch (error) { + console.log('Unhandled error RAW:', { error, key, asyncAction }) + + Sentry.captureException(error) + return false + } + } diff --git a/src/actions/daoAction.js b/src/actions/daoAction.js deleted file mode 100644 index e434d5f6..00000000 --- a/src/actions/daoAction.js +++ /dev/null @@ -1,79 +0,0 @@ -/* - Varna - A Privacy-Preserving Marketplace - Varna uses Fully Homomorphic Encryption to make markets fair. - Copyright (C) 2021 Enya Inc. Palo Alto, CA - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -import networkService from 'services/networkService'; -import { createAction } from './createAction' - -/***********************************************/ -/***** DAO Action *****/ -/***********************************************/ - -export function fetchDaoBalance() { - return createAction('BALANCE/DAO/GET', () => networkService.getDaoBalance()) -} - -export function fetchDaoVotes() { - return createAction('VOTES/DAO/GET', () => networkService.getDaoVotes()) -} - -export function fetchDaoBalanceX() { - return createAction('BALANCEX/DAO/GET', () => networkService.getDaoBalanceX()) -} - -export function fetchDaoVotesX() { - return createAction('VOTESX/DAO/GET', () => networkService.getDaoVotesX()) -} - -export function transferDao({ recipient, amount }) { - return createAction('TRANSFER/DAO/CREATE', () => networkService.transferDao({ recipient, amount })) -} - -export function delegateVotes({ recipient }) { - return createAction('DELEGATE/VOTES/CREATE', () => networkService.delegateVotes({ recipient })) -} - -export function delegateVotesX({ recipient }) { - return createAction('DELEGATEX/VOTES/CREATE', () => networkService.delegateVotesX({ recipient })) -} - -export function getProposalThreshold() { - return createAction('PROPOSALTHRESHOLD/GET', () => networkService.getProposalThreshold()) -} - -export function fetchDaoProposals() { - return createAction('PROPOSALS/GET', () => networkService.fetchProposals()) -} - -export function createDaoProposal(payload) { - return createAction('PROPOSAL/CREATE', () => networkService.createProposal(payload)) -} - -export function queueProposal(proposalID) { - return createAction('PROPOSAL/QUEUE', () => networkService.queueProposal(proposalID)) -} - -export function executeProposal(proposalID) { - return createAction('PROPOSAL/EXECUTE', () => networkService.executeProposal(proposalID)) -} - -export function castProposalVote(payload) { - return createAction('PROPOSAL/CAST/VOTE', () => networkService.castProposalVote(payload)) -} - - diff --git a/src/actions/daoAction.ts b/src/actions/daoAction.ts new file mode 100644 index 00000000..f61857d1 --- /dev/null +++ b/src/actions/daoAction.ts @@ -0,0 +1,72 @@ +/* + Varna - A Privacy-Preserving Marketplace + Varna uses Fully Homomorphic Encryption to make markets fair. + Copyright (C) 2021 Enya Inc. Palo Alto, CA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import networkService from 'services/networkService' +import { createAction } from './createAction' + +/***********************************************/ +/***** DAO Action *****/ +/***********************************************/ + +/***** DAO Action *****/ +export const fetchDaoBalance = () => + createAction('BALANCE/DAO/GET', () => networkService.getDaoBalance()) + +export const fetchDaoVotes = () => + createAction('VOTES/DAO/GET', () => networkService.getDaoVotes()) + +export const fetchDaoBalanceX = () => + createAction('BALANCEX/DAO/GET', () => networkService.getDaoBalanceX()) + +export const fetchDaoVotesX = () => + createAction('VOTESX/DAO/GET', () => networkService.getDaoVotesX()) + +export const delegateVotes = ({ recipient }) => + createAction('DELEGATE/VOTES/CREATE', () => + networkService.delegateVotes({ recipient }) + ) + +export const delegateVotesX = ({ recipient }) => + createAction('DELEGATEX/VOTES/CREATE', () => + networkService.delegateVotesX({ recipient }) + ) + +export const getProposalThreshold = () => + createAction('PROPOSALTHRESHOLD/GET', () => + networkService.getProposalThreshold() + ) + +export const fetchDaoProposals = () => + createAction('PROPOSALS/GET', () => networkService.fetchProposals()) + +export const createDaoProposal = (payload) => + createAction('PROPOSAL/CREATE', () => networkService.createProposal(payload)) + +export const queueProposal = (proposalID) => + createAction('PROPOSAL/QUEUE', () => networkService.queueProposal(proposalID)) + +export const executeProposal = (proposalID) => + createAction('PROPOSAL/EXECUTE', () => + networkService.executeProposal(proposalID) + ) + +export const castProposalVote = (payload) => + createAction('PROPOSAL/CAST/VOTE', () => + networkService.castProposalVote(payload) + ) diff --git a/src/actions/devToolsAction.js b/src/actions/devToolsAction.ts similarity index 67% rename from src/actions/devToolsAction.js rename to src/actions/devToolsAction.ts index ab0b064f..5ac55510 100644 --- a/src/actions/devToolsAction.js +++ b/src/actions/devToolsAction.ts @@ -17,15 +17,19 @@ along with this program. If not, see . */ -import networkService from 'services/networkService'; +import networkService from 'services/networkService' import { createAction } from './createAction' +import { Contract } from 'ethers' -export function submitTxBuilder(contract, methodIndex, methodName, inputs) { - return createAction('TX_BUILDER', () => networkService.submitTxBuilder(contract, methodIndex, methodName, inputs)) -} +export const submitTxBuilder = ( + contract: Contract, + methodIndex: number, + methodName: string, + inputs: any +) => + createAction('TX_BUILDER', () => + networkService.submitTxBuilder(contract, methodIndex, methodName, inputs) + ) -export function resetTxBuilder() { - return function (dispatch) { - return dispatch({ type: 'TX_BUILDER/REST'}) - } -} +export const resetTxBuilder = () => (dispatch) => + dispatch({ type: 'TX_BUILDER/REST' }) diff --git a/src/actions/earnAction.js b/src/actions/earnAction.js deleted file mode 100644 index e7d0b911..00000000 --- a/src/actions/earnAction.js +++ /dev/null @@ -1,124 +0,0 @@ -/* - Varna - A Privacy-Preserving Marketplace - Varna uses Fully Homomorphic Encryption to make markets fair. - Copyright (C) 2021 Enya Inc. Palo Alto, CA - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -import networkService from 'services/networkService' -import { createAction } from './createAction' - -const getEarnInfoBegin = () => ({ - type: 'GET_EARNINFO', -}) - -const getEarnInfoSuccess = (L1PoolInfo, L1UserInfo, L2PoolInfo, L2UserInfo) => ({ - type: 'GET_EARNINFO_SUCCESS', - payload: { L1PoolInfo, L1UserInfo, L2PoolInfo, L2UserInfo } -}) - -// const getL1FeeBegin = () => ({ -// type: 'GET_USERINFO', -// }) - -// const getL2FeeBegin = () => ({ -// type: 'GET_USERINFO', -// }) - -// const getL1FeeSuccess = (totalFeeRate, userRewardFeeRate) => ({ -// type: 'GET_L1FEE_SUCCESS', -// payload: { totalFeeRate, userRewardFeeRate }, -// }) - -// const getL2FeeSuccess = (totalFeeRate, userRewardFeeRate) => ({ -// type: 'GET_L2FEE_SUCCESS', -// payload: { totalFeeRate, userRewardFeeRate }, -// }) - -export const getEarnInfo = () => async (dispatch) => { - dispatch(getEarnInfoBegin()) - const [L1LPInfo, L2LPInfo] = await Promise.all([ - networkService.getL1LPInfo(), - networkService.getL2LPInfo(), - ]) - dispatch(getEarnInfoSuccess( - L1LPInfo.poolInfo, - L1LPInfo.userInfo, - L2LPInfo.poolInfo, - L2LPInfo.userInfo, - )) -} - -// export const getL1Fee = () => async (dispatch) => { -// dispatch(getL1FeeBegin()) -// const [totalFeeRate, userFeeRate] = await Promise.all([ -// networkService.getL1TotalFeeRate(), -// networkService.getL1UserRewardFeeRate(), -// ]) -// console.log("L1 totalFeeRate",totalFeeRate) -// console.log("L1 userRewardFeeRate",userFeeRate) -// dispatch(getL1FeeSuccess(totalFeeRate, userFeeRate)) -// } - -// export const getL2Fee = () => async (dispatch) => { -// dispatch(getL2FeeBegin()) -// const [totalFeeRate, userFeeRate] = await Promise.all([ -// networkService.getL2TotalFeeRate(), -// networkService.getL2UserRewardFeeRate(), -// ]) -// console.log("L2 totalFeeRate",totalFeeRate) -// console.log("L2 userRewardFeeRate",userFeeRate) -// dispatch(getL2FeeSuccess(totalFeeRate, userFeeRate)) -// } - -export function fetchL1UserFee(currency) {return createAction('FETCH/L1USERFEE', () => networkService.getL1UserRewardFeeRate(currency))} -export function fetchL2UserFee(currency) {return createAction('FETCH/L2USERFEE', () => networkService.getL2UserRewardFeeRate(currency))} - -export const updateStakeToken = (stakeToken) => ({ - type: 'UPDATE_STAKE_TOKEN', - payload: stakeToken, -}) - -export const updateWithdrawToken = (withdrawToken) => ({ - type: 'UPDATE_WITHDRAW_TOKEN', - payload: withdrawToken, -}) - -export function fetchAllowance(currency, lpAddress) { - return createAction('FETCH/ALLOWANCE', () => networkService.checkAllowance( - currency, - lpAddress - )) -} - -export function addLiquidity( - currency, - weiString, - L1orL2Pool -) { - return createAction('ADD/LIQUIDITY', () => networkService.addLiquidity( - currency, - weiString, - L1orL2Pool - )) -} - -export function fetchL1LPBalance(currency) { - return createAction('FETCH/L1LPBALANCE', () => networkService.L1LPBalance(currency)) -} - -export function fetchL2LPBalance(currency) { - return createAction('FETCH/L2LPBALANCE', () => networkService.L2LPBalance(currency)) -} diff --git a/src/actions/earnAction.ts b/src/actions/earnAction.ts new file mode 100644 index 00000000..860dbf7b --- /dev/null +++ b/src/actions/earnAction.ts @@ -0,0 +1,81 @@ +/* + Varna - A Privacy-Preserving Marketplace + Varna uses Fully Homomorphic Encryption to make markets fair. + Copyright (C) 2021 Enya Inc. Palo Alto, CA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import networkService from 'services/networkService' +import { createAction } from './createAction' + +const getEarnInfoBegin = () => ({ + type: 'GET_EARNINFO', +}) + +const getEarnInfoSuccess = ( + L1PoolInfo, + L1UserInfo, + L2PoolInfo, + L2UserInfo +) => ({ + type: 'GET_EARNINFO_SUCCESS', + payload: { L1PoolInfo, L1UserInfo, L2PoolInfo, L2UserInfo }, +}) + +export const getEarnInfo = () => async (dispatch) => { + dispatch(getEarnInfoBegin()) + const [L1LPInfo, L2LPInfo] = await Promise.all([ + networkService.getL1LPInfo(), + networkService.getL2LPInfo(), + ]) + dispatch( + getEarnInfoSuccess( + L1LPInfo.poolInfo, + L1LPInfo.userInfo, + L2LPInfo.poolInfo, + L2LPInfo.userInfo + ) + ) +} + +export const updateStakeToken = (stakeToken: string) => ({ + type: 'UPDATE_STAKE_TOKEN', + payload: stakeToken, +}) + +export const updateWithdrawToken = (withdrawToken: string) => ({ + type: 'UPDATE_WITHDRAW_TOKEN', + payload: withdrawToken, +}) + +export const fetchAllowance = (currency: string, lpAddress: string) => + createAction('FETCH/ALLOWANCE', () => + networkService.checkAllowance(currency, lpAddress) + ) + +export const addLiquidity = ( + currency: string, + weiString: string, + L1orL2Pool: string +) => + createAction('ADD/LIQUIDITY', () => + networkService.addLiquidity(currency, weiString, L1orL2Pool) + ) + +export const fetchL1LPBalance = (currency: string) => + createAction('FETCH/L1LPBALANCE', () => networkService.L1LPBalance(currency)) + +export const fetchL2LPBalance = (currency: string) => + createAction('FETCH/L2LPBALANCE', () => networkService.L2LPBalance(currency)) diff --git a/src/actions/fixedAction.js b/src/actions/fixedAction.ts similarity index 64% rename from src/actions/fixedAction.js rename to src/actions/fixedAction.ts index d6058090..09694f53 100644 --- a/src/actions/fixedAction.js +++ b/src/actions/fixedAction.ts @@ -20,18 +20,16 @@ import networkService from 'services/networkService' import { createAction } from './createAction' -export function addFS_Savings(weiString) { - return createAction('ADD/FS_SAVINGS', () => networkService.addFS_Savings(weiString)) -} +export const addFS_Savings = (weiString: string) => + createAction('ADD/FS_SAVINGS', () => networkService.addFS_Savings(weiString)) -export function withdrawFS_Savings(stakeID) { - return createAction('WITHDRAW/FS_SAVINGS', () => networkService.withdrawFS_Savings(stakeID)) -} +export const withdrawFS_Savings = (stakeID: number) => + createAction('WITHDRAW/FS_SAVINGS', () => + networkService.withdrawFS_Savings(stakeID) + ) -export function getFS_Saves(currency) { - return createAction('GET/FS_SAVES', () => networkService.getFS_Saves()) -} +export const getFS_Saves = () => + createAction('GET/FS_SAVES', () => networkService.getFS_Saves()) -export function getFS_Info(currency) { - return createAction('GET/FS_INFO', () => networkService.getFS_Info()) -} \ No newline at end of file +export const getFS_Info = () => + createAction('GET/FS_INFO', () => networkService.getFS_Info()) diff --git a/src/actions/networkAction.js b/src/actions/networkAction.js deleted file mode 100644 index c3c1fc38..00000000 --- a/src/actions/networkAction.js +++ /dev/null @@ -1,283 +0,0 @@ -/* -Copyright 2021-present Boba Network. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -import networkService from 'services/networkService' -import transactionService from 'services/transaction.service' -import { createAction } from './createAction' - -export function fetchBalances() { - return createAction('BALANCE/GET', () => networkService.getBalances()) -} - -export function addTokenList() { - return createAction('TOKENLIST/GET', () => networkService.addTokenList()) -} - -export function fetchTransactions() { - return createAction('TRANSACTION/GETALL', () => - transactionService.getTransactions() - ) -} - -export function fetchSevens() { - return createAction('SEVENS/GETALL', () => - transactionService.getSevens() - ) -} - -export function fetchFastExits() { - return createAction('FASTEXITS/GETALL', () => - transactionService.getFastExits() - ) -} - -export function exitBOBA(token, value) { - return createAction('EXIT/CREATE', () => - networkService.exitBOBA(token, value) - ) -} - -//SWAP RELATED -export function depositL1LP(currency,value) { - return createAction('DEPOSIT/CREATE', () => - networkService.depositL1LP(currency,value) - ) -} - -export function isTeleportationOfAssetSupported(layer, asset, destChainId) { - return createAction('DEPOSIT/TELEPORTATION/TOKEN_SUPPORTED', () => - networkService.isTeleportationOfAssetSupported(layer, asset, destChainId) - ) -} - -export function depositWithTeleporter(layer, currency, value, destChainId) { - return createAction('DEPOSIT/CREATE', () => - networkService.depositWithTeleporter(layer, currency, value, destChainId) - ) -} - -export function depositL1LPBatch(payload) { - return createAction('DEPOSIT/CREATE', () => - networkService.depositL1LPBatch(payload) - ) -} - -//SWAP RELATED - Depositing into the L2LP triggers the swap-exit -export function depositL2LP(token, value) { - return createAction('EXIT/CREATE', () => - networkService.depositL2LP(token, value) - ) -} - -//SWAP RELATED - Depositing into the L2LP triggers the swap-exit - variant of depositL2LP -//that handles Exit All -export function fastExitAll(token) { - return createAction('EXIT/CREATE', () => - networkService.fastExitAll(token) - ) -} - -//CLASSIC DEPOSIT ETH -export function depositETHL2(payload) { - return createAction('DEPOSIT/CREATE', () => { - return networkService.depositETHL2(payload) - } - ) -} - -//DEPOSIT ERC20 -export function depositErc20(payload) { - return createAction('DEPOSIT/CREATE', () => - networkService.depositErc20(payload) - ) -} - -//DEPOSIT ERC20 to Alt L1 bridge -export function depositErc20ToL1(payload) { - return createAction('DEPOSIT_ALTL1/CREATE', () => networkService.depositErc20ToL1(payload)) -} - -//EARN -export function earnL1(value_Wei_String, currencyAddress) { - return createAction('EARN/CREATE', () => - networkService.approveERC20_L1LP(value_Wei_String, currencyAddress) - ) -} -export function earnL2(value_Wei_String, currencyAddress) { - return createAction('EARN/CREATE', () => - networkService.approveERC20_L2LP(value_Wei_String, currencyAddress) - ) -} -export function getReward(currencyAddress, value_Wei_String, L1orL2Pool) { - return createAction('EARN/HARVEST', () => - networkService.getReward(currencyAddress, value_Wei_String, L1orL2Pool) - ) -} - -export function withdrawLiquidity(currencyAddress, value_Wei_String, L1orL2Pool) { - - return createAction('EARN/WITHDRAW', () => - networkService.withdrawLiquidity(currencyAddress, value_Wei_String, L1orL2Pool) - ) -} - -export function approveERC20( - value, - currency, - approveContractAddress, - contractABI -) { - return createAction('APPROVE/CREATE', () => - networkService.approveERC20( - value, - currency, - approveContractAddress, - contractABI - ) - ) -} - -export function approveFastDepositBatch(payload) { - return createAction('APPROVE/CREATE', () => - networkService.approveFastDepositBatch( - payload - ) - ) -} - -export function approveERC20_L2LP( - value, - currency, -) { - return createAction('APPROVE/CREATE', () => - networkService.approveERC20_L2LP( - value, - currency, - ) - ) -} - -export function approveERC20_L1LP( - value, - currency, -) { - return createAction('APPROVE/CREATE', () => - networkService.approveERC20_L1LP( - value, - currency, - ) - ) -} - -export function transfer(recipient, value, currency) { - return createAction('TRANSFER/CREATE', () => - networkService.transfer(recipient, value, currency) - ) -} - -export function transferEstimate(value_Wei_String, currency) { - return createAction('TRANSFER_ESTIMATE/CREATE', () => - networkService.transferEstimate(value_Wei_String, currency) - ) -} - -export function transferNFT(recipient, nft) { - return createAction('TRANSFER_NFT/CREATE', () => - networkService.transferNFT(recipient, nft) - ) -} - -export function settle_v0() { - return createAction('SETTLE_v0/CREATE', () => - networkService.settle_v0() - ) -} - -export function settle_v1() { - return createAction('SETTLE_v1/CREATE', () => - networkService.settle_v1() - ) -} - -export function settle_v2() { - return createAction('SETTLE_v2/CREATE', () => - networkService.settle_v2() - ) -} - -export function settle_v2OLO() { - return createAction('SETTLE_v2OLO/CREATE', () => - networkService.settle_v2OLO() - ) -} - -export function settle_v3() { - return createAction('SETTLE_v3/CREATE', () => - networkService.settle_v3() - ) -} - -export function settle_v3OLO() { - return createAction('SETTLE_v3OLO/CREATE', () => - networkService.settle_v3OLO() - ) -} - -export function fetchLookUpPrice(params) { - return createAction('PRICE/GET', () => - networkService.fetchLookUpPrice(params)) -} - -export function clearLookupPrice() { - return function (dispatch) { - return dispatch({ type: 'LOOKUP/PRICE/CLEAR' }) - } -} - -export function enableBrowserWallet(network) { - return createAction('ENABLE/BROWSER/WALLET', () => networkService.enableBrowserWallet(network)) -} - -export function getAllAddresses() { - return createAction('GET/ALL/ADDRESS', () => networkService.getAllAddresses()) -} - - -/********************************/ -/******ONE GATEWAY ACTIONS *****/ -/********************************/ -/** - * @params - * network - ethereum, bnb, avax - * networkType - MAINNET, TESTNET -*/ -export function setNetwork(payload) { - return function (dispatch) { - return dispatch({ type: 'NETWORK/SET', payload: payload }) - } -} - -// to update the active network. -export function setActiveNetwork(payload) { - return function (dispatch) { - return dispatch({ type: 'NETWORK/SET/ACTIVE' }) - } -} - -export function setActiveNetworkType(payload) { - return function (dispatch) { - return dispatch({ type: 'NETWORK/SET_TYPE/ACTIVE', payload }) - } -} diff --git a/src/actions/networkAction.ts b/src/actions/networkAction.ts new file mode 100644 index 00000000..9212736a --- /dev/null +++ b/src/actions/networkAction.ts @@ -0,0 +1,163 @@ +/* +Copyright 2021-present Boba Network. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +import networkService from 'services/networkService' +import transactionService from 'services/transaction.service' +import { createAction } from './createAction' +import { BigNumberish } from 'ethers' + +export const fetchBalances = () => + createAction('BALANCE/GET', () => networkService.getBalances()) + +export const addTokenList = () => + createAction('TOKENLIST/GET', () => networkService.addTokenList()) + +export const fetchTransactions = () => + createAction('TRANSACTION/GETALL', () => transactionService.getTransactions()) + +export const fetchSevens = () => + createAction('SEVENS/GETALL', () => transactionService.getSevens()) + +export const fetchFastExits = () => + createAction('FASTEXITS/GETALL', () => transactionService.getFastExits()) + +export const exitBOBA = (token: string, value: BigNumberish) => + createAction('EXIT/CREATE', () => networkService.exitBOBA(token, value)) + +//SWAP RELATED +export const depositL1LP = (currency: string, value: BigNumberish) => + createAction('DEPOSIT/CREATE', () => + networkService.depositL1LP(currency, value) + ) + +export const isTeleportationOfAssetSupported = ( + layer: string, + asset: string, + destChainId: string +) => + createAction('DEPOSIT/TELEPORTATION/TOKEN_SUPPORTED', () => + networkService.isTeleportationOfAssetSupported(layer, asset, destChainId) + ) + +export const depositWithLightBridge = ( + layer: string, + currency: string, + value: BigNumberish, + destChainId: BigNumberish +) => + createAction('DEPOSIT/CREATE', () => + networkService.depositWithTeleporter(layer, currency, value, destChainId) + ) + +//SWAP RELATED - Depositing into the L2LP triggers the swap-exit +export const depositL2LP = (token: string, value: BigNumberish) => + createAction('EXIT/CREATE', () => networkService.depositL2LP(token, value)) + +//CLASSIC DEPOSIT ETH +export const depositETHL2 = (payload) => + createAction('DEPOSIT/CREATE', () => { + return networkService.depositETHL2(payload) + }) + +//DEPOSIT ERC20 +export const depositErc20 = (payload) => + createAction('DEPOSIT/CREATE', () => networkService.depositErc20(payload)) + +//EARN +export const earnL1 = ( + value_Wei_String: BigNumberish, + currencyAddress: string +) => + createAction('EARN/CREATE', () => + networkService.approveERC20_L1LP(value_Wei_String, currencyAddress) + ) +export const earnL2 = ( + value_Wei_String: BigNumberish, + currencyAddress: string +) => + createAction('EARN/CREATE', () => + networkService.approveERC20_L2LP(value_Wei_String, currencyAddress) + ) +export const getReward = ( + currencyAddress: string, + value_Wei_String: BigNumberish, + L1orL2Pool: string +) => + createAction('EARN/HARVEST', () => + networkService.getReward(currencyAddress, value_Wei_String, L1orL2Pool) + ) + +export const withdrawLiquidity = ( + currencyAddress: string, + value_Wei_String: string, + L1orL2Pool: string +) => + createAction('EARN/WITHDRAW', () => + networkService.withdrawLiquidity( + currencyAddress, + value_Wei_String, + L1orL2Pool + ) + ) + +export const approveERC20 = ( + value: BigNumberish, + currency: string, + approveContractAddress: string, + contractABI? +) => + createAction('APPROVE/CREATE', () => + networkService.approveERC20( + value, + currency, + approveContractAddress, + contractABI + ) + ) + +export const transfer = ( + recipient: string, + value: BigNumberish, + currency: string +) => + createAction('TRANSFER/CREATE', () => + networkService.transfer(recipient, value, currency) + ) + +export const fetchLookUpPrice = (params) => + createAction('PRICE/GET', () => networkService.fetchLookUpPrice(params)) + +export const clearLookupPrice = () => (dispatch) => + dispatch({ type: 'LOOKUP/PRICE/CLEAR' }) + +export const getAllAddresses = () => + createAction('GET/ALL/ADDRESS', () => networkService.getAllAddresses()) + +/********************************/ +/******ONE GATEWAY ACTIONS *****/ +/********************************/ +/** + * @param payload: {network: ethereum, bnb, networkType + * @param networkType: MAINNET, TESTNET + */ +export const setNetwork = (payload) => (dispatch) => + dispatch({ type: 'NETWORK/SET', payload }) + +// to update the active network. +export const setActiveNetwork = () => (dispatch) => + dispatch({ type: 'NETWORK/SET/ACTIVE' }) + +export const setActiveNetworkType = (payload) => (dispatch) => + dispatch({ type: 'NETWORK/SET_TYPE/ACTIVE', payload }) diff --git a/src/actions/setupAction.js b/src/actions/setupAction.js deleted file mode 100644 index 0a5cc6d0..00000000 --- a/src/actions/setupAction.js +++ /dev/null @@ -1,102 +0,0 @@ -/* -Copyright 2021-present Boba Network. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - - -import networkService from 'services/networkService' -import { createAction } from './createAction' -import store from 'store' - -export function setEnableAccount(enabled) { - return function (dispatch) { - return dispatch({ type: 'SETUP/ACCOUNT/SET', payload: enabled }) - } -} - -export function setBaseState(enabled) { - return function (dispatch) { - return dispatch({ type: 'SETUP/BASE/SET', payload: enabled }) - } -} - -export function setLayer(layer) { - return function (dispatch) { - return dispatch({ type: 'SETUP/LAYER/SET', payload: layer }) - } -} - -export function setWalletAddress(account) { - return function (dispatch) { - return dispatch({ type: 'SETUP/WALLETADDRESS/SET', payload: account }) - } -} - -export function switchChain(layer) { - return createAction('SETUP/SWITCH', () => networkService.switchChain(layer)) -} - -export function switchFee(targetFee) { - return createAction('SETUP/SWITCHFEE', () => networkService.switchFee(targetFee)) -} - -export function getETHMetaTransaction() { - return createAction('SETUP/GETETH', () => networkService.getETHMetaTransaction()) -} - -export async function addBobaFee ( bobaFee ) { - store.dispatch({ type: 'BOBAFEE/ADD/SUCCESS', payload: bobaFee }) -} - -export function setConnectETH( state ) { - return function (dispatch) { - return dispatch({ type: 'SETUP/CONNECT_ETH', payload: state }) - } -} - -export function setConnectBOBA( state ) { - return function (dispatch) { - return dispatch({ type: 'SETUP/CONNECT_BOBA', payload: state }) - } -} - -export function setConnect( state ) { - return function (dispatch) { - return dispatch({ type: 'SETUP/CONNECT', payload: state }) - } -} - -export function setWalletConnected( state ) { - return function (dispatch) { - return dispatch({ type: 'SETUP/WALLET_CONNECTED', payload: state }) - } -} - -export function setChainIdChanged(state) { - return function (dispatch) { - return dispatch({ type: 'SETUP/CHAINIDCHANGED/SET', payload: state }) - } -} - -export function resetChainIdChanged() { - return function (dispatch) { - return dispatch({ type: 'SETUP/CHAINIDCHANGED/RESET' }) - } -} - - -export function disconnectSetup() { - return function(dispatch) { - return dispatch({type: 'SETUP/DISCONNECT'}) - } -} \ No newline at end of file diff --git a/src/actions/setupAction.ts b/src/actions/setupAction.ts new file mode 100644 index 00000000..de92f2ad --- /dev/null +++ b/src/actions/setupAction.ts @@ -0,0 +1,55 @@ +/* +Copyright 2021-present Boba Network. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +import networkService from 'services/networkService' +import { createAction } from './createAction' +import store from 'store' + +export const setEnableAccount = (enabled) => (dispatch) => + dispatch({ type: 'SETUP/ACCOUNT/SET', payload: enabled }) + +export const setBaseState = (enabled) => (dispatch) => + dispatch({ type: 'SETUP/BASE/SET', payload: enabled }) + +export const setLayer = (layer) => (dispatch) => + dispatch({ type: 'SETUP/LAYER/SET', payload: layer }) + +export const setWalletAddress = (account) => (dispatch) => + dispatch({ type: 'SETUP/WALLETADDRESS/SET', payload: account }) + +export const switchFee = (targetFee) => + createAction('SETUP/SWITCHFEE', () => networkService.switchFee(targetFee)) + +export const getETHMetaTransaction = () => + createAction('SETUP/GETETH', () => networkService.getETHMetaTransaction()) + +export const addBobaFee = async (bobaFee) => { + store.dispatch({ type: 'BOBAFEE/ADD/SUCCESS', payload: bobaFee }) +} + +export const setConnectETH = (state) => (dispatch) => + dispatch({ type: 'SETUP/CONNECT_ETH', payload: state }) + +export const setConnectBOBA = (state) => (dispatch) => + dispatch({ type: 'SETUP/CONNECT_BOBA', payload: state }) + +export const setConnect = (state) => (dispatch) => + dispatch({ type: 'SETUP/CONNECT', payload: state }) + +export const setChainIdChanged = (state) => (dispatch) => + dispatch({ type: 'SETUP/CHAINIDCHANGED/SET', payload: state }) + +export const disconnectSetup = () => (dispatch) => + dispatch({ type: 'SETUP/DISCONNECT' }) diff --git a/src/actions/signAction.js b/src/actions/signAction.ts similarity index 55% rename from src/actions/signAction.js rename to src/actions/signAction.ts index 562d869f..94b8a0eb 100644 --- a/src/actions/signAction.js +++ b/src/actions/signAction.ts @@ -13,16 +13,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import store from 'store'; +import store from 'store' -export async function updateSignatureStatus_exitLP ( sigStatus ) { - store.dispatch({type: 'EXIT/LP/SIGNED',payload: sigStatus}) +export const updateSignatureStatus_exitLP = async (sigStatus: boolean) => { + store.dispatch({ type: 'EXIT/LP/SIGNED', payload: sigStatus }) } -export async function updateSignatureStatus_exitTRAD ( sigStatus ) { - store.dispatch({type: 'EXIT/TRAD/SIGNED',payload: sigStatus}) +export const updateSignatureStatus_exitTRAD = async (sigStatus: boolean) => { + store.dispatch({ type: 'EXIT/TRAD/SIGNED', payload: sigStatus }) } -export async function updateSignatureStatus_depositLP ( sigStatus ) { - store.dispatch({type: 'DEPOSIT/LP/SIGNED',payload: sigStatus}) +export const updateSignatureStatus_depositLP = async (sigStatus: boolean) => { + store.dispatch({ type: 'DEPOSIT/LP/SIGNED', payload: sigStatus }) } diff --git a/src/actions/tokenAction.js b/src/actions/tokenAction.ts similarity index 58% rename from src/actions/tokenAction.js rename to src/actions/tokenAction.ts index 4154462e..ad4afa75 100644 --- a/src/actions/tokenAction.js +++ b/src/actions/tokenAction.ts @@ -30,9 +30,10 @@ EVERYTHING IS INDEXED BY L1 TOKEN ADDRESS const ETHL1 = '0x0000000000000000000000000000000000000000' const ETHL2 = '0x4200000000000000000000000000000000000006' -export async function getToken ( tokenContractAddressL1 ) { - - if( tokenContractAddressL1 === null) return +export const getToken = async (tokenContractAddressL1: string) => { + if (tokenContractAddressL1 === null) { + return + } //this *might* be coming from a person, and or copy-paste from Etherscan //so need toLowerCase() @@ -54,9 +55,10 @@ export async function getToken ( tokenContractAddressL1 ) { /* Get the token info from networkService.web3.eth.Contract */ -export async function addToken ( tokenContractAddressL1 ) { - - if( tokenContractAddressL1 === null ) return +export const addToken = async (tokenContractAddressL1: string) => { + if (tokenContractAddressL1 === null) { + return + } const state = store.getState() @@ -68,93 +70,86 @@ export async function addToken ( tokenContractAddressL1 ) { //if we already have looked it up, no need to look up again. if (state.tokenList[_tokenContractAddressL1]) { - console.log("token already in list:",_tokenContractAddressL1) - return state.tokenList[_tokenContractAddressL1]; + console.log('token already in list:', _tokenContractAddressL1) + return state.tokenList[_tokenContractAddressL1] } try { - - let tA = networkService.tokenAddresses + const tA: any = networkService.tokenAddresses let tokenContract - let _tokenContractAddressL2 = null + let _tokenContractAddressL2: string /********* DO WE HAVE L2 DATA?? *************/ // Let's go see // console.log("Addresses for lookup:", networkService.tokenAddresses) - if(_tokenContractAddressL1 === 'xboba') { - if(tA['xBOBA'].L2 !== null) _tokenContractAddressL2 = tA['xBOBA'].L2.toLowerCase() + if (_tokenContractAddressL1 === 'xboba') { + _tokenContractAddressL2 = tA['xBOBA']?.L2?.toLowerCase() tokenContract = new ethers.Contract( _tokenContractAddressL2, erc20abi, - networkService.L2Provider, + networkService.L2Provider! ) } else if (_tokenContractAddressL1 === 'wagmiv0') { - if(tA['WAGMIv0'].L2 !== null) _tokenContractAddressL2 = tA['WAGMIv0'].L2.toLowerCase() + _tokenContractAddressL2 = tA['WAGMIv0']?.L2?.toLowerCase() tokenContract = new ethers.Contract( _tokenContractAddressL2, erc20abi, - networkService.L2Provider, + networkService.L2Provider! ) } else if (_tokenContractAddressL1 === 'wagmiv1') { - if(tA['WAGMIv1'].L2 !== null) _tokenContractAddressL2 = tA['WAGMIv1'].L2.toLowerCase() + _tokenContractAddressL2 = tA['WAGMIv1']?.L2?.toLowerCase() tokenContract = new ethers.Contract( _tokenContractAddressL2, erc20abi, - networkService.L2Provider, + networkService.L2Provider! ) - } - else if (_tokenContractAddressL1 === 'wagmiv2') { - if(tA['WAGMIv2'].L2 !== null) _tokenContractAddressL2 = tA['WAGMIv2'].L2.toLowerCase() + } else if (_tokenContractAddressL1 === 'wagmiv2') { + _tokenContractAddressL2 = tA['WAGMIv2']?.L2?.toLowerCase() tokenContract = new ethers.Contract( _tokenContractAddressL2, erc20abi, - networkService.L2Provider, + networkService.L2Provider! ) - } - else if (_tokenContractAddressL1 === 'wagmiv2-oolong') { - if(tA['WAGMIv2-Oolong'].L2 !== null) _tokenContractAddressL2 = tA['WAGMIv2-Oolong'].L2.toLowerCase() + } else if (_tokenContractAddressL1 === 'wagmiv2-oolong') { + _tokenContractAddressL2 = tA['WAGMIv2-Oolong']?.L2?.toLowerCase() tokenContract = new ethers.Contract( _tokenContractAddressL2, erc20abi, - networkService.L2Provider, + networkService.L2Provider! ) - } - else if (_tokenContractAddressL1 === 'wagmiv3') { - if(tA['WAGMIv3'].L2 !== null) _tokenContractAddressL2 = tA['WAGMIv3'].L2.toLowerCase() + } else if (_tokenContractAddressL1 === 'wagmiv3') { + _tokenContractAddressL2 = tA['WAGMIv3']?.L2?.toLowerCase() tokenContract = new ethers.Contract( _tokenContractAddressL2, erc20abi, - networkService.L2Provider, + networkService.L2Provider! ) - } - else if (_tokenContractAddressL1 === 'wagmiv3-oolong') { - if(tA['WAGMIv3-Oolong'].L2 !== null) _tokenContractAddressL2 = tA['WAGMIv3-Oolong'].L2.toLowerCase() + } else if (_tokenContractAddressL1 === 'wagmiv3-oolong') { + _tokenContractAddressL2 = tA['WAGMIv3-Oolong']?.L2?.toLowerCase() tokenContract = new ethers.Contract( _tokenContractAddressL2, erc20abi, - networkService.L2Provider, + networkService.L2Provider! ) - } - else if (_tokenContractAddressL1 === 'olo') { - if(tA['OLO'].L2 !== null) _tokenContractAddressL2 = tA['OLO'].L2.toLowerCase() + } else if (_tokenContractAddressL1 === 'olo') { + _tokenContractAddressL2 = tA['OLO']?.L2?.toLowerCase() tokenContract = new ethers.Contract( _tokenContractAddressL2, erc20abi, - networkService.L2Provider, + networkService.L2Provider! ) } else { Object.keys(tA).forEach((token, i) => { //let's see if we know about this Token - if(_tokenContractAddressL1 === tA[token].L1.toLowerCase()) { - if( tA[token].L2 !== null) - _tokenContractAddressL2 = tA[token].L2.toLowerCase() + if (_tokenContractAddressL1 === tA[token].L1.toLowerCase()) { + _tokenContractAddressL2 = tA[token]?.L2?.toLowerCase() } }) tokenContract = new ethers.Contract( _tokenContractAddressL1, erc20abi, - networkService.L1Provider, //Everything is defined by the L1 address - will deal with the L2 address later + networkService.L1Provider! //Everything is defined by the L1 address - will deal with the L2 address later ) } @@ -163,71 +158,84 @@ export async function addToken ( tokenContractAddressL1 ) { let _name if (ethers.utils.isAddress(_tokenContractAddressL1)) { - const tokenInfo = networkService.tokenInfo.L1[ethers.utils.getAddress(_tokenContractAddressL1)] - if (tokenInfo) { - _symbolL1 = tokenInfo.symbol - _decimals = tokenInfo.decimals - _name = tokenInfo.name + const tmpTokenInfo = + networkService.tokenInfo.L1[ + ethers.utils.getAddress(_tokenContractAddressL1) + ] + if (tmpTokenInfo) { + _symbolL1 = tmpTokenInfo.symbol + _decimals = tmpTokenInfo.decimals + _name = tmpTokenInfo.name } } if (!_symbolL1 || !_decimals || !_name) { - [ _symbolL1, _decimals, _name ] = await Promise.all([ + ;[_symbolL1, _decimals, _name] = await Promise.all([ tokenContract.symbol(), tokenContract.decimals(), - tokenContract.name() - ]).catch(e => [ null, null, null ]) + tokenContract.name(), + ]).catch((e) => [null, null, null]) } - const decimals = _decimals ? Number(_decimals.toString()) : 'NOT ON ETHEREUM' + const decimals = _decimals + ? Number(_decimals.toString()) + : 'NOT ON ETHEREUM' const symbolL1 = _symbolL1 || 'NOT ON ETHEREUM' const symbolL2 = _symbolL1 || 'NOT ON ETHEREUM' const name = _name || 'NOT ON ETHEREUM' //ETH is special as always - if(_tokenContractAddressL1 === ETHL1 ) { + if (_tokenContractAddressL1 === ETHL1) { _tokenContractAddressL2 = ETHL2 } const tokenInfo = { - currency: ( - _symbolL1 === 'xBOBA' || + currency: + _symbolL1 === 'xBOBA' || _symbolL1 === 'WAGMIv0' || _symbolL1 === 'WAGMIv1' || _symbolL1 === 'WAGMIv2' || _symbolL1 === 'WAGMIv2-Oolong' || _symbolL1 === 'WAGMIv3' || _symbolL1 === 'WAGMIv3-Oolong' - ) ? _tokenContractAddressL2 : _tokenContractAddressL1, + ? _tokenContractAddressL2! + : _tokenContractAddressL1, addressL1: _tokenContractAddressL1, - addressL2: _tokenContractAddressL2, + addressL2: _tokenContractAddressL2!, symbolL1, symbolL2, decimals, name, - redalert: _decimals ? false : true + redalert: !_decimals, } store.dispatch({ type: 'TOKEN/GET/SUCCESS', - payload: tokenInfo - }); + payload: tokenInfo, + }) return tokenInfo - } catch (error) { - store.dispatch({ type: 'TOKEN/GET/FAILURE', - payload: {currency: _tokenContractAddressL1, L1address: _tokenContractAddressL1, L2address: '', symbol: 'Not found', error: 'Not found'}, + payload: { + currency: _tokenContractAddressL1, + L1address: _tokenContractAddressL1, + L2address: '', + symbol: 'Not found', + error: 'Not found', + }, }) - return {currency: _tokenContractAddressL1, L1address: _tokenContractAddressL1, L2address: '', symbol: 'Not found', error: 'Not found'}; + return { + currency: _tokenContractAddressL1, + L1address: _tokenContractAddressL1, + L2address: '', + symbol: 'Not found', + error: 'Not found', + } } } -export function restTokenList () { - return function (dispatch) { - return dispatch({ type: 'TOKEN/GET/RESET' }); - } -} +export const restTokenList = () => (dispatch) => + dispatch({ type: 'TOKEN/GET/RESET' }) diff --git a/src/actions/transactionAction.js b/src/actions/transactionAction.ts similarity index 67% rename from src/actions/transactionAction.js rename to src/actions/transactionAction.ts index a2e84cfe..794a92d1 100644 --- a/src/actions/transactionAction.js +++ b/src/actions/transactionAction.ts @@ -13,14 +13,5 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -export function setCDMCompletion (payload) { - return function (dispatch) { - return dispatch({ type: 'CDM/COMPLETE/SET', payload }); - } -} - -export function resetCDMCompletion () { - return function (dispatch) { - return dispatch({ type: 'CDM/COMPLETE/RESET' }); - } -} +export const resetCDMCompletion = () => (dispatch) => + dispatch({ type: 'CDM/COMPLETE/RESET' }) diff --git a/src/actions/uiAction.js b/src/actions/uiAction.js deleted file mode 100644 index e6d92653..00000000 --- a/src/actions/uiAction.js +++ /dev/null @@ -1,80 +0,0 @@ -/* -Copyright 2021-present Boba Network. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -export function setTheme (theme) { - return function (dispatch) { - return dispatch({ type: 'UI/THEME/UPDATE', payload: theme }); - } -} - -export function openModal (modal, token, fast, tokenIndex, lock, proposalId, selectionLayer, destNetworkSelection) { - return function (dispatch) { - return dispatch({ type: 'UI/MODAL/OPEN', payload: modal, token, fast, tokenIndex, lock, proposalId, selectionLayer, destNetworkSelection }); - } -} - -export function closeModal (modal) { - return function (dispatch) { - return dispatch({ type: 'UI/MODAL/CLOSE', payload: modal }); - } -} - -export function openAlert (message) { - return function (dispatch) { - return dispatch({ type: 'UI/ALERT/UPDATE', payload: message }); - } -} - -export function closeAlert () { - return function (dispatch) { - return dispatch({ type: 'UI/ALERT/UPDATE', payload: null }); - } -} - -export function openError (message) { - return function (dispatch) { - return dispatch({ type: 'UI/ERROR/UPDATE', payload: message }); - } -} - -export function closeError () { - return function (dispatch) { - return dispatch({ type: 'UI/ERROR/UPDATE', payload: null }); - } -} - -export function ledgerConnect (derivation) { - return function (dispatch) { - return dispatch({ type: 'UI/LEDGER/UPDATE', payload: derivation }); - } -} - -export function setActiveHistoryTab (tab) { - return function (dispatch) { - return dispatch({ type: 'UI/HISTORYTAB/UPDATE', payload: tab }); - } -} - -export function setActiveDataTab (tab) { - return function (dispatch) { - return dispatch({ type: 'UI/DATATAB/UPDATE', payload: tab }); - } -} - -export function setModalData (modal, data) { - return function (dispatch) { - return dispatch({ type: 'UI/MODAL/DATA', payload: { modal, data } }); - } -} diff --git a/src/actions/uiAction.ts b/src/actions/uiAction.ts new file mode 100644 index 00000000..df2a982b --- /dev/null +++ b/src/actions/uiAction.ts @@ -0,0 +1,56 @@ +/* +Copyright 2021-present Boba Network. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +export const setTheme = (theme) => (dispatch) => + dispatch({ type: 'UI/THEME/UPDATE', payload: theme }) + +export const openModal = + ( + modal?, + token?, + fast?, + tokenIndex?, + lock?, + proposalId?, + selectionLayer?, + destNetworkSelection? + ) => + (dispatch) => + dispatch({ + type: 'UI/MODAL/OPEN', + payload: modal, + token, + fast, + tokenIndex, + lock, + proposalId, + selectionLayer, + destNetworkSelection, + }) + +export const closeModal = (modal) => (dispatch) => + dispatch({ type: 'UI/MODAL/CLOSE', payload: modal }) + +export const openAlert = (message) => (dispatch) => + dispatch({ type: 'UI/ALERT/UPDATE', payload: message }) + +export const closeAlert = () => (dispatch) => + dispatch({ type: 'UI/ALERT/UPDATE', payload: null }) + +export const openError = (message) => (dispatch) => + dispatch({ type: 'UI/ERROR/UPDATE', payload: message }) + +export const closeError = () => (dispatch) => + dispatch({ type: 'UI/ERROR/UPDATE', payload: null }) diff --git a/src/actions/verifierAction.js b/src/actions/verifierAction.ts similarity index 68% rename from src/actions/verifierAction.js rename to src/actions/verifierAction.ts index a3c4509f..87f1f5e1 100644 --- a/src/actions/verifierAction.js +++ b/src/actions/verifierAction.ts @@ -14,14 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ import verifierService from 'services/verifier.service' -import {createAction} from './createAction' +import { createAction } from './createAction' -export function fetchVerifierStatus() { - return createAction('VERIFIER/GET',() => verifierService.getVerifierStatus()) -} +export const fetchVerifierStatus = () => + createAction('VERIFIER/GET', () => verifierService.getVerifierStatus()) -export function resetVerifierStatus() { - return function(dispatch) { - return dispatch({type: 'VERIFIER/RESET'}); - } -} +export const resetVerifierStatus = () => (dispatch) => + dispatch({ type: 'VERIFIER/RESET' }) diff --git a/src/api/coinGeckoAxios.js b/src/api/coinGeckoAxios.ts similarity index 100% rename from src/api/coinGeckoAxios.js rename to src/api/coinGeckoAxios.ts diff --git a/src/api/metaTransactionAxios.js b/src/api/metaTransactionAxios.ts similarity index 74% rename from src/api/metaTransactionAxios.js rename to src/api/metaTransactionAxios.ts index 9d6cfc23..a086e053 100644 --- a/src/api/metaTransactionAxios.js +++ b/src/api/metaTransactionAxios.ts @@ -1,9 +1,9 @@ import axios from 'axios' -export default function metaTransactionAxiosInstance(networkConfig) { +export default (networkConfig: any) => { const url = networkConfig['META_TRANSACTION'] - let axiosInstance = axios.create({ + const axiosInstance = axios.create({ baseURL: url, }) diff --git a/src/api/omgxWatcherAxios.js b/src/api/omgxWatcherAxios.js deleted file mode 100644 index 2255191c..00000000 --- a/src/api/omgxWatcherAxios.js +++ /dev/null @@ -1,17 +0,0 @@ -import axios from 'axios' - -export default function omgxWatcherAxiosInstance(networkConfig) { - const watcherUrl = networkConfig[ 'OMGX_WATCHER_URL' ] - - let axiosInstance = axios.create({ - baseURL: watcherUrl, - }) - - axiosInstance.interceptors.request.use((config) => { - config.headers[ 'Accept' ] = 'application/json' - config.headers[ 'Content-Type' ] = 'application/json' - return config - }) - - return axiosInstance -} diff --git a/src/api/omgxWatcherAxios.ts b/src/api/omgxWatcherAxios.ts new file mode 100644 index 00000000..f09736d3 --- /dev/null +++ b/src/api/omgxWatcherAxios.ts @@ -0,0 +1,17 @@ +import axios from 'axios' + +export default (networkConfig) => { + const watcherUrl = networkConfig['OMGX_WATCHER_URL'] + + const axiosInstance = axios.create({ + baseURL: watcherUrl, + }) + + axiosInstance.interceptors.request.use((config) => { + config.headers['Accept'] = 'application/json' + config.headers['Content-Type'] = 'application/json' + return config + }) + + return axiosInstance +} diff --git a/src/api/verifierWatcherAxios.js b/src/api/verifierWatcherAxios.js deleted file mode 100644 index f6df944d..00000000 --- a/src/api/verifierWatcherAxios.js +++ /dev/null @@ -1,21 +0,0 @@ -import axios from 'axios' - -export default function verifierWatcherAxiosInstance(networkConfig) { - const url = networkConfig[ 'VERIFIER_WATCHER_URL' ] - - if (!url) { - return null; - } - - let axiosInstance = axios.create({ - baseURL: url - }) - - axiosInstance.interceptors.request.use((config) => { - config.headers[ 'Accept' ] = 'application/json' - config.headers[ 'Content-Type' ] = 'application/json' - return config - }) - - return axiosInstance -} diff --git a/src/api/verifierWatcherAxios.ts b/src/api/verifierWatcherAxios.ts new file mode 100644 index 00000000..fdde639c --- /dev/null +++ b/src/api/verifierWatcherAxios.ts @@ -0,0 +1,21 @@ +import axios from 'axios' + +export default (networkConfig) => { + const url = networkConfig['VERIFIER_WATCHER_URL'] + + if (!url) { + return null + } + + const axiosInstance = axios.create({ + baseURL: url, + }) + + axiosInstance.interceptors.request.use((config) => { + config.headers['Accept'] = 'application/json' + config.headers['Content-Type'] = 'application/json' + return config + }) + + return axiosInstance +} diff --git a/src/components/bridge/ChainLabel/types.ts b/src/components/bridge/ChainLabel/types.ts index 526c2eea..bf86b283 100644 --- a/src/components/bridge/ChainLabel/types.ts +++ b/src/components/bridge/ChainLabel/types.ts @@ -5,7 +5,6 @@ export interface ChainLabelInterface { export type IconType = { ethereum: ({ selected }: { selected?: boolean | undefined }) => Element bnb: ({ selected }: { selected?: boolean | undefined }) => Element - avax: ({ selected }: { selected?: boolean | undefined }) => Element } export type DirectionType = { diff --git a/src/components/button/Button.js b/src/components/button/Button.tsx similarity index 85% rename from src/components/button/Button.js rename to src/components/button/Button.tsx index d8dcd6bb..e88a2f83 100644 --- a/src/components/button/Button.js +++ b/src/components/button/Button.tsx @@ -14,11 +14,25 @@ See the License for the specific language governing permissions and limitations under the License. */ import React from 'react' -import { CircularProgress } from '@mui/material' -import { Button as ButtonMUI } from '@mui/material' +import { CircularProgress, Button as ButtonMUI } from '@mui/material' import Tooltip from '../tooltip/Tooltip' -function Button({ +interface IButtonProps { + children + style + onClick + color + variant + fullWidth + disabled: boolean + loading: boolean + sx + tooltip: string + size + triggerTime: Date +} + +const Button = ({ children, style, onClick, @@ -28,14 +42,10 @@ function Button({ disabled, loading, sx, - pulsate, tooltip = '', size, - className, - triggerTime -}) { - if (disabled || loading) pulsate = false - + triggerTime, +}: IButtonProps) => { let timeDefined = false if (typeof triggerTime !== 'undefined') { timeDefined = true @@ -55,8 +65,11 @@ function Button({ } }, [loading]) + // @ts-ignore let waitTime = (now - triggerTime) / 1000 - if (waitTime < 0) waitTime = 0 + if (waitTime < 0) { + waitTime = 0 + } waitTime = Math.round(waitTime) const muiProps = { diff --git a/src/components/icons/AlertIcon.js b/src/components/icons/AlertIcon.js deleted file mode 100644 index 55aa4da5..00000000 --- a/src/components/icons/AlertIcon.js +++ /dev/null @@ -1,24 +0,0 @@ -import * as React from "react"; -import { useTheme } from "@mui/material/styles"; - -function AlertIcon() { - const theme = useTheme(); - const color = theme.palette.primary.alert; - return ( - - - - ); -} - -export default AlertIcon; - - diff --git a/src/components/icons/AlertIcon.tsx b/src/components/icons/AlertIcon.tsx new file mode 100644 index 00000000..befb2355 --- /dev/null +++ b/src/components/icons/AlertIcon.tsx @@ -0,0 +1,26 @@ +import * as React from 'react' +import { useTheme } from '@mui/material/styles' + +const AlertIcon = () => { + const theme = useTheme() + const color = (theme.palette.primary as any).alert + return ( + + + + ) +} + +export default AlertIcon diff --git a/src/components/icons/Boba2Icon.js b/src/components/icons/Boba2Icon.js deleted file mode 100644 index 364ded00..00000000 --- a/src/components/icons/Boba2Icon.js +++ /dev/null @@ -1,48 +0,0 @@ -import * as React from "react" -import { useTheme } from '@mui/material'; - -function Boba2Icon({ dark = false, selected = true }) { - - const theme = useTheme(); - - const recColor = theme.palette.mode === 'light' ? '#031313' : '#ffffff' - - if (!selected) { - return - - - - } - - if (theme.palette.mode === 'dark') { - return ( - - - - - - - - - - - - ) - } - - return ( - - - - - - - - - - - - ) -} - -export default Boba2Icon diff --git a/src/components/icons/Boba2Icon.tsx b/src/components/icons/Boba2Icon.tsx new file mode 100644 index 00000000..4aee8b66 --- /dev/null +++ b/src/components/icons/Boba2Icon.tsx @@ -0,0 +1,142 @@ +import * as React from 'react' +import { useTheme } from '@mui/material' + +const Boba2Icon = ({ selected = true }) => { + const theme = useTheme() + + const recColor = theme.palette.mode === 'light' ? '#031313' : '#ffffff' + + if (!selected) { + return ( + + + + + ) + } + + if (theme.palette.mode === 'dark') { + return ( + + + + + + + + + + + + ) + } + + return ( + + + + + + + + + + + + ) +} + +export default Boba2Icon diff --git a/src/components/icons/BobaGlassIcon.js b/src/components/icons/BobaGlassIcon.js deleted file mode 100644 index c94345f2..00000000 --- a/src/components/icons/BobaGlassIcon.js +++ /dev/null @@ -1,18 +0,0 @@ -import * as React from "react" - -function BobaGlassIcon() { - - return ( - - - - - - - - - - ) -} - -export default BobaGlassIcon diff --git a/src/components/icons/BobaGlassIcon.tsx b/src/components/icons/BobaGlassIcon.tsx new file mode 100644 index 00000000..af7cda01 --- /dev/null +++ b/src/components/icons/BobaGlassIcon.tsx @@ -0,0 +1,31 @@ +import * as React from 'react' + +const BobaGlassIcon = () => ( + + + + + + + + + +) + +export default BobaGlassIcon diff --git a/src/components/icons/BobaLogo.js b/src/components/icons/BobaLogo.js deleted file mode 100644 index 5fa24431..00000000 --- a/src/components/icons/BobaLogo.js +++ /dev/null @@ -1,21 +0,0 @@ -import * as React from "react" -import { useTheme } from '@mui/material'; -import { ReactComponent as LogoBoba2 } from 'assets/images/boba2/logo-boba2.svg'; -import {ReactComponent as LogoBoba2dark} from 'assets/images/boba2/logo-boba2-dark.svg'; - -function BobaLogo() { - - const theme = useTheme(); - - if (theme.palette.mode === 'dark') { - return ( - - ) - } - - return ( - - ) -} - -export default BobaLogo diff --git a/src/components/icons/BobaLogo.tsx b/src/components/icons/BobaLogo.tsx new file mode 100644 index 00000000..945e2c06 --- /dev/null +++ b/src/components/icons/BobaLogo.tsx @@ -0,0 +1,16 @@ +import * as React from 'react' +import { useTheme } from '@mui/material' +import { ReactComponent as LogoBoba2 } from 'assets/images/boba2/logo-boba2.svg' +import { ReactComponent as LogoBoba2dark } from 'assets/images/boba2/logo-boba2-dark.svg' + +const BobaLogo = () => { + const theme = useTheme() + + if (theme.palette.mode === 'dark') { + return + } + + return +} + +export default BobaLogo diff --git a/src/components/icons/CalenderIcon.js b/src/components/icons/CalenderIcon.js deleted file mode 100644 index 20cd086d..00000000 --- a/src/components/icons/CalenderIcon.js +++ /dev/null @@ -1,18 +0,0 @@ -import * as React from "react"; -import { useTheme } from "@mui/material/styles"; - -function CalenderIcon() { - const theme = useTheme(); - const isLight = theme.palette.mode === 'light'; - const color = theme.palette.common[ isLight ? 'black' : 'white' ]; - return ( - - - - ); -} - -export default CalenderIcon; diff --git a/src/components/icons/CalenderIcon.tsx b/src/components/icons/CalenderIcon.tsx new file mode 100644 index 00000000..f6cda775 --- /dev/null +++ b/src/components/icons/CalenderIcon.tsx @@ -0,0 +1,25 @@ +import * as React from 'react' +import { useTheme } from '@mui/material/styles' + +const CalenderIcon = () => { + const theme = useTheme() + const isLight = theme.palette.mode === 'light' + const color = theme.palette.common[isLight ? 'black' : 'white'] + return ( + + + + ) +} + +export default CalenderIcon diff --git a/src/components/icons/DarkIcon.js b/src/components/icons/DarkIcon.tsx similarity index 83% rename from src/components/icons/DarkIcon.js rename to src/components/icons/DarkIcon.tsx index 3192c88b..f34fd6b8 100644 --- a/src/components/icons/DarkIcon.js +++ b/src/components/icons/DarkIcon.tsx @@ -1,10 +1,10 @@ -import * as React from "react"; -import { useTheme } from "@mui/material/styles"; +import * as React from 'react' +import { useTheme } from '@mui/material/styles' -function DarkIcon() { - const theme = useTheme(); - const isLight = theme.palette.mode === 'light'; - const color = theme.palette.common[isLight ? 'black' : 'white']; +const DarkIcon = () => { + const theme = useTheme() + const isLight = theme.palette.mode === 'light' + const color = theme.palette.common[isLight ? 'black' : 'white'] return ( { + const theme = useTheme() + const isLight = theme.palette.mode === 'light' + const color = theme.palette.common[isLight ? 'black' : 'white'] return ( - - - - - ) -} - -export default SearchIcon diff --git a/src/components/icons/SearchIcon.tsx b/src/components/icons/SearchIcon.tsx new file mode 100644 index 00000000..2a7831f1 --- /dev/null +++ b/src/components/icons/SearchIcon.tsx @@ -0,0 +1,31 @@ +import * as React from 'react' + +const SearchIcon = ({ color }) => ( + + + + +) + +export default SearchIcon diff --git a/src/components/icons/chain/L1/AvalancheIcon.js b/src/components/icons/chain/L1/AvalancheIcon.js deleted file mode 100644 index 50a1f903..00000000 --- a/src/components/icons/chain/L1/AvalancheIcon.js +++ /dev/null @@ -1,11 +0,0 @@ -import * as React from "react" -import { getCoinImage } from "util/coinImage" - -function AvalancheIcon({ selected = false }) { - - return <> - avax icon - -} - -export default AvalancheIcon diff --git a/src/components/icons/chain/L1/AvalancheIcon.tsx b/src/components/icons/chain/L1/AvalancheIcon.tsx new file mode 100644 index 00000000..0a653b55 --- /dev/null +++ b/src/components/icons/chain/L1/AvalancheIcon.tsx @@ -0,0 +1,10 @@ +import * as React from 'react' +import { getCoinImage } from 'util/coinImage' + +const AvalancheIcon = ({ selected }) => ( + <> + avax icon + +) + +export default AvalancheIcon diff --git a/src/components/icons/chain/L1/BNBIcon.js b/src/components/icons/chain/L1/BNBIcon.js deleted file mode 100644 index 0667b3d4..00000000 --- a/src/components/icons/chain/L1/BNBIcon.js +++ /dev/null @@ -1,10 +0,0 @@ -import * as React from "react" -import { getCoinImage } from "util/coinImage" - -function BnbIcon({ selected = false }) { - return <> - bnb logo - -} - -export default BnbIcon diff --git a/src/components/icons/chain/L1/BNBIcon.tsx b/src/components/icons/chain/L1/BNBIcon.tsx new file mode 100644 index 00000000..ac15c2ce --- /dev/null +++ b/src/components/icons/chain/L1/BNBIcon.tsx @@ -0,0 +1,10 @@ +import * as React from 'react' +import { getCoinImage } from 'util/coinImage' + +const BnbIcon = ({ selected }) => ( + <> + bnb logo + +) + +export default BnbIcon diff --git a/src/components/icons/chain/L1/EthereumIcon.js b/src/components/icons/chain/L1/EthereumIcon.js deleted file mode 100644 index 1d13913f..00000000 --- a/src/components/icons/chain/L1/EthereumIcon.js +++ /dev/null @@ -1,18 +0,0 @@ -import * as React from "react" - -function EthereumIcon({ selected = false }) { - - - return - - - - - - - - - -} - -export default EthereumIcon diff --git a/src/components/icons/chain/L1/EthereumIcon.tsx b/src/components/icons/chain/L1/EthereumIcon.tsx new file mode 100644 index 00000000..a462308e --- /dev/null +++ b/src/components/icons/chain/L1/EthereumIcon.tsx @@ -0,0 +1,39 @@ +import * as React from 'react' + +const EthereumIcon = ({ selected }) => ( + + + + + + + + + +) + +export default EthereumIcon diff --git a/src/components/icons/chain/L2/BobaAvaxIcon.js b/src/components/icons/chain/L2/BobaAvaxIcon.js deleted file mode 100644 index 74b3fe17..00000000 --- a/src/components/icons/chain/L2/BobaAvaxIcon.js +++ /dev/null @@ -1,15 +0,0 @@ -import * as React from "react" - -function BobaAvaxIcon({ selected = false }) { - return - - - - - - - - -} - -export default BobaAvaxIcon diff --git a/src/components/icons/chain/L2/BobaAvaxIcon.tsx b/src/components/icons/chain/L2/BobaAvaxIcon.tsx new file mode 100644 index 00000000..b4e47892 --- /dev/null +++ b/src/components/icons/chain/L2/BobaAvaxIcon.tsx @@ -0,0 +1,37 @@ +import * as React from 'react' + +const BobaAvaxIcon = ({ selected }) => ( + + + + + + + + + +) + +export default BobaAvaxIcon diff --git a/src/components/icons/chain/L2/BobaBNBIcon.js b/src/components/icons/chain/L2/BobaBNBIcon.js deleted file mode 100644 index 466387d2..00000000 --- a/src/components/icons/chain/L2/BobaBNBIcon.js +++ /dev/null @@ -1,17 +0,0 @@ -import * as React from "react" - -function BobaBnbIcon({ selected = false }) { - - - return - - - - - - - - -} - -export default BobaBnbIcon diff --git a/src/components/icons/chain/L2/BobaBNBIcon.tsx b/src/components/icons/chain/L2/BobaBNBIcon.tsx new file mode 100644 index 00000000..0b517973 --- /dev/null +++ b/src/components/icons/chain/L2/BobaBNBIcon.tsx @@ -0,0 +1,29 @@ +import * as React from 'react' + +const BobaBnbIcon = ({ selected }) => ( + + + + + + + + +) + +export default BobaBnbIcon diff --git a/src/components/icons/chain/L2/BobaIcon.js b/src/components/icons/chain/L2/BobaIcon.js deleted file mode 100644 index 4eef9978..00000000 --- a/src/components/icons/chain/L2/BobaIcon.js +++ /dev/null @@ -1,22 +0,0 @@ -import * as React from "react" - -function BobaIcon({ selected = false }) { - - return - - - - - - - - - - - - - - -} - -export default BobaIcon diff --git a/src/components/icons/chain/L2/BobaIcon.tsx b/src/components/icons/chain/L2/BobaIcon.tsx new file mode 100644 index 00000000..dd016719 --- /dev/null +++ b/src/components/icons/chain/L2/BobaIcon.tsx @@ -0,0 +1,37 @@ +import * as React from 'react' + +const BobaIcon = ({ selected }) => ( + + + + + + + + + + + + + +) + +export default BobaIcon diff --git a/src/components/layout/Footer/FooterLinks/index.tsx b/src/components/layout/Footer/FooterLinks/index.tsx index f2bba9b4..8027e0f9 100644 --- a/src/components/layout/Footer/FooterLinks/index.tsx +++ b/src/components/layout/Footer/FooterLinks/index.tsx @@ -22,10 +22,6 @@ const blockExplorerLinks = { l1: `https://testnet.bscscan.com`, l2: `https://testnet.bobascan.com`, }, - [NETWORK.AVAX]: { - l1: `https://testnet.snowtrace.io`, - l2: `https://blockexplorer.testnet.avax.boba.network`, - }, }, [NETWORK_TYPE.MAINNET]: { [NETWORK.ETHEREUM]: { @@ -36,10 +32,6 @@ const blockExplorerLinks = { l1: `https://bscscan.com`, l2: `https://bobascan.com`, }, - [NETWORK.AVAX]: { - l1: `https://snowtrace.io/`, - l2: `https://blockexplorer.avax.boba.network`, - }, }, } @@ -99,14 +91,6 @@ const FooterLinks = () => { label: 'BNB Block Explorer L2', onClick: () => onLinkClick(NETWORK.BNB, 'l2'), }, - { - label: 'AVAX Block Explorer L1', - onClick: () => onLinkClick(NETWORK.AVAX, 'l1'), - }, - { - label: 'AVAX Block Explorer L2', - onClick: () => onLinkClick(NETWORK.AVAX, 'l2'), - }, ]} label="Block explorers" /> diff --git a/src/components/notificationBanner/bannerConfig.ts b/src/components/notificationBanner/bannerConfig.ts index 65052bd1..9cda8c37 100644 --- a/src/components/notificationBanner/bannerConfig.ts +++ b/src/components/notificationBanner/bannerConfig.ts @@ -20,9 +20,4 @@ interface BannerContent { * */ -export const BannerConfig: Record = { - [NETWORK.AVAX]: { - message: `BobaAvax (Fuji) is being wound down & will no longer be available, starting October 31st`, - content: `BobaAvax (Fuji) is being wound down & will no longer be available starting October 31st. For users of BobaAvax or BobaAvax applications you will need to transfer all your funds to Avalanche mainnet before October 31st or risk permanently losing access to any assets on BobaAvax.`, - }, -} +export const BannerConfig: Record = {} diff --git a/src/components/notificationBanner/index.tsx b/src/components/notificationBanner/index.tsx index 0f36ac65..95d47f6c 100644 --- a/src/components/notificationBanner/index.tsx +++ b/src/components/notificationBanner/index.tsx @@ -5,10 +5,6 @@ import { selectActiveNetwork } from 'selectors' import { useSelector } from 'react-redux' import { Typography } from 'components/global' -/* -// TODO: Depracate this once avax launch. -*/ - // @style const NotificationBannerContainer = styled('div')` max-height: 0; diff --git a/src/components/notificationBanner/tests/__snapshots__/index.test.tsx.snap b/src/components/notificationBanner/tests/__snapshots__/index.test.tsx.snap index 90612581..74c49395 100644 --- a/src/components/notificationBanner/tests/__snapshots__/index.test.tsx.snap +++ b/src/components/notificationBanner/tests/__snapshots__/index.test.tsx.snap @@ -9,7 +9,7 @@ exports[`NotificationBanner should match snapshot and check show banner when op class="sc-dAlyuH eGlSty sc-gFqAkR guazbW" data-testid="message" > - BobaAvax (Fuji) is being wound down & will no longer be available, starting October 31st + Banner message lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsum - BobaAvax (Fuji) is being wound down & will no longer be available, starting October 31st + Banner message lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsum ({ BannerConfig: { - AVAX: { - message: `BobaAvax (Fuji) is being wound down & will no longer be available, starting October 31st`, - content: `BobaAvax (Fuji) is being wound down & will no longer be available starting October 31st. For users of BobaAvax or BobaAvax applications you will need to transfer all your funds to Avalanche mainnet before October 31st or risk permanently losing access to any assets on BobaAvax.`, + ETHEREUM: { + message: `Banner message lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsum`, + content: `Banner message lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumBanner message lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumBanner message lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumBanner message lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumBanner message lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsum`, }, }, })) -const data = BannerConfig[NETWORK.AVAX] +const data = BannerConfig[NETWORK.ETHEREUM] const mockStore = configureStore() @@ -28,7 +28,7 @@ const renderBanner = (props: any) => { theme: 'dark', }, network: { - activeNetwork: NETWORK.AVAX, + activeNetwork: NETWORK.ETHEREUM, activeNetworkType: NETWORK_TYPE.MAINNET, }, })} diff --git a/src/containers/Bridging/chain/constant.ts b/src/containers/Bridging/chain/constant.ts index 6c36c2df..10f41c25 100644 --- a/src/containers/Bridging/chain/constant.ts +++ b/src/containers/Bridging/chain/constant.ts @@ -1,10 +1,8 @@ import { ElementType } from 'react' -import AvalancheIcon from 'components/icons/chain/L1/AvalancheIcon' import BNBIcon from 'components/icons/chain/L1/BNBIcon' import EthereumIcon from 'components/icons/chain/L1/EthereumIcon' -import BobaAvaxIcon from 'components/icons/chain/L2/BobaAvaxIcon' import BobaBNBIcon from 'components/icons/chain/L2/BobaBNBIcon' import BobaIcon from 'components/icons/chain/L2/BobaIcon' @@ -24,8 +22,4 @@ export const NETWORK_ICONS: NetworkIconsType = { L1: BNBIcon, L2: BobaBNBIcon, }, - avax: { - L1: AvalancheIcon, - L2: BobaAvaxIcon, - }, } diff --git a/src/containers/history/constants.ts b/src/containers/history/constants.ts index e7319578..b9948b23 100644 --- a/src/containers/history/constants.ts +++ b/src/containers/history/constants.ts @@ -8,7 +8,6 @@ import { CHAIN_NAME, ChainMap } from './types' import bobaEth from 'assets/bobaEth.svg' import bobaBnb from 'assets/bobaBNB.svg' -import bobaAvax from 'assets/bobaAvax.svg' import ethIcon from 'assets/ethereum.svg' @@ -67,30 +66,6 @@ export const Chains: ChainMap = { symbol: 'BOBA', imgSrc: bobaEth, }, - '43114': { - name: CHAIN_NAME.Avalanche, - transactionUrlPrefix: 'https://snowtrace.io/tx/', - symbol: 'AVAX', - imgSrc: getCoinImage('AVAX'), - }, - '43288': { - name: CHAIN_NAME.Boba_Avalanche, - transactionUrlPrefix: 'https://blockexplorer.avax.boba.network/tx/', - symbol: 'BOBA', - imgSrc: bobaAvax, - }, - '43113': { - name: CHAIN_NAME.Avalanche_Testnet, - transactionUrlPrefix: 'https://testnet.snowtrace.io/tx/', - symbol: 'AVAX', - imgSrc: getCoinImage('AVAX'), - }, - '4328': { - name: CHAIN_NAME.Boba_Avalanche_Testnet, - transactionUrlPrefix: 'https://blockexplorer.testnet.avax.boba.network/tx/', - symbol: 'BOBA', - imgSrc: bobaAvax, - }, } export const ALL_NETWORKS: IDropdownItem = { @@ -114,30 +89,12 @@ export const NETWORK_L1_OPTIONS: IDropdownItem[] = [ imgSrc: getCoinImage('BNB'), headerName: NETWORK_TYPE.MAINNET, }, - { - value: '43114', - label: 'AVAX', - imgSrc: getCoinImage('AVAX'), - headerName: NETWORK_TYPE.MAINNET, - }, { value: '5', label: 'Goerli', imgSrc: ethIcon, headerName: NETWORK_TYPE.TESTNET, }, - { - value: '97', - label: 'tBNB', - imgSrc: getCoinImage('BNB'), - headerName: NETWORK_TYPE.TESTNET, - }, - { - value: '43113', - label: 'Fuji', - imgSrc: getCoinImage('AVAX'), - headerName: NETWORK_TYPE.TESTNET, - }, ] export const NETWORK_L2_OPTIONS = [ @@ -154,12 +111,6 @@ export const NETWORK_L2_OPTIONS = [ imgSrc: bobaBnb, headerName: NETWORK_TYPE.MAINNET, }, - { - value: '43288', - label: 'Boba Avax', - imgSrc: bobaAvax, - headerName: NETWORK_TYPE.MAINNET, - }, { value: '2888', label: 'Boba Goerli', @@ -172,12 +123,6 @@ export const NETWORK_L2_OPTIONS = [ imgSrc: bobaBnb, headerName: NETWORK_TYPE.TESTNET, }, - { - value: '4328', - label: 'Boba Fuji', - imgSrc: bobaAvax, - headerName: NETWORK_TYPE.TESTNET, - }, ] export const FILTER_OPTIONS: IFilterDropdownItem[] = [ diff --git a/src/containers/history/tokenInfo.ts b/src/containers/history/tokenInfo.ts index 758e90f2..fba749e4 100644 --- a/src/containers/history/tokenInfo.ts +++ b/src/containers/history/tokenInfo.ts @@ -452,132 +452,4 @@ export const TokenInfo: TokenInfoMap = { decimals: 18, }, }, - '43114': { - '0x0000000000000000000000000000000000000000': { - name: 'Avalanche', - symbol: 'AVAX', - decimals: 18, - }, - '0x3cD790449CF7D187a143d4Bd7F4654d4f2403e02': { - name: 'BOBA Token', - symbol: 'BOBA', - decimals: 18, - }, - '0x42006Ab57701251B580bDFc24778C43c9ff589A1': { - name: 'EVO', - symbol: 'EVO', - decimals: 18, - }, - '0xc7198437980c041c805A1EDcbA50c1Ce5db95118': { - name: 'Tether USD', - symbol: 'USDT.e', - decimals: 6, - }, - '0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7': { - name: 'TetherToken', - symbol: 'USDt', - decimals: 6, - }, - '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E': { - name: 'USD Coin', - symbol: 'USDC', - decimals: 6, - }, - '0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664': { - name: 'USD Coin', - symbol: 'USDC.e', - decimals: 6, - }, - '0x19860CCB0A68fd4213aB9D8266F7bBf05A8dDe98': { - name: 'Binance USD', - symbol: 'BUSD.e', - decimals: 18, - }, - '0x9C9e5fD8bbc25984B178FdCE6117Defa39d2db39': { - name: 'BUSD Token', - symbol: 'BUSD', - decimals: 18, - }, - '0xd586E7F844cEa2F87f50152665BCbc2C279D8d70': { - name: 'Dai Stablecoin', - symbol: 'DAI.e', - decimals: 18, - }, - }, - '43288': { - '0x4200000000000000000000000000000000000006': { - name: 'BOBA Token', - symbol: 'BOBA', - decimals: 18, - }, - '0xc8849f32138de93F6097199C5721a9EfD91ceE01': { - name: 'EVO', - symbol: 'EVO', - decimals: 18, - }, - '0x4ED96c1dc969d7E2310D9582A68c39556C005912': { - name: 'Tether USD', - symbol: 'USDT.e', - decimals: 6, - }, - '0xfaA13D82756f1e0e4dec9416b83121db3Fc35199': { - name: 'TetherToken', - symbol: 'USDt', - decimals: 6, - }, - '0x12bb1A120dcF8Cb7152eDAC9f04d176DD7f41F7e': { - name: 'USD Coin', - symbol: 'USDC', - decimals: 6, - }, - '0x126969743a6d300bab08F303f104f0f7DBAfbe20': { - name: 'USD Coin', - symbol: 'USDC.e', - decimals: 6, - }, - '0xb8B0034CFD89925944C07Ac6CcB2834d1774cfb6': { - name: 'Binance USD', - symbol: 'BUSD.e', - decimals: 18, - }, - '0x87e062dE99Ed71aF9b22dDA63e1b6D43333798f8': { - name: 'BUSD Token', - symbol: 'BUSD', - decimals: 18, - }, - '0x69B7d24f0E03Ff21949081C95dA7288fEa5C844D': { - name: 'Dai Stablecoin', - symbol: 'DAI.e', - decimals: 18, - }, - '0x4200000000000000000000000000000000000023': { - name: 'Avalanche', - symbol: 'AVAX', - decimals: 18, - }, - }, - '43113': { - '0x0000000000000000000000000000000000000000': { - name: 'Avalanche', - symbol: 'AVAX', - decimals: 18, - }, - '0xEaE78E78cC22690719361F65a50734A15aaE698C': { - name: 'BOBA Token', - symbol: 'BOBA', - decimals: 18, - }, - }, - '4328': { - '0x4200000000000000000000000000000000000006': { - name: 'BOBA Token', - symbol: 'BOBA', - decimals: 18, - }, - '0x4200000000000000000000000000000000000023': { - name: 'Avalanche', - symbol: 'AVAX', - decimals: 18, - }, - }, } diff --git a/src/containers/history/types.ts b/src/containers/history/types.ts index d9778122..74bf7c42 100644 --- a/src/containers/history/types.ts +++ b/src/containers/history/types.ts @@ -26,10 +26,6 @@ export enum CHAIN_NAME { Boba_Ethereum = 'Boba Ethereum', Goerli = 'Goerli', Boba_Goerli = 'Boba Goerli', - Avalanche = 'Avax', - Boba_Avalanche = 'Boba Avax', - Avalanche_Testnet = 'Fuji', - Boba_Avalanche_Testnet = 'Boba Fuji', } export enum LAYER { diff --git a/src/containers/modals/walletSelector/WalletSelectorModal.js b/src/containers/modals/walletSelector/WalletSelectorModal.js index d0582a09..b46be5ae 100644 --- a/src/containers/modals/walletSelector/WalletSelectorModal.js +++ b/src/containers/modals/walletSelector/WalletSelectorModal.js @@ -6,7 +6,8 @@ import { closeModal } from 'actions/uiAction' import { setConnectBOBA, setConnectETH, -} from 'actions/setupAction.js' + setConnect +} from 'actions/setupAction' import Modal from 'components/modal/Modal' import { Typography } from 'components/global/typography' @@ -19,7 +20,6 @@ import ArrowIcon from 'assets/images/icons/arrowright.svg' import { Wallets, Wallet, Icon, ArrowContainer, IconContainer } from './styles' import { useWalletConnect } from 'hooks/useWalletConnect' -import { setConnect } from 'actions/setupAction' import styled from 'styled-components' const StyledSvg = styled(Svg)` diff --git a/src/hooks/useAmountToReceive/index.test.tsx b/src/hooks/useAmountToReceive/index.test.tsx new file mode 100644 index 00000000..7f572344 --- /dev/null +++ b/src/hooks/useAmountToReceive/index.test.tsx @@ -0,0 +1,212 @@ +import React from 'react' +import { renderHook, act } from '@testing-library/react-hooks' +import { useAmountToReceive } from './' +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import { mockedInitialState } from 'util/tests' +import { Provider } from 'react-redux' +import { BRIDGE_TYPE } from 'containers/Bridging/BridgeTypeSelector' +import { LAYER } from 'util/constant' + +describe('useAmountToReceive', () => { + const middlewares = [thunk] + const mockStore = configureMockStore(middlewares) + + test('Should return undefined if token is not defined', async () => { + const initialState = { + ...mockedInitialState, + balance: { + ...mockedInitialState.balance, + l1FeeRateN: 1, + l2FeeRateN: 2, + }, + bridge: { + ...mockedInitialState.bridge, + tokens: null, + amountToBridge: 1, + bridgeType: BRIDGE_TYPE.CLASSIC, + }, + } + const store = mockStore(initialState) + + const wrapper = ({ children }) => ( + {children} + ) + const { result } = renderHook(() => useAmountToReceive(), { + wrapper, + }) + expect(result.current.amount).toBe('0 undefined') + }) + + test('Should calculate the amount to receive correctly for L1 Classic Bridge', async () => { + const initialState = { + ...mockedInitialState, + balance: { + ...mockedInitialState.balance, + l1FeeRateN: 1, + l2FeeRateN: 2, + }, + bridge: { + ...mockedInitialState.bridge, + amountToBridge: 1, + bridgeType: BRIDGE_TYPE.CLASSIC, + }, + } + const store = mockStore(initialState) + + const wrapper = ({ children }) => ( + {children} + ) + const { result } = renderHook(() => useAmountToReceive(), { + wrapper, + }) + + expect(result.current.amount).toBe('1.0000 ETH') + }) + + test('Should calculate the amount to receive correctly for L1 Fast Bridge', async () => { + const initialState = { + ...mockedInitialState, + balance: { + ...mockedInitialState.balance, + l1FeeRateN: 1, + l2FeeRateN: 2, + }, + bridge: { + ...mockedInitialState.bridge, + amountToBridge: 1, + bridgeType: BRIDGE_TYPE.FAST, + }, + } + const store = mockStore(initialState) + + const wrapper = ({ children }) => ( + {children} + ) + const { result } = renderHook(() => useAmountToReceive(), { + wrapper, + }) + + expect(result.current.amount).toBe('0.980 ETH') + }) + + test('Should calculate the amount to receive correctly for L1 Light Bridge', async () => { + const initialState = { + ...mockedInitialState, + balance: { + ...mockedInitialState.balance, + l1FeeRateN: 1, + l2FeeRateN: 2, + }, + setup: { + ...mockedInitialState, + netLayer: LAYER.L1, + }, + bridge: { + ...mockedInitialState.bridge, + amountToBridge: 1, + bridgeType: BRIDGE_TYPE.LIGHT, + }, + } + const store = mockStore(initialState) + + const wrapper = ({ children }) => ( + {children} + ) + const { result } = renderHook(() => useAmountToReceive(), { + wrapper, + }) + + expect(result.current.amount).toBe('1 ETH') + }) + + test('Should calculate the amount to receive correctly for L2 Classic Bridge', async () => { + const initialState = { + ...mockedInitialState, + balance: { + ...mockedInitialState.balance, + l1FeeRateN: 1, + l2FeeRateN: 2, + }, + setup: { + ...mockedInitialState, + netLayer: LAYER.L2, + }, + bridge: { + ...mockedInitialState.bridge, + amountToBridge: 1, + bridgeType: BRIDGE_TYPE.CLASSIC, + }, + } + const store = mockStore(initialState) + + const wrapper = ({ children }) => ( + {children} + ) + const { result } = renderHook(() => useAmountToReceive(), { + wrapper, + }) + + expect(result.current.amount).toBe('1.0000 ETH') + }) + + test('Should calculate the amount to receive correctly for L2 Fast Bridge', async () => { + const initialState = { + ...mockedInitialState, + balance: { + ...mockedInitialState.balance, + l1FeeRateN: 1, + l2FeeRateN: 2, + }, + setup: { + ...mockedInitialState, + netLayer: LAYER.L2, + }, + bridge: { + ...mockedInitialState.bridge, + amountToBridge: 1, + bridgeType: BRIDGE_TYPE.FAST, + }, + } + const store = mockStore(initialState) + + const wrapper = ({ children }) => ( + {children} + ) + const { result } = renderHook(() => useAmountToReceive(), { + wrapper, + }) + + expect(result.current.amount).toBe('0.990 ETH') + }) + + test('Should calculate the amount to receive correctly for L2 LIGHT Bridge', async () => { + const initialState = { + ...mockedInitialState, + balance: { + ...mockedInitialState.balance, + l1FeeRateN: 1, + l2FeeRateN: 2, + }, + setup: { + ...mockedInitialState, + netLayer: LAYER.L2, + }, + bridge: { + ...mockedInitialState.bridge, + amountToBridge: 1, + bridgeType: BRIDGE_TYPE.LIGHT, + }, + } + const store = mockStore(initialState) + + const wrapper = ({ children }) => ( + {children} + ) + const { result } = renderHook(() => useAmountToReceive(), { + wrapper, + }) + + expect(result.current.amount).toBe('1 ETH') + }) +}) diff --git a/src/hooks/useAmountToReceive.ts b/src/hooks/useAmountToReceive/index.ts similarity index 100% rename from src/hooks/useAmountToReceive.ts rename to src/hooks/useAmountToReceive/index.ts diff --git a/src/hooks/useBridge/index.ts b/src/hooks/useBridge/index.ts index 63b8625b..c56341b6 100644 --- a/src/hooks/useBridge/index.ts +++ b/src/hooks/useBridge/index.ts @@ -4,7 +4,7 @@ import { depositETHL2, depositL1LP, depositL2LP, - depositWithTeleporter, + depositWithLightBridge, exitBOBA, } from 'actions/networkAction' import { closeModal, openError, openModal } from 'actions/uiAction' @@ -129,7 +129,7 @@ export const useBridge = () => { } } return dispatch( - depositWithTeleporter(layer, token.address, amountWei, destChainId) + depositWithLightBridge(layer, token.address, amountWei, destChainId) ) } diff --git a/src/hooks/useBridgeAlerts.ts b/src/hooks/useBridgeAlerts.ts index f320f4ef..870179cf 100644 --- a/src/hooks/useBridgeAlerts.ts +++ b/src/hooks/useBridgeAlerts.ts @@ -447,20 +447,6 @@ const useBridgeAlerts = () => { fastDepositCost, ]) - useEffect(() => { - if (activeNetwork === NETWORK.AVAX && layer === LAYER.L1) { - dispatch( - setBridgeAlert({ - meta: ALERT_KEYS.DEPRECATION_WARNING, - text: `For users of BobaAvax (Fuji) or BobaAvax (Fuji) applications - you will need to transfer all your funds to Avalanche mainnet before October 31st - or risk permanently losing access to any assets on BobaAvax (Fuji)`, - type: 'warning', - }) - ) - } - }, [activeNetwork, layer]) - // on changing bridgeType and active network cleanup alerts useEffect(() => { dispatch(purgeBridgeAlert()) diff --git a/src/hooks/useOnboard.ts b/src/hooks/useOnboard.ts deleted file mode 100644 index 259021fa..00000000 --- a/src/hooks/useOnboard.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { setBaseState } from 'actions/setupAction' -import { useEffect } from 'react' -import { useDispatch, useSelector } from 'react-redux' -import { - selectActiveNetwork, - selectActiveNetworkType, - selectBaseEnabled, -} from 'selectors' -import networkService from 'services/networkService' - -export const useOnboard = () => { - const dispatch = useDispatch() - - const activeNetwork = useSelector(selectActiveNetwork()) - const activeNetworkType = useSelector(selectActiveNetworkType()) - const baseEnabled = useSelector(selectBaseEnabled()) - - useEffect(() => { - window.scrollTo(0, 0) - const initBase = async () => { - const initialized = await networkService.initializeBase({ - networkGateway: activeNetwork, - networkType: activeNetworkType, - }) - - if (!initialized) { - dispatch(setBaseState(false)) - } - - if (initialized === 'enabled') { - dispatch(setBaseState(true)) - } - } - - if (!baseEnabled) { - initBase() - } - }, [dispatch, activeNetwork, activeNetworkType, baseEnabled]) -} diff --git a/src/hooks/useSwitchChain/index.test.tsx b/src/hooks/useSwitchChain/index.test.tsx new file mode 100644 index 00000000..11c46ca6 --- /dev/null +++ b/src/hooks/useSwitchChain/index.test.tsx @@ -0,0 +1,177 @@ +import React from 'react' +import { renderHook, act } from '@testing-library/react-hooks' +import useNetwork from '.' +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import { mockedInitialState } from 'util/tests' +import { Provider } from 'react-redux' +import { LAYER } from 'util/constant' +import { BRIDGE_TYPE } from 'containers/Bridging/BridgeTypeSelector' + +describe('useSwitchChain', () => { + const middlewares = [thunk] + const mockStore = configureMockStore(middlewares) + + let originalConsoleWarn + let consoleOutput + + beforeAll(() => { + originalConsoleWarn = console.warn + console.warn = (message) => { + if (consoleOutput === undefined) { + consoleOutput = [] + } + consoleOutput.push(message) + } + }) + + test('If account is not enable should open walletSelectorModal', async () => { + const initialState = { + ...mockedInitialState, + setup: { + ...mockedInitialState.setup, + accountEnabled: null, + }, + } + const store = mockStore(initialState) + const wrapper = ({ children }) => ( + {children} + ) + + const { result } = renderHook(() => useNetwork(), { + wrapper, + }) + + result.current.switchChain() + + const actions = store.getActions() + expect(actions).toContainEqual({ + type: 'UI/MODAL/OPEN', + payload: 'walletSelectorModal', + }) + }) + + test('if account enabled && layer is L2 , should connect to L1', async () => { + const initialState = { + ...mockedInitialState, + setup: { + ...mockedInitialState.setup, + accountEnabled: true, + netLayer: LAYER.L2, + }, + } + const store = mockStore(initialState) + const wrapper = ({ children }) => ( + {children} + ) + + const { result } = renderHook(() => useNetwork(), { + wrapper, + }) + + result.current.switchChain() + + const actions = store.getActions() + expect(actions).toContainEqual({ + type: 'SETUP/CONNECT_ETH', + payload: true, + }) + }) + + test('if account enabled && layer is L1 , should connect to L2', async () => { + const initialState = { + ...mockedInitialState, + setup: { + ...mockedInitialState.setup, + accountEnabled: true, + netLayer: LAYER.L1, + }, + } + const store = mockStore(initialState) + const wrapper = ({ children }) => ( + {children} + ) + + const { result } = renderHook(() => useNetwork(), { + wrapper, + }) + + result.current.switchChain() + + const actions = store.getActions() + expect(actions).toContainEqual({ + type: 'SETUP/CONNECT_BOBA', + payload: true, + }) + }) + + test('if account enabled && bridgeType is Light should SetNetwork', async () => { + const initialState = { + ...mockedInitialState, + bridge: { + ...mockedInitialState.bridge, + destChainIdTeleportation: 1, + bridgeType: BRIDGE_TYPE.LIGHT, + }, + setup: { + ...mockedInitialState.setup, + accountEnabled: true, + netLayer: LAYER.L1, + }, + } + const store = mockStore(initialState) + const wrapper = ({ children }) => ( + {children} + ) + + const { result } = renderHook(() => useNetwork(), { + wrapper, + }) + + result.current.switchChain() + + const actions = store.getActions() + expect(actions).toContainEqual({ + payload: { + chainIds: 1, + name: 'Ethereum', + network: 'ETHEREUM', + networkIcon: 'ethereum', + networkType: 'Mainnet', + }, + type: 'NETWORK/SET', + }) + expect(actions).toContainEqual({ + payload: '1', + type: 'BRIDGE/TELEPORTER/DEST_CHAIN_ID', + }) + }) + + test('if account enabled && bridgeType is Light && unsuported network', async () => { + const initialState = { + ...mockedInitialState, + bridge: { + ...mockedInitialState.bridge, + bridgeType: BRIDGE_TYPE.LIGHT, + }, + setup: { + ...mockedInitialState.setup, + accountEnabled: true, + netLayer: LAYER.L1, + }, + } + const consoleWarnSpy = jest.spyOn(console, 'warn') + + const store = mockStore(initialState) + const wrapper = ({ children }) => ( + {children} + ) + + const { result } = renderHook(() => useNetwork(), { + wrapper, + }) + + result.current.switchChain() + expect(consoleOutput).toEqual(['Unknown destination chain id: ']) + }) +}) diff --git a/src/hooks/useSwitchChain.ts b/src/hooks/useSwitchChain/index.ts similarity index 89% rename from src/hooks/useSwitchChain.ts rename to src/hooks/useSwitchChain/index.ts index f39e8189..9f690a11 100644 --- a/src/hooks/useSwitchChain.ts +++ b/src/hooks/useSwitchChain/index.ts @@ -15,14 +15,10 @@ import { selectLayer, } from 'selectors' import { Layer, LAYER } from 'util/constant' -import { BRIDGE_TYPE } from '../containers/Bridging/BridgeTypeSelector' -import { setNetwork } from '../actions/networkAction' -import { - CHAIN_ID_LIST, - INetwork, - NetworkList, -} from '../util/network/network.util' -import { setTeleportationDestChainId } from '../actions/bridgeAction' +import { BRIDGE_TYPE } from 'containers/Bridging/BridgeTypeSelector' +import { setNetwork } from 'actions/networkAction' +import { CHAIN_ID_LIST, INetwork, NetworkList } from 'util/network/network.util' +import { setTeleportationDestChainId } from 'actions/bridgeAction' const useSwitchChain = () => { const dispatch = useDispatch() diff --git a/src/hooks/useThemeSwitcher/index.test.tsx b/src/hooks/useThemeSwitcher/index.test.tsx new file mode 100644 index 00000000..a6eb3f25 --- /dev/null +++ b/src/hooks/useThemeSwitcher/index.test.tsx @@ -0,0 +1,57 @@ +import React from 'react' +import { renderHook, act } from '@testing-library/react-hooks' +import configureMockStore from 'redux-mock-store' +import { Provider } from 'react-redux' +import thunk from 'redux-thunk' +import useThemeSwitcher from './' +import { THEME_NAME } from 'components/layout/Header/types' +import { mockedInitialState } from 'util/tests' +import { AnyAction } from 'redux' + +const middlewares = [thunk] +const mockStore = configureMockStore(middlewares) + +describe('useThemeSwitcher', () => { + it('Light version has to be update', () => { + const store = mockStore(mockedInitialState) + const wrapper = ({ children }) => ( + {children} + ) + const { result } = renderHook(() => useThemeSwitcher(), { + wrapper, + }) + + act(() => { + result.current.setThemeLight() + }) + + expect(localStorage.getItem('theme')).toBe(THEME_NAME.LIGHT) + + const actions: AnyAction[] = store.getActions() + expect(actions).toContainEqual({ + type: 'UI/THEME/UPDATE', + payload: THEME_NAME.LIGHT, + }) + }) + + it('Dark version has to be update', () => { + const store = mockStore(mockedInitialState) + const wrapper = ({ children }) => ( + {children} + ) + const { result } = renderHook(() => useThemeSwitcher(), { + wrapper, + }) + + act(() => { + result.current.setThemeDark() + }) + + expect(localStorage.getItem('theme')).toBe(THEME_NAME.DARK) + const actions: AnyAction[] = store.getActions() + expect(actions).toContainEqual({ + type: 'UI/THEME/UPDATE', + payload: THEME_NAME.DARK, + }) + }) +}) diff --git a/src/hooks/useThemeSwitcher.ts b/src/hooks/useThemeSwitcher/index.ts similarity index 100% rename from src/hooks/useThemeSwitcher.ts rename to src/hooks/useThemeSwitcher/index.ts diff --git a/src/hooks/useWalletSwitch/index.test.tsx b/src/hooks/useWalletSwitch/index.test.tsx new file mode 100644 index 00000000..12d4c426 --- /dev/null +++ b/src/hooks/useWalletSwitch/index.test.tsx @@ -0,0 +1,289 @@ +import React from 'react' +import { renderHook, act } from '@testing-library/react-hooks' +import useWalletSwitch from '.' +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import { mockedInitialState } from 'util/tests' +import { Provider } from 'react-redux' +import { LAYER } from 'util/constant' + +describe('useWalletSwitch', () => { + const middlewares = [thunk] + const mockStore = configureMockStore(middlewares) + + describe('When accountEnabled is falsy', () => { + test('Should set baseState, activenetwork, enableAccount when activeNetwork changes', async () => { + const store = mockStore({ + ...mockedInitialState, + network: { + ...mockedInitialState.network, + network: 'BNB', + networkIcon: 'bnb', + networkType: 'Mainnet', + name: {}, + }, + }) + const wrapper = ({ children }) => ( + {children} + ) + + renderHook(() => useWalletSwitch(), { + wrapper, + }) + + const actions = store.getActions() + + expect(actions).toEqual([ + { type: 'NETWORK/SET/ACTIVE' }, + { payload: false, type: 'SETUP/BASE/SET' }, + { payload: false, type: 'SETUP/ACCOUNT/SET' }, + ]) + }) + test('Should set baseState, activenetwork, enableAccount when activeNetworkType changes', async () => { + const store = mockStore({ + ...mockedInitialState, + network: { + ...mockedInitialState.network, + network: 'ETHEREUM', + networkIcon: 'ethereum', + networkType: 'Testnet', + name: {}, + }, + }) + const wrapper = ({ children }) => ( + {children} + ) + + renderHook(() => useWalletSwitch(), { + wrapper, + }) + + const actions = store.getActions() + + expect(actions).toEqual([ + { type: 'NETWORK/SET/ACTIVE' }, + { payload: false, type: 'SETUP/BASE/SET' }, + { payload: false, type: 'SETUP/ACCOUNT/SET' }, + ]) + }) + test('Should not update state when activeNetwork/activeNetworkType not changes', async () => { + const store = mockStore({ + ...mockedInitialState, + network: { + ...mockedInitialState.network, + network: 'ETHEREUM', + networkIcon: 'ethereum', + networkType: 'Mainnet', + name: {}, + }, + }) + const wrapper = ({ children }) => ( + {children} + ) + renderHook(() => useWalletSwitch(), { + wrapper, + }) + const actions = store.getActions() + expect(actions).toEqual([]) + }) + }) + describe('When accountEnabled is truthy', () => { + test('Should open switchNetworkModal when activeNetwork changes', async () => { + const store = mockStore({ + ...mockedInitialState, + setup: { + ...mockedInitialState.setup, + accountEnabled: true, + }, + network: { + ...mockedInitialState.network, + network: 'BNB', + networkIcon: 'bnb', + networkType: 'Mainnet', + name: {}, + }, + }) + const wrapper = ({ children }) => ( + {children} + ) + + renderHook(() => useWalletSwitch(), { + wrapper, + }) + + const actions = store.getActions() + + expect(actions).toEqual([ + { + destNetworkSelection: undefined, + fast: undefined, + lock: undefined, + payload: 'switchNetworkModal', + proposalId: undefined, + selectionLayer: undefined, + token: undefined, + tokenIndex: undefined, + type: 'UI/MODAL/OPEN', + }, + ]) + }) + test('Should open switchNetworkModal when activeNetworkType changes', async () => { + const store = mockStore({ + ...mockedInitialState, + setup: { + ...mockedInitialState.setup, + accountEnabled: true, + }, + network: { + ...mockedInitialState.network, + network: 'ETHEREUM', + networkIcon: 'ethereum', + networkType: 'Testnet', + name: {}, + }, + }) + const wrapper = ({ children }) => ( + {children} + ) + + renderHook(() => useWalletSwitch(), { + wrapper, + }) + + const actions = store.getActions() + + expect(actions).toEqual([ + { + destNetworkSelection: undefined, + fast: undefined, + lock: undefined, + payload: 'switchNetworkModal', + proposalId: undefined, + selectionLayer: undefined, + token: undefined, + tokenIndex: undefined, + type: 'UI/MODAL/OPEN', + }, + ]) + }) + test('Should not update state when activeNetwork / activeNetworkType not changed', async () => { + const store = mockStore({ + ...mockedInitialState, + setup: { + ...mockedInitialState.setup, + accountEnabled: true, + }, + network: { + ...mockedInitialState.network, + network: 'ETHEREUM', + networkIcon: 'ethereum', + networkType: 'Mainnet', + name: {}, + }, + }) + const wrapper = ({ children }) => ( + {children} + ) + renderHook(() => useWalletSwitch(), { + wrapper, + }) + const actions = store.getActions() + expect(actions).toEqual([]) + }) + }) + + describe('Should trigger connect when base enabled & reconnect', () => { + test('should dispatch connectETH on layer L1', async () => { + const setReconnectMock = jest.fn() + const useStateMock = jest.spyOn(React, 'useState') + useStateMock.mockImplementation(() => [true, setReconnectMock]) + + const initialState = { + ...mockedInitialState, + setup: { + ...mockedInitialState.setup, + baseEnabled: true, + }, + } + + const store = mockStore(initialState) + const wrapper = ({ children }) => ( + {children} + ) + + renderHook(() => useWalletSwitch(), { + wrapper, + }) + + const actions = store.getActions() + expect(actions).toEqual([ + { payload: true, type: 'SETUP/CONNECT_ETH' }, + { type: 'NETWORK/SET/ACTIVE' }, + { payload: false, type: 'SETUP/BASE/SET' }, + { payload: false, type: 'SETUP/ACCOUNT/SET' }, + ]) + }) + test('should dispatch connectBOBA on layer L2', async () => { + const setReconnectMock = jest.fn() + const useStateMock = jest.spyOn(React, 'useState') + useStateMock.mockImplementation(() => [true, setReconnectMock]) + + const initialState = { + ...mockedInitialState, + setup: { + ...mockedInitialState.setup, + netLayer: 'L2', + baseEnabled: true, + }, + } + + const store = mockStore(initialState) + const wrapper = ({ children }) => ( + {children} + ) + + renderHook(() => useWalletSwitch(), { + wrapper, + }) + + const actions = store.getActions() + expect(actions).toEqual([ + { payload: true, type: 'SETUP/CONNECT_BOBA' }, + { type: 'NETWORK/SET/ACTIVE' }, + { payload: false, type: 'SETUP/BASE/SET' }, + { payload: false, type: 'SETUP/ACCOUNT/SET' }, + ]) + }) + test('should dispatch connect on layer is not L1 or L2', async () => { + const setReconnectMock = jest.fn() + const useStateMock = jest.spyOn(React, 'useState') + useStateMock.mockImplementation(() => [true, setReconnectMock]) + + const initialState = { + ...mockedInitialState, + setup: { + ...mockedInitialState.setup, + netLayer: null, + baseEnabled: true, + }, + } + + const store = mockStore(initialState) + const wrapper = ({ children }) => ( + {children} + ) + + renderHook(() => useWalletSwitch(), { + wrapper, + }) + + const actions = store.getActions() + expect(actions).toEqual([ + { payload: true, type: 'SETUP/CONNECT' }, + { type: 'NETWORK/SET/ACTIVE' }, + { payload: false, type: 'SETUP/BASE/SET' }, + { payload: false, type: 'SETUP/ACCOUNT/SET' }, + ]) + }) + }) +}) diff --git a/src/hooks/useWalletSwitch.ts b/src/hooks/useWalletSwitch/index.ts similarity index 100% rename from src/hooks/useWalletSwitch.ts rename to src/hooks/useWalletSwitch/index.ts diff --git a/src/reducers/networkReducer.js b/src/reducers/networkReducer.js index 015d41de..a1953581 100644 --- a/src/reducers/networkReducer.js +++ b/src/reducers/networkReducer.js @@ -16,7 +16,7 @@ limitations under the License. */ import { NETWORK, NETWORK_TYPE } from "util/network/network.util" /** - * network : ethereum, bnb, avax + * network : ethereum, bnb * networkType : mainnet, testnet. **/ diff --git a/src/selectors/bridgeSelector.js b/src/selectors/bridgeSelector.js index ef7cf4a1..45a0dbbb 100644 --- a/src/selectors/bridgeSelector.js +++ b/src/selectors/bridgeSelector.js @@ -21,7 +21,7 @@ export function selectBridgeTokens() { export function selectTokenToBridge() { return function (state) { - return state.bridge.tokens[ 0 ] + return state.bridge.tokens?.[ 0 ] } } diff --git a/src/services/app.service.js b/src/services/app.service.js index b3a0377d..0b119649 100644 --- a/src/services/app.service.js +++ b/src/services/app.service.js @@ -2,12 +2,10 @@ import {NETWORK, NETWORK_TYPE} from "../util/network/network.util"; // testnet addresss import addresses_Goerli from "@bobanetwork/register/addresses/addressesGoerli_0x6FF9c8FF8F0B6a0763a3030540c21aFC721A9148" -import addresses_BobaFuji from "@bobanetwork/register/addresses/addressBobaFuji_0xcE78de95b85212BC348452e91e0e74c17cf37c79" import addresses_BobaBnbTestnet from "@bobanetwork/register/addresses/addressBobaBnbTestnet_0xAee1fb3f4353a9060aEC3943fE932b6Efe35CdAa" // mainnet address import addresses_Mainnet from "@bobanetwork/register/addresses/addressesMainnet_0x8376ac6C3f73a25Dd994E0b0669ca7ee0C02F089" -import addresses_BobaAvax from "@bobanetwork/register/addresses/addressBobaAvax_0x00220f8ce1c4be8436574e575fE38558d85e2E6b" import addresses_BobaBnb from "@bobanetwork/register/addresses/addressBobaBnb_0xeb989B25597259cfa51Bd396cE1d4B085EC4c753" // layerzero addresses. @@ -33,12 +31,6 @@ const ADDRESS_CONFIG = { ...layerZeroMainnet.Layer_Zero_Protocol.Mainnet, layerZeroTargetChainID: layerZeroMainnet.Layer_Zero_Protocol.Mainnet.Layer_Zero_ChainId, }, - [ NETWORK.AVAX ]: { - ...addresses_BobaAvax, - ...layerZeroMainnet.BOBA_Bridges.Avalanche, - ...layerZeroMainnet.Layer_Zero_Protocol.Avalanche, - layerZeroTargetChainID: layerZeroMainnet.Layer_Zero_Protocol.Mainnet.Layer_Zero_ChainId, - }, [ NETWORK.BNB ]: { ...addresses_BobaBnb, ...layerZeroMainnet.BOBA_Bridges.BNB, @@ -53,12 +45,6 @@ const ADDRESS_CONFIG = { ...layerZeroTestnet.Layer_Zero_Protocol.Testnet, layerZeroTargetChainID: layerZeroTestnet.Layer_Zero_Protocol.Testnet.Layer_Zero_ChainId, }, - [ NETWORK.AVAX ]: { - ...addresses_BobaFuji, - ...layerZeroTestnet.BOBA_Bridges.Avalanche, - ...layerZeroTestnet.Layer_Zero_Protocol.Avalanche, - layerZeroTargetChainID: layerZeroTestnet.Layer_Zero_Protocol.Avalanche.Layer_Zero_ChainId, - }, [ NETWORK.BNB ]: { ...addresses_BobaBnbTestnet, ...layerZeroTestnet.BOBA_Bridges.BNB, @@ -114,13 +100,6 @@ const SUPPORTED_ASSETS = { }, altL1Chains: [ 'BNB', 'Avalanche' ] }, - [ NETWORK.AVAX ]: { - tokenAddresses: { - 'EVO': { 'L1': '0x42006Ab57701251B580bDFc24778C43c9ff589A1', 'L2': '0xc8849f32138de93F6097199C5721a9EfD91ceE01' } - }, - tokens: [ 'BOBA', 'AVAX', 'EVO', 'USDT.e', 'USDt', 'USDC.e', 'BUSD.e', 'BUSD', 'DAI.e' ], - altL1Chains: [ 'Avalanche' ] - }, [ NETWORK.BNB ]: { tokenAddresses: {}, tokens: [ 'BOBA', 'BNB', 'BUSD', 'USDC', 'USDT', 'SUSHI' ], @@ -133,11 +112,6 @@ const SUPPORTED_ASSETS = { tokens: [ 'BOBA', 'USDC', 'OMG', 'xBOBA' ], altL1Chains: [ 'BNB', 'Avalanche' ] }, - [ NETWORK.AVAX ]: { - tokenAddresses: {}, - tokens: [ 'BOBA', 'AVAX' ], - altL1Chains: [ 'Avalanche' ] - }, [ NETWORK.BNB ]: { tokenAddresses: {}, tokens: [ 'BOBA', 'BNB', 'MMT' ], diff --git a/src/util/constant.ts b/src/util/constant.ts index 97891914..4d2ddd0a 100644 --- a/src/util/constant.ts +++ b/src/util/constant.ts @@ -91,14 +91,13 @@ export const ROUTES_PATH: RoutesPathType = { export const PER_PAGE: number = 8 -type Network = 'ethereum' | 'bnb' | 'avax' //we move this to global network type once we define this +type Network = 'ethereum' | 'bnb' //we move this to global network type once we define this type Page = 'Bridge' | 'History' | 'Earn' | 'Stake' | 'DAO' | 'Monster' type PagesByNetworkType = Record export const PAGES_BY_NETWORK: PagesByNetworkType = { ethereum: ['Bridge', 'History', 'Earn', 'Stake', 'DAO'], bnb: ['Bridge', 'Earn', 'History'], - avax: ['Bridge', 'Earn', 'History'], } export enum Layer { diff --git a/src/util/network/config/avax.js b/src/util/network/config/avax.js deleted file mode 100644 index e92fb866..00000000 --- a/src/util/network/config/avax.js +++ /dev/null @@ -1,70 +0,0 @@ - -export const avaxConfig = { - Testnet: { - OMGX_WATCHER_URL: `https://api-watcher.testnet.avax.boba.network/`, - META_TRANSACTION: `https://api-meta-transaction.testnet.avax.boba.network/`, - MM_Label: `Boba Avalanche Testnet`, - addressManager: `0xcE78de95b85212BC348452e91e0e74c17cf37c79`, - L1: { - name: "Avalanche Testnet", - chainId: 43113, - chainIdHex: '0xA869', - rpcUrl: [ - `https://api.avax-test.network/ext/bc/C/rpc`, - `https://rpc.ankr.com/avalanche_fuji`, - ], - transaction: `https://testnet.snowtrace.io/tx/`, - blockExplorerUrl: `https://testnet.snowtrace.io/`, - symbol: "AVAX", - tokenName: "AVAX", - }, - L2: { - name: "Boba Avalanche Testnet", - chainId: 4328, - chainIdHex: '0x10E8', - rpcUrl: [ - `https://testnet.avax.boba.network` - ], - blockExplorer: `https://blockexplorer.testnet.avax.boba.network/`, - transaction: `https://blockexplorer.testnet.avax.boba.network/tx/`, - blockExplorerUrl: `https://blockexplorer.testnet.avax.boba.network/`, - symbol: "BOBA", - tokenName: "Boba Token", - }, - gasEstimateAccount: `0xdb5a187FED81c735ddB1F6E47F28f2A5F74639b2`, - twitterFaucetPromotionText: `https://twitter.com/intent/tweet?text=I%27m%20developing%20on%20Boba%20Avalanche%20Testnet%20for%20Avalanche%20` - }, - Mainnet: { - OMGX_WATCHER_URL: `https://api-watcher.avax.boba.network/`, - META_TRANSACTION: `https://api-meta-transaction.avax.boba.network/`, - MM_Label: `Boba Avalanche Mainnet`, - addressManager: `0x00220f8ce1c4be8436574e575fE38558d85e2E6b`, - L1: { - name: "Avalanche Mainnet", - chainId: 43114, - chainIdHex: '0xA86A', - rpcUrl: [ - `https://api.avax.network/ext/bc/C/rpc`, - `https://rpc.ankr.com/avalanche`, - `https://1rpc.io/avax/c`, - ], - transaction: `https://snowtrace.io/tx/`, - blockExplorerUrl: `https://snowtrace.io/`, - symbol: "AVAX", - tokenName: "AVAX", - }, - L2: { - name: "Boba Avalanche Mainnet", - chainId: 43288, - chainIdHex: '0xA918', - rpcUrl: [ `https://avax.boba.network`, ], - blockExplorer: `https://blockexplorer.avax.boba.network/`, - transaction: `https://blockexplorer.avax.boba.network/tx/`, - blockExplorerUrl: `https://blockexplorer.avax.boba.network/`, - symbol: "BOBA", - tokenName: "Boba Token", - }, - gasEstimateAccount: `0xdb5a187FED81c735ddB1F6E47F28f2A5F74639b2`, - twitterFaucetPromotionText: `https://twitter.com/intent/tweet?text=I%27m%20developing%20on%20Boba%20Avalanche%20Testnet%20for%20Avalanche%20` - } -} diff --git a/src/util/network/network.util.ts b/src/util/network/network.util.ts index ebeeb94e..aad6ad38 100644 --- a/src/util/network/network.util.ts +++ b/src/util/network/network.util.ts @@ -2,27 +2,22 @@ import { BigNumberish, providers } from 'ethers' import EthereumIcon from 'components/icons/chain/L1/EthereumIcon' import BNBIcon from 'components/icons/chain/L1/BNBIcon' -import AvalancheIcon from 'components/icons/chain/L1/AvalancheIcon' import BobaIcon from 'components/icons/chain/L2/BobaIcon' import BobaBNBIcon from 'components/icons/chain/L2/BobaBNBIcon' -import BobaAvaxIcon from 'components/icons/chain/L2/BobaAvaxIcon' import { ethereumConfig } from './config/ethereum' import { bnbConfig } from './config/bnb' -import { avaxConfig } from './config/avax' import { Layer, LAYER } from 'util/constant' export const L1_ICONS = { ethereum: EthereumIcon, bnb: BNBIcon, - avax: AvalancheIcon, } export const L2_ICONS = { ethereum: BobaIcon, bnb: BobaBNBIcon, - avax: BobaAvaxIcon, } export const NETWORK_TYPE = { @@ -33,7 +28,6 @@ export const NETWORK_TYPE = { export const NETWORK = { ETHEREUM: 'ETHEREUM', BNB: 'BNB', - AVAX: 'AVAX', } export const CHAIN_ID_LIST = { @@ -65,35 +59,6 @@ export const CHAIN_ID_LIST = { name: 'Boba Eth', icon: 'ethereum', }, - // TODO: Remove Avax once down - 43113: { - networkType: NETWORK_TYPE.TESTNET, - chain: NETWORK.AVAX, - layer: LAYER.L1, - name: 'Fuji', - icon: 'avax', - }, - 4328: { - networkType: NETWORK_TYPE.TESTNET, - chain: NETWORK.AVAX, - layer: LAYER.L2, - name: 'Boba Fuji', - icon: 'avax', - }, - 43114: { - networkType: NETWORK_TYPE.MAINNET, - chain: NETWORK.AVAX, - layer: LAYER.L1, - name: 'Avax', - icon: 'avax', - }, - 43288: { - networkType: NETWORK_TYPE.MAINNET, - chain: NETWORK.AVAX, - layer: LAYER.L2, - name: 'Boba Avax', - icon: 'avax', - }, 97: { networkType: NETWORK_TYPE.TESTNET, chain: NETWORK.BNB, @@ -124,6 +89,11 @@ export const CHAIN_ID_LIST = { }, } +export interface INetworkClass { + network: typeof NETWORK + networkType: typeof NETWORK_TYPE +} + export interface INetwork { icon: string chain: string @@ -157,17 +127,6 @@ export const NetworkList: { Mainnet: INetwork[]; Testnet: INetwork[] } = { }, chainId: { [Layer.L1]: '56', [Layer.L2]: '56288' }, }, - { - icon: 'avax', - chain: NETWORK.AVAX, - label: 'Avalanche <> Boba', - key: 'avax', - name: { - l1: 'Avalanche Mainnet C-Chain', - l2: 'Boba Avalanche', - }, - chainId: { [Layer.L1]: '43114', [Layer.L2]: '43288' }, - }, ], Testnet: [ { @@ -192,24 +151,12 @@ export const NetworkList: { Mainnet: INetwork[]; Testnet: INetwork[] } = { }, chainId: { [Layer.L1]: '97', [Layer.L2]: '9728' }, }, - { - icon: 'avax', - chain: NETWORK.AVAX, - label: 'Fuji (Testnet) <> Boba', - key: 'avax', - name: { - l1: 'Fuji Testnet', - l2: 'Boba Fuji Testnet', - }, - chainId: { [Layer.L1]: '43113', [Layer.L2]: '4328' }, - }, ], } export const AllNetworkConfigs = { [NETWORK.ETHEREUM]: ethereumConfig, [NETWORK.BNB]: bnbConfig, - [NETWORK.AVAX]: avaxConfig, } export const getNetworkDetail = ({ network, networkType }) => {