diff --git a/.env.example b/.env.example index 0f8f543..e637a29 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -ETHERSCAN_API_KEY= \ No newline at end of file +ETHERSCAN_API_KEY= +INFURA_PROJECT_ID= \ No newline at end of file diff --git a/package.json b/package.json index ea79f6e..92c8d74 100644 --- a/package.json +++ b/package.json @@ -30,13 +30,14 @@ "license": "MIT", "dependencies": { "@coingecko/cryptoformat": "^0.3.4", + "@oceanprotocol/keeper-contracts": "^0.13.2", "axios": "^0.19.2", "electron-is-dev": "^1.1.0", "electron-next": "^3.1.5", "electron-store": "^5.1.1", "ethereum-address": "^0.0.4", "ethereum-blockies": "github:MyEtherWallet/blockies", - "ethjs-unit": "^0.1.6", + "ethjs": "^0.4.0", "ms": "^2.1.2", "shortid": "^2.2.15" }, diff --git a/src/main/index.js b/src/main/index.js index 51a461d..70a1437 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -18,6 +18,8 @@ let mainWindow const width = 640 const height = 450 +app.allowRendererProcessReuse = true + const createWindow = async () => { const isDarkMode = nativeTheme.shouldUseDarkColors diff --git a/src/renderer/next.config.js b/src/renderer/next.config.js index 6e44b64..275dd70 100644 --- a/src/renderer/next.config.js +++ b/src/renderer/next.config.js @@ -36,7 +36,8 @@ const withElectron = (nextConfig = {}) => { module.exports = withSvgr( withElectron({ env: { - ETHERSCAN_API_KEY: process.env.ETHERSCAN_API_KEY + ETHERSCAN_API_KEY: process.env.ETHERSCAN_API_KEY, + INFURA_PROJECT_ID: process.env.INFURA_PROJECT_ID }, exportPathMap() { return { diff --git a/src/renderer/store/helpers.js b/src/renderer/store/helpers.js index 5071405..ebe0ce6 100644 --- a/src/renderer/store/helpers.js +++ b/src/renderer/store/helpers.js @@ -1,7 +1,8 @@ import Store from 'electron-store' -import unit from 'ethjs-unit' +import Eth from 'ethjs' import { fetchData } from '../../utils' import { oceanTokenContract, conversions } from '../../config' +import { abi } from '@oceanprotocol/keeper-contracts/artifacts/OceanToken.pacific.json' export async function fetchAndSetPrices(prices) { const currencies = conversions.join(',') @@ -22,12 +23,14 @@ export async function fetchAndSetPrices(prices) { } export async function getBalance(account) { - const json = await fetchData( - `https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=${oceanTokenContract}&address=${account}&tag=latest&apikey=${process.env.ETHERSCAN_API_KEY}` + const provider = new Eth.HttpProvider( + `https://mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}` ) + const eth = new Eth(provider) + const token = eth.contract(abi).at(oceanTokenContract) + const balance = await token.balanceOf(account) - const balance = unit.fromWei(`${json.result}`, 'ether') - return balance + return Eth.fromWei(balance[0], 'ether') } export async function getAccounts() { diff --git a/tests/Providers.test.jsx b/tests/Providers.test.jsx index 6a78086..893b978 100644 --- a/tests/Providers.test.jsx +++ b/tests/Providers.test.jsx @@ -1,22 +1,47 @@ import React from 'react' -import { render, waitForElement } from '@testing-library/react' +import { + render, + waitForElement, + waitForElementToBeRemoved, + fireEvent +} from '@testing-library/react' import AppProvider from '../src/renderer/store/AppProvider' import PriceProvider from '../src/renderer/store/PriceProvider' -import { PriceContext } from '../src/renderer/store/createContext' +import { PriceContext, AppContext } from '../src/renderer/store/createContext' import { priceContext } from './__fixtures__/context' describe('Providers', () => { - it('PriceProvider', async () => { - const { getByText } = render(Hello) - await waitForElement(() => getByText('Hello')) + describe('PriceProvider', () => { + it('renders without crashing', async () => { + const { getByText } = render( + + + {({ priceChanges }) => JSON.stringify(priceChanges)} + + + ) + await waitForElementToBeRemoved(() => getByText(/"eur":0/)) + expect(getByText(/eur/)).toBeInTheDocument() + }) }) - it('AppProvider', async () => { - const { getByText } = render( - - Hello - - ) - await waitForElement(() => getByText('Hello')) + describe('AppProvider', () => { + it('renders without crashing', async () => { + const { getByText } = render( + + + + {({ toggleCurrencies }) => ( + + )} + + + + ) + await waitForElement(() => getByText('Click')) + expect(getByText('Click')).toBeInTheDocument() + + fireEvent.click(getByText('Click')) + }) }) })