From 367de5b29c1689dba83fe08efb5cde7e5d14aa7c Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 17 Nov 2020 16:43:27 -0800 Subject: [PATCH 1/4] fix(servers): Updating default servers --- src/components/admin-lte/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/admin-lte/index.js b/src/components/admin-lte/index.js index ff7abc9..32fa0a3 100644 --- a/src/components/admin-lte/index.js +++ b/src/components/admin-lte/index.js @@ -371,10 +371,10 @@ class AdminLTEPage extends React.Component { const servers = [server1, server2] + // Default server is BCHN. let selectedServer = server1 - // Assign the second server if the url path - // is different of 'wallet.fullstack.cash' - if (accessLocation !== 'wallet.fullstack.cash') { + + if (accessLocation === 'wallet.fullstack.cash') { selectedServer = server1 } @@ -387,6 +387,11 @@ class AdminLTEPage extends React.Component { selectedServer = server2 } + // Split uses BCHN by default + if (accessLocation === 'splitbch.com') { + selectedServer = server1 + } + walletInfo.selectedServer = selectedServer walletInfo.servers = servers From e4382daba2102d28a9a2e535e334c34340c84495 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 17 Nov 2020 17:58:12 -0800 Subject: [PATCH 2/4] Trying to implement BCHA prices --- src/components/admin-lte/index.js | 36 ++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/components/admin-lte/index.js b/src/components/admin-lte/index.js index 32fa0a3..369ae46 100644 --- a/src/components/admin-lte/index.js +++ b/src/components/admin-lte/index.js @@ -60,18 +60,18 @@ class AdminLTEPage extends React.Component { - + -
+
{!_this.state.inFetch && ( -
+

{siteConfig.balanceText}

@@ -81,9 +81,9 @@ class AdminLTEPage extends React.Component { USD: ${_this.state.usdBalance}
@@ -101,8 +101,8 @@ class AdminLTEPage extends React.Component { - -
+ +
{_this.renderNewViewItems(_this.props)}
@@ -132,7 +132,17 @@ class AdminLTEPage extends React.Component { const myBalance = await bchWalletLib.getBalance() const bchjs = bchWalletLib.bchjs - const currentRate = await bchjs.Price.getUsd() * 100 + + let currentRate + + if (bchjs.restURL.includes('abc.fullstack')) { + currentRate = await bchjs.Price.getBchaUsd() + console.log(`currentRate: ${currentRate}`) + } else { + // BCHN price. + currentRate = (await bchjs.Price.getUsd()) * 100 + } + _this.setState({ currentRate: currentRate }) @@ -341,14 +351,14 @@ class AdminLTEPage extends React.Component { return '' }) ) - } catch (err) { } + } catch (err) {} } getInvisibleMenuItem () { return (
  • {/* Adding this childrens prevents console errors */} - + From 7ee6eb989065d0ea44bd9be2e15c82c4bc7064d5 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Wed, 18 Nov 2020 15:02:20 -0400 Subject: [PATCH 3/4] feat(BCHA): Added price for BCHA --- src/components/admin-lte/configure/index.js | 5 +- src/components/admin-lte/configure/servers.js | 65 +++++++++++++++++-- src/components/admin-lte/index.js | 30 +++++---- src/components/admin-lte/wallet/import.js | 13 +++- src/redux/createStore.js | 1 + 5 files changed, 95 insertions(+), 19 deletions(-) diff --git a/src/components/admin-lte/configure/index.js b/src/components/admin-lte/configure/index.js index 333566f..43542d4 100644 --- a/src/components/admin-lte/configure/index.js +++ b/src/components/admin-lte/configure/index.js @@ -38,6 +38,7 @@ class Configure extends React.Component { setWalletInfo={_this.props.setWalletInfo} walletInfo={_this.props.walletInfo} setBchWallet={_this.props.setBchWallet} + updateBalance={_this.props.updateBalance} /> - +

    @@ -194,6 +198,11 @@ class Servers extends React.Component { } handleUpdateServer () { + // Show loader spinner + _this.setState({ + inFetch: true + }) + _this.handleNewServerUrl() // await for state update delay setTimeout(() => { @@ -224,12 +233,21 @@ class Servers extends React.Component { bchWalletLib.tokens.utxos.bchjs = new bchWalletLib.BCHJS(bchjsOptions) _this.props.setBchWallet(bchWalletLib) + + // update server current price + _this.handleUpdateBalance(bchWalletLib) + } else { + // Hide loader spinner + _this.setState({ + inFetch: false + }) } _this.saveServer() } catch (error) { console.warn(error) _this.setState({ - errMsg: error.message + errMsg: error.message, + inFetch: false }) } } @@ -263,6 +281,44 @@ class Servers extends React.Component { } } + // Get wallet balance + async handleUpdateBalance (bchWallet) { + try { + const { mnemonic } = _this.props.walletInfo + if (mnemonic && bchWallet) { + const bchWalletLib = bchWallet + await bchWalletLib.walletInfoPromise + const myBalance = await bchWalletLib.getBalance() + + const bchjs = bchWalletLib.bchjs + + let currentRate + + if (bchjs.restURL.includes('abc.fullstack')) { + currentRate = await bchjs.Price.getBchaUsd() + } else { + // BCHN price. + currentRate = (await bchjs.Price.getUsd()) * 100 + } + + _this.setState({ + currentRate: currentRate + }) + _this.props.updateBalance({ myBalance, currentRate }) + } + // Hide loader spinner + _this.setState({ + inFetch: false + }) + } catch (error) { + console.error(error) + // Hide loader spinner + _this.setState({ + inFetch: false + }) + } + } + // clean the text form field resetForm () { _this.setState({ @@ -273,7 +329,8 @@ class Servers extends React.Component { Servers.propTypes = { setWalletInfo: PropTypes.func.isRequired, walletInfo: PropTypes.object.isRequired, - setBchWallet: PropTypes.func.isRequired + setBchWallet: PropTypes.func.isRequired, + updateBalance: PropTypes.func.isRequired } export default Servers diff --git a/src/components/admin-lte/index.js b/src/components/admin-lte/index.js index 369ae46..6d60b08 100644 --- a/src/components/admin-lte/index.js +++ b/src/components/admin-lte/index.js @@ -60,18 +60,18 @@ class AdminLTEPage extends React.Component { - + -
    +
    {!_this.state.inFetch && ( -
    +

    {siteConfig.balanceText}

    @@ -81,9 +81,9 @@ class AdminLTEPage extends React.Component { USD: ${_this.state.usdBalance}
    @@ -101,8 +101,8 @@ class AdminLTEPage extends React.Component { - -
    + +
    {_this.renderNewViewItems(_this.props)}
    @@ -137,7 +137,6 @@ class AdminLTEPage extends React.Component { if (bchjs.restURL.includes('abc.fullstack')) { currentRate = await bchjs.Price.getBchaUsd() - console.log(`currentRate: ${currentRate}`) } else { // BCHN price. currentRate = (await bchjs.Price.getUsd()) * 100 @@ -198,6 +197,7 @@ class AdminLTEPage extends React.Component { _this.changeSection(_this.defaultSection) } } + _this.updateState() } // Update component state when props change @@ -209,7 +209,11 @@ class AdminLTEPage extends React.Component { } if (_this.props.bchBalance.bchBalance !== _this.state.bchBalance) { _this.setState({ - bchBalance: _this.props.bchBalance.bchBalance, + bchBalance: _this.props.bchBalance.bchBalance + }) + } + if (_this.props.bchBalance.usdBalance !== _this.state.usdBalance) { + _this.setState({ usdBalance: _this.props.bchBalance.usdBalance }) } @@ -358,7 +362,7 @@ class AdminLTEPage extends React.Component { return (
  • {/* Adding this childrens prevents console errors */} - + diff --git a/src/components/admin-lte/wallet/import.js b/src/components/admin-lte/wallet/import.js index 92c52d7..1c9e8fe 100644 --- a/src/components/admin-lte/wallet/import.js +++ b/src/components/admin-lte/wallet/import.js @@ -148,8 +148,19 @@ class ImportWallet extends React.Component { const myBalance = await bchWalletLib.getBalance() const bchjs = bchWalletLib.bchjs - const currentRate = await bchjs.Price.getUsd() * 100 + let currentRate + if (bchjs.restURL.includes('abc.fullstack')) { + currentRate = await bchjs.Price.getBchaUsd() + } else { + // BCHN price. + currentRate = (await bchjs.Price.getUsd()) * 100 + } + + _this.setState({ + currentRate: currentRate + }) + _this.props.updateBalance({ myBalance, currentRate }) // Update redux state _this.props.setWalletInfo(currentWallet) _this.props.updateBalance({ myBalance, currentRate }) diff --git a/src/redux/createStore.js b/src/redux/createStore.js index 728017b..c654e13 100644 --- a/src/redux/createStore.js +++ b/src/redux/createStore.js @@ -28,6 +28,7 @@ const reducer = (state, action) => { if (action.type === 'UPDATE_BALANCE') { // Convert satoshis to bch const { myBalance, currentRate } = action.value + console.log(`currentRate: ${currentRate}`) const satoshis = myBalance const bch = satoshis / 100000000 From 616a2eaca4060a67cf145bc0485d2b914e6078f7 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Wed, 18 Nov 2020 21:39:56 -0400 Subject: [PATCH 4/4] fixed bcha price display --- src/components/admin-lte/configure/servers.js | 2 +- src/components/admin-lte/index.js | 2 +- src/components/admin-lte/wallet/import.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/admin-lte/configure/servers.js b/src/components/admin-lte/configure/servers.js index b0b4168..f6098e1 100644 --- a/src/components/admin-lte/configure/servers.js +++ b/src/components/admin-lte/configure/servers.js @@ -295,7 +295,7 @@ class Servers extends React.Component { let currentRate if (bchjs.restURL.includes('abc.fullstack')) { - currentRate = await bchjs.Price.getBchaUsd() + currentRate = await bchjs.Price.getBchaUsd() * 100 } else { // BCHN price. currentRate = (await bchjs.Price.getUsd()) * 100 diff --git a/src/components/admin-lte/index.js b/src/components/admin-lte/index.js index 6d60b08..be4437f 100644 --- a/src/components/admin-lte/index.js +++ b/src/components/admin-lte/index.js @@ -136,7 +136,7 @@ class AdminLTEPage extends React.Component { let currentRate if (bchjs.restURL.includes('abc.fullstack')) { - currentRate = await bchjs.Price.getBchaUsd() + currentRate = await bchjs.Price.getBchaUsd() * 100 } else { // BCHN price. currentRate = (await bchjs.Price.getUsd()) * 100 diff --git a/src/components/admin-lte/wallet/import.js b/src/components/admin-lte/wallet/import.js index 1c9e8fe..cbb3ecd 100644 --- a/src/components/admin-lte/wallet/import.js +++ b/src/components/admin-lte/wallet/import.js @@ -151,7 +151,7 @@ class ImportWallet extends React.Component { let currentRate if (bchjs.restURL.includes('abc.fullstack')) { - currentRate = await bchjs.Price.getBchaUsd() + currentRate = await bchjs.Price.getBchaUsd() * 100 } else { // BCHN price. currentRate = (await bchjs.Price.getUsd()) * 100