diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-11 09:27:06 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-11 09:28:12 +0800 |
commit | 19f61906d3075391efb32c17c99c2cba1f7a3858 (patch) | |
tree | 5341adb545f8cbc883f3e569adf99b58a8b03de1 /packages/instant/src/util | |
parent | a5a033c359a1a00a144ae0655080b4e6d0e43c88 (diff) | |
download | dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.gz dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.bz2 dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.lz dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.xz dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.zst dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.zip |
feat: Move over features from zrx-buyer
Diffstat (limited to 'packages/instant/src/util')
-rw-r--r-- | packages/instant/src/util/asset_buyer.ts | 11 | ||||
-rw-r--r-- | packages/instant/src/util/coinbase_api.ts | 8 | ||||
-rw-r--r-- | packages/instant/src/util/provider.ts | 12 | ||||
-rw-r--r-- | packages/instant/src/util/web3_wrapper.ts | 5 |
4 files changed, 36 insertions, 0 deletions
diff --git a/packages/instant/src/util/asset_buyer.ts b/packages/instant/src/util/asset_buyer.ts new file mode 100644 index 000000000..b030501c4 --- /dev/null +++ b/packages/instant/src/util/asset_buyer.ts @@ -0,0 +1,11 @@ +import { AssetBuyer } from '@0xproject/asset-buyer'; + +import { sraApiUrl } from '../constants'; + +import { getProvider } from './provider'; + +const provider = getProvider(); + +export const assetBuyer = AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(provider, sraApiUrl, { + expiryBufferSeconds: 300, +}); diff --git a/packages/instant/src/util/coinbase_api.ts b/packages/instant/src/util/coinbase_api.ts new file mode 100644 index 000000000..63c8077da --- /dev/null +++ b/packages/instant/src/util/coinbase_api.ts @@ -0,0 +1,8 @@ +const baseEndpoint = 'https://api.coinbase.com/v2'; +export const coinbaseApi = { + getEthUsdPrice: async (): Promise<string> => { + const res = await fetch(`${baseEndpoint}/prices/ETH-USD/buy`); + const resJson = await res.json(); + return resJson.data.amount; + }, +}; diff --git a/packages/instant/src/util/provider.ts b/packages/instant/src/util/provider.ts new file mode 100644 index 000000000..49705fd11 --- /dev/null +++ b/packages/instant/src/util/provider.ts @@ -0,0 +1,12 @@ +import { Provider } from 'ethereum-types'; + +export const getProvider = (): Provider => { + const injectedWeb3 = (window as any).web3 || undefined; + try { + // Use MetaMask/Mist provider + return injectedWeb3.currentProvider; + } catch (err) { + // Throws when user doesn't have MetaMask/Mist running + throw new Error(`No injected web3 found: ${err}`); + } +}; diff --git a/packages/instant/src/util/web3_wrapper.ts b/packages/instant/src/util/web3_wrapper.ts new file mode 100644 index 000000000..d7e43521f --- /dev/null +++ b/packages/instant/src/util/web3_wrapper.ts @@ -0,0 +1,5 @@ +import { Web3Wrapper } from '@0xproject/web3-wrapper'; + +import { getProvider } from './provider'; + +export const web3Wrapper = new Web3Wrapper(getProvider()); |