mirror of
https://github.com/fullstack-cash/fullstack-gatsby-theme-bch-wallet.git
synced 2026-09-21 16:52:06 -07:00
Merge branch 'master' into dh-max-button
This commit is contained in:
@@ -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}
|
||||
/>
|
||||
|
||||
<JsonWebTokens
|
||||
@@ -63,7 +64,9 @@ class Configure extends React.Component {
|
||||
Configure.propTypes = {
|
||||
setWalletInfo: PropTypes.func.isRequired,
|
||||
walletInfo: PropTypes.object.isRequired,
|
||||
setBchWallet: PropTypes.func.isRequired
|
||||
setBchWallet: PropTypes.func.isRequired,
|
||||
updateBalance: PropTypes.func.isRequired
|
||||
|
||||
}
|
||||
|
||||
export default Configure
|
||||
|
||||
@@ -23,7 +23,8 @@ class Servers extends React.Component {
|
||||
errMsg: '',
|
||||
selectedServer: '',
|
||||
showAddField: false,
|
||||
newServer: ''
|
||||
newServer: '',
|
||||
inFetch: false
|
||||
}
|
||||
_this.BchWallet = BchWallet
|
||||
}
|
||||
@@ -32,7 +33,10 @@ class Servers extends React.Component {
|
||||
return (
|
||||
<Row>
|
||||
<Col sm={12}>
|
||||
<Box className='hover-shadow border-none mt-2'>
|
||||
<Box
|
||||
className='hover-shadow border-none mt-2'
|
||||
loaded={!_this.state.inFetch}
|
||||
>
|
||||
<Row>
|
||||
<Col sm={12} className='text-center'>
|
||||
<h1>
|
||||
@@ -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() * 100
|
||||
} 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
|
||||
|
||||
@@ -132,7 +132,16 @@ 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() * 100
|
||||
} else {
|
||||
// BCHN price.
|
||||
currentRate = (await bchjs.Price.getUsd()) * 100
|
||||
}
|
||||
|
||||
_this.setState({
|
||||
currentRate: currentRate
|
||||
})
|
||||
@@ -188,6 +197,7 @@ class AdminLTEPage extends React.Component {
|
||||
_this.changeSection(_this.defaultSection)
|
||||
}
|
||||
}
|
||||
_this.updateState()
|
||||
}
|
||||
|
||||
// Update component state when props change
|
||||
@@ -199,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
|
||||
})
|
||||
}
|
||||
@@ -341,7 +355,7 @@ class AdminLTEPage extends React.Component {
|
||||
return ''
|
||||
})
|
||||
)
|
||||
} catch (err) { }
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
getInvisibleMenuItem () {
|
||||
@@ -371,10 +385,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 +401,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
|
||||
|
||||
|
||||
@@ -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() * 100
|
||||
} 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 })
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user