This repository has been archived by the owner on Feb 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved all initializers to respective API's index file Updated all apps to use the new initializers Co-authored-by: Leandro Boscariol <[email protected]>
- Loading branch information
1 parent
7ed0004
commit 43af8ff
Showing
15 changed files
with
214 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Erc20Api } from 'api/erc20/Erc20Api' | ||
|
||
import { DepositApi, DepositApiDependencies } from './DepositApi' | ||
import { DepositApiMock } from './DepositApiMock' | ||
import { DepositApiProxy } from './DepositApiProxy' | ||
|
||
import { exchangeBalanceStates } from '../../../test/data' | ||
|
||
export function createDepositApi(erc20Api: Erc20Api, injectedDependencies: DepositApiDependencies): DepositApi { | ||
let depositApi | ||
if (process.env.MOCK_DEPOSIT === 'true') { | ||
depositApi = new DepositApiMock(exchangeBalanceStates, erc20Api) | ||
} else { | ||
depositApi = new DepositApiProxy(injectedDependencies) | ||
} | ||
window['depositApi'] = depositApi // register for convenience | ||
return depositApi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DexPriceEstimatorApi } from './DexPriceEstimatorApi' | ||
import { DexPriceEstimatorApiProxy } from './DexPriceEstimatorApiProxy' | ||
|
||
export function createDexPriceEstimatorApi(): DexPriceEstimatorApi { | ||
const { type, config } = CONFIG.dexPriceEstimator | ||
let dexPriceEstimatorApi: DexPriceEstimatorApi | ||
switch (type) { | ||
case 'dex-price-estimator': | ||
dexPriceEstimatorApi = new DexPriceEstimatorApiProxy(config) | ||
break | ||
|
||
default: | ||
throw new Error('Unknown implementation for DexPriceEstimatorApi: ' + type) | ||
} | ||
|
||
window['dexPriceEstimatorApi'] = dexPriceEstimatorApi | ||
return dexPriceEstimatorApi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Erc20Api, Erc20ApiDependencies } from './Erc20Api' | ||
import Erc20ApiMock from './Erc20ApiMock' | ||
import { Erc20ApiProxy } from './Erc20ApiProxy' | ||
|
||
import { erc20Balances, erc20Allowances, unregisteredTokens } from '../../../test/data' | ||
|
||
export function createErc20Api(injectedDependencies: Erc20ApiDependencies): Erc20Api { | ||
let erc20Api | ||
if (process.env.MOCK_ERC20 === 'true') { | ||
erc20Api = new Erc20ApiMock({ balances: erc20Balances, allowances: erc20Allowances, tokens: unregisteredTokens }) | ||
} else { | ||
erc20Api = new Erc20ApiProxy(injectedDependencies) | ||
} | ||
window['erc20Api'] = erc20Api // register for convenience | ||
return erc20Api | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { DepositApiDependencies } from 'api/deposit/DepositApi' | ||
import { Erc20Api } from 'api/erc20/Erc20Api' | ||
|
||
import { ExchangeApi } from './ExchangeApi' | ||
import ExchangeApiMock from './ExchangeApiMock' | ||
import { ExchangeApiProxy } from './ExchangeApiProxy' | ||
|
||
import { tokenList, exchangeBalanceStates, FEE_TOKEN, exchangeOrders, TOKEN_8 } from '../../../test/data' | ||
|
||
export function createExchangeApi(erc20Api: Erc20Api, injectedDependencies: DepositApiDependencies): ExchangeApi { | ||
let exchangeApi | ||
if (process.env.MOCK_EXCHANGE === 'true') { | ||
const tokens = [FEE_TOKEN, ...tokenList.map((token) => token.address), TOKEN_8] | ||
exchangeApi = new ExchangeApiMock({ | ||
balanceStates: exchangeBalanceStates, | ||
erc20Api, | ||
registeredTokens: tokens, | ||
ordersByUser: exchangeOrders, | ||
}) | ||
} else { | ||
exchangeApi = new ExchangeApiProxy({ | ||
...injectedDependencies, | ||
contractsDeploymentBlocks: CONFIG.exchangeContractConfig.config, | ||
}) | ||
} | ||
window['exchangeApi'] = exchangeApi | ||
return exchangeApi | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Web3 from 'web3' | ||
|
||
import { MultiTcrApiProxy } from './MultiTcrApiProxy' | ||
import { TcrApi } from './TcrApi' | ||
|
||
export function createTcrApi(web3: Web3): TcrApi | undefined { | ||
const { type } = CONFIG.tcr | ||
let tcrApi: TcrApi | undefined | ||
switch (CONFIG.tcr.type) { | ||
case 'none': | ||
tcrApi = undefined | ||
break | ||
case 'multi-tcr': { | ||
const multiTcrApiConfig = CONFIG.tcr | ||
tcrApi = new MultiTcrApiProxy({ web3, ...multiTcrApiConfig.config }) | ||
break | ||
} | ||
|
||
default: | ||
throw new Error('Unknown implementation for DexPriceEstimatorApi: ' + type) | ||
} | ||
|
||
window['tcrApi'] = tcrApi | ||
return tcrApi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { TheGraphApi } from './TheGraphApi' | ||
import { TheGraphApiProxy } from './TheGraphApiProxy' | ||
|
||
export function createTheGraphApi(): TheGraphApi { | ||
const { type, config } = CONFIG.theGraphApi | ||
let theGraphApi: TheGraphApi | ||
switch (type) { | ||
case 'the-graph': | ||
theGraphApi = new TheGraphApiProxy(config) | ||
break | ||
|
||
default: | ||
throw new Error('Unknown implementation for TheGraphApi: ' + type) | ||
} | ||
|
||
window['theGraphApi'] = theGraphApi | ||
return theGraphApi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Network } from 'types' | ||
|
||
import TokenListApiImpl, { TokenList } from './TokenListApi' | ||
import TokenListApiMock from './TokenListApiMock' | ||
|
||
import { tokenList } from '../../../test/data' | ||
|
||
export function createTokenListApi(): TokenList { | ||
const networkIds = [Network.Mainnet, Network.Rinkeby, Network.xDAI] | ||
|
||
let tokenListApi: TokenList | ||
if (process.env.MOCK_TOKEN_LIST === 'true') { | ||
tokenListApi = new TokenListApiMock(tokenList) | ||
} else { | ||
tokenListApi = new TokenListApiImpl({ networkIds, initialTokenList: CONFIG.initialTokenList }) | ||
} | ||
|
||
window['tokenListApi'] = tokenListApi // register for convenience | ||
return tokenListApi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Web3 from 'web3' | ||
|
||
import WalletApiImpl, { WalletApi } from './WalletApi' | ||
import WalletApiMock from './WalletApiMock' | ||
|
||
export function createWalletApi(web3: Web3): WalletApi { | ||
let walletApi | ||
if (process.env.MOCK_WALLET === 'true') { | ||
walletApi = new WalletApiMock() | ||
} else { | ||
walletApi = new WalletApiImpl(web3) | ||
} | ||
window['walletApi'] = walletApi // register for convenience | ||
return walletApi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Web3 from 'web3' | ||
|
||
import { ETH_NODE_URL } from 'const' | ||
|
||
// TODO connect to mainnet if we need AUTOCONNECT at all | ||
export const getDefaultProvider = (): string | null => (process.env.NODE_ENV === 'test' ? null : ETH_NODE_URL) | ||
|
||
export function createWeb3Api(): Web3 { | ||
// TODO: Create an `EthereumApi` https://github.com/gnosis/gp-v1-ui/issues/331 | ||
const web3 = new Web3(getDefaultProvider()) | ||
// `handleRevert = true` makes `require` failures to throw | ||
// For more details see https://github.com/gnosis/gp-v1-ui/issues/511 | ||
web3.eth['handleRevert'] = true | ||
|
||
if (process.env.MOCK_WEB3 === 'true') { | ||
// Only function that needs to be mocked so far. We can add more and add extra logic as needed | ||
web3.eth.getCode = async (address: string): Promise<string> => address | ||
} | ||
return web3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { WethApi, WethApiDependencies, WethApiImpl } from './WethApi' | ||
import { WethApiMock } from './WethApiMock' | ||
|
||
export function createWethApi(injectedDependencies: WethApiDependencies): WethApi { | ||
let wethApi | ||
if (process.env.MOCK_WETH === 'true') { | ||
wethApi = new WethApiMock() | ||
} else { | ||
wethApi = new WethApiImpl(injectedDependencies) | ||
} | ||
window['wethApi'] = wethApi // register for convenience | ||
|
||
return wethApi | ||
} |
Oops, something went wrong.