use Redux store for token data

This commit is contained in:
nicocappabianca
2020-09-16 21:17:30 -03:00
parent 80b9229469
commit 080ef3c554
2 changed files with 18 additions and 4 deletions
+5 -1
View File
@@ -132,6 +132,8 @@ class AdminLTEPage extends React.Component {
<Tokens
walletInfo={_this.props.walletInfo}
bchWallet={_this.props.bchWallet}
setTokensInfo={_this.props.setTokensInfo}
tokensInfo={_this.props.tokensInfo}
/>
)}
@@ -394,7 +396,9 @@ AdminLTEPage.propTypes = {
setWalletInfo: PropTypes.func.isRequired, // set wallet info
updateBalance: PropTypes.func.isRequired, // update bch balance
setBchWallet: PropTypes.func.isRequired, // set minimal-slp-wallet instance
bchWallet: PropTypes.object // get minimal-slp-wallet instance
bchWallet: PropTypes.object, // get minimal-slp-wallet instance
setTokensInfo: PropTypes.func.isRequired, // set tokens info
tokensInfo: PropTypes.array // tokens info
}
export default AdminLTEPage
+13 -3
View File
@@ -125,7 +125,7 @@ class Tokens extends React.Component {
})
}
async handleGetTokens () {
async handleGetTokens (refresh = null) {
_this.setState({
inFetch: true
})
@@ -141,7 +141,12 @@ class Tokens extends React.Component {
}
await bchWallet.walletInfoPromise
tokens = await bchWallet.listTokens()
if(_this.props.tokensInfo.length > 0 && refresh === null) {
tokens = _this.props.tokensInfo
} else {
tokens = await bchWallet.listTokens()
}
if (!tokens.length) {
throw new Error('No tokens found on this wallet.')
@@ -150,6 +155,9 @@ class Tokens extends React.Component {
tokens,
inFetch: false
})
_this.props.setTokensInfo(tokens)
} catch (error) {
_this.handleError(error)
}
@@ -223,6 +231,8 @@ class Tokens extends React.Component {
}
Tokens.propTypes = {
walletInfo: PropTypes.object.isRequired, // wallet info
bchWallet: PropTypes.object // get minimal-slp-wallet instance
bchWallet: PropTypes.object, // get minimal-slp-wallet instance
setTokensInfo: PropTypes.func.isRequired, // set tokens info
tokensInfo: PropTypes.array // tokens info
}
export default Tokens