mirror of
https://github.com/kremalicious/blowfish.git
synced 2024-12-28 23:57:52 +01:00
Merge pull request #61 from kremalicious/feature/balance-chain
get balance from chain
This commit is contained in:
commit
c72609e4b3
@ -1 +1,2 @@
|
|||||||
ETHERSCAN_API_KEY=
|
ETHERSCAN_API_KEY=
|
||||||
|
INFURA_PROJECT_ID=
|
@ -30,13 +30,14 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@coingecko/cryptoformat": "^0.3.4",
|
"@coingecko/cryptoformat": "^0.3.4",
|
||||||
|
"@oceanprotocol/keeper-contracts": "^0.13.2",
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"electron-is-dev": "^1.1.0",
|
"electron-is-dev": "^1.1.0",
|
||||||
"electron-next": "^3.1.5",
|
"electron-next": "^3.1.5",
|
||||||
"electron-store": "^5.1.1",
|
"electron-store": "^5.1.1",
|
||||||
"ethereum-address": "^0.0.4",
|
"ethereum-address": "^0.0.4",
|
||||||
"ethereum-blockies": "github:MyEtherWallet/blockies",
|
"ethereum-blockies": "github:MyEtherWallet/blockies",
|
||||||
"ethjs-unit": "^0.1.6",
|
"ethjs": "^0.4.0",
|
||||||
"ms": "^2.1.2",
|
"ms": "^2.1.2",
|
||||||
"shortid": "^2.2.15"
|
"shortid": "^2.2.15"
|
||||||
},
|
},
|
||||||
|
@ -18,6 +18,8 @@ let mainWindow
|
|||||||
const width = 640
|
const width = 640
|
||||||
const height = 450
|
const height = 450
|
||||||
|
|
||||||
|
app.allowRendererProcessReuse = true
|
||||||
|
|
||||||
const createWindow = async () => {
|
const createWindow = async () => {
|
||||||
const isDarkMode = nativeTheme.shouldUseDarkColors
|
const isDarkMode = nativeTheme.shouldUseDarkColors
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ const withElectron = (nextConfig = {}) => {
|
|||||||
module.exports = withSvgr(
|
module.exports = withSvgr(
|
||||||
withElectron({
|
withElectron({
|
||||||
env: {
|
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() {
|
exportPathMap() {
|
||||||
return {
|
return {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import Store from 'electron-store'
|
import Store from 'electron-store'
|
||||||
import unit from 'ethjs-unit'
|
import Eth from 'ethjs'
|
||||||
import { fetchData } from '../../utils'
|
import { fetchData } from '../../utils'
|
||||||
import { oceanTokenContract, conversions } from '../../config'
|
import { oceanTokenContract, conversions } from '../../config'
|
||||||
|
import { abi } from '@oceanprotocol/keeper-contracts/artifacts/OceanToken.pacific.json'
|
||||||
|
|
||||||
export async function fetchAndSetPrices(prices) {
|
export async function fetchAndSetPrices(prices) {
|
||||||
const currencies = conversions.join(',')
|
const currencies = conversions.join(',')
|
||||||
@ -22,12 +23,14 @@ export async function fetchAndSetPrices(prices) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getBalance(account) {
|
export async function getBalance(account) {
|
||||||
const json = await fetchData(
|
const provider = new Eth.HttpProvider(
|
||||||
`https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=${oceanTokenContract}&address=${account}&tag=latest&apikey=${process.env.ETHERSCAN_API_KEY}`
|
`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 Eth.fromWei(balance[0], 'ether')
|
||||||
return balance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAccounts() {
|
export async function getAccounts() {
|
||||||
|
@ -1,22 +1,47 @@
|
|||||||
import React from 'react'
|
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 AppProvider from '../src/renderer/store/AppProvider'
|
||||||
import PriceProvider from '../src/renderer/store/PriceProvider'
|
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'
|
import { priceContext } from './__fixtures__/context'
|
||||||
|
|
||||||
describe('Providers', () => {
|
describe('Providers', () => {
|
||||||
it('PriceProvider', async () => {
|
describe('PriceProvider', () => {
|
||||||
const { getByText } = render(<PriceProvider>Hello</PriceProvider>)
|
it('renders without crashing', async () => {
|
||||||
await waitForElement(() => getByText('Hello'))
|
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 () => {
|
describe('AppProvider', () => {
|
||||||
|
it('renders without crashing', async () => {
|
||||||
const { getByText } = render(
|
const { getByText } = render(
|
||||||
<PriceContext.Provider value={priceContext}>
|
<PriceContext.Provider value={priceContext}>
|
||||||
<AppProvider>Hello</AppProvider>
|
<AppProvider>
|
||||||
|
<AppContext.Consumer>
|
||||||
|
{({ toggleCurrencies }) => (
|
||||||
|
<button onClick={() => toggleCurrencies('eur')}>Click</button>
|
||||||
|
)}
|
||||||
|
</AppContext.Consumer>
|
||||||
|
</AppProvider>
|
||||||
</PriceContext.Provider>
|
</PriceContext.Provider>
|
||||||
)
|
)
|
||||||
await waitForElement(() => getByText('Hello'))
|
await waitForElement(() => getByText('Click'))
|
||||||
|
expect(getByText('Click')).toBeInTheDocument()
|
||||||
|
|
||||||
|
fireEvent.click(getByText('Click'))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user