1
0
mirror of https://github.com/kremalicious/blowfish.git synced 2024-12-27 15:17:51 +01:00

Merge pull request #61 from kremalicious/feature/balance-chain

get balance from chain
This commit is contained in:
Matthias Kretschmann 2020-02-26 22:02:21 +01:00 committed by GitHub
commit c72609e4b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 20 deletions

View File

@ -1 +1,2 @@
ETHERSCAN_API_KEY=
ETHERSCAN_API_KEY=
INFURA_PROJECT_ID=

View File

@ -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"
},

View File

@ -18,6 +18,8 @@ let mainWindow
const width = 640
const height = 450
app.allowRendererProcessReuse = true
const createWindow = async () => {
const isDarkMode = nativeTheme.shouldUseDarkColors

View File

@ -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 {

View File

@ -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() {

View File

@ -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(<PriceProvider>Hello</PriceProvider>)
await waitForElement(() => getByText('Hello'))
describe('PriceProvider', () => {
it('renders without crashing', async () => {
const { getByText } = render(
<PriceProvider>
<PriceContext.Consumer>
{({ priceChanges }) => JSON.stringify(priceChanges)}
</PriceContext.Consumer>
</PriceProvider>
)
await waitForElementToBeRemoved(() => getByText(/"eur":0/))
expect(getByText(/eur/)).toBeInTheDocument()
})
})
it('AppProvider', async () => {
const { getByText } = render(
<PriceContext.Provider value={priceContext}>
<AppProvider>Hello</AppProvider>
</PriceContext.Provider>
)
await waitForElement(() => getByText('Hello'))
describe('AppProvider', () => {
it('renders without crashing', async () => {
const { getByText } = render(
<PriceContext.Provider value={priceContext}>
<AppProvider>
<AppContext.Consumer>
{({ toggleCurrencies }) => (
<button onClick={() => toggleCurrencies('eur')}>Click</button>
)}
</AppContext.Consumer>
</AppProvider>
</PriceContext.Provider>
)
await waitForElement(() => getByText('Click'))
expect(getByText('Click')).toBeInTheDocument()
fireEvent.click(getByText('Click'))
})
})
})