diff --git a/src/walletapp.js b/src/walletapp.js index e32d3f5..d6e5f2c 100644 --- a/src/walletapp.js +++ b/src/walletapp.js @@ -168,7 +168,7 @@ BusyModal.propTypes = { export class WalletApp extends React.Component { state = { - web3sol: new Web3Sol('master.testnet.solana.com'), // TODO: make endpoint configurable by the user + web3sol: new Web3Sol('http://master.testnet.solana.com:8899'), // TODO: make endpoint configurable by the user errors: [], busyModal: null, publicKey: '', diff --git a/src/web3-sol.js b/src/web3-sol.js index 8bfbfd7..0f87fb7 100644 --- a/src/web3-sol.js +++ b/src/web3-sol.js @@ -5,6 +5,7 @@ import nacl from 'tweetnacl'; import bs58 from 'bs58'; +import joi from 'joi'; import {createRpcClient} from './rpc-client'; @@ -32,7 +33,23 @@ export class Web3Sol { } async getBalance() { - await sleep(500); // TODO + try { + const res = await this.rpcClient.request( + 'getBalance', + [bs58.encode(this.keypair.publicKey)] + ); + console.log('getBalance result', res); + if (res.error) { + throw new Error(res.error.message); + } + this.balance = joi.attempt( + res.result, + joi.number().required().min(0) + ); + } catch (err) { + console.log('Failed to getBalance:', err); + } + return this.balance; } diff --git a/webpack.config.js b/webpack.config.js index 4f4ce7c..3b22d52 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -22,6 +22,11 @@ module.exports = { }, ] }, + node: { + net: 'empty', + tls: 'empty', + dns: 'empty', + }, resolve: { extensions: ['*', '.js', '.jsx'] },