1
0
mirror of https://github.com/kremalicious/blowfish.git synced 2024-11-22 01:36:58 +01:00

get balance from chain

This commit is contained in:
Matthias Kretschmann 2020-02-26 21:04:40 +01:00
parent 26df59c687
commit 41fda20563
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 14 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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