Merge pull request #65 from Permissionless-Software-Foundation/feature/ReduxStore_TokenData

Use Redux store for token data
This commit is contained in:
Chris Troutner
2020-09-20 13:46:51 -07:00
committed by GitHub
4 changed files with 31 additions and 8 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
+4 -3
View File
@@ -9,8 +9,8 @@ const AdminLTE =
// Maps the props that are going to be sended
// to the component connected with Redux
const mapStateToProps = ({ walletInfo, bchBalance, bchWallet }) => {
return { walletInfo, bchBalance, bchWallet }
const mapStateToProps = ({ walletInfo, bchBalance, bchWallet, tokensInfo }) => {
return { walletInfo, bchBalance, bchWallet, tokensInfo }
}
// Send each action of the reducer as props
@@ -19,7 +19,8 @@ const mapDispatchToProps = dispatch => {
return {
setWalletInfo: value => dispatch({ type: 'SET_WALLET_INFO', value }),
updateBalance: value => dispatch({ type: 'UPDATE_BALANCE', value }),
setBchWallet: value => dispatch({ type: 'SET_BCH_WALLET', value })
setBchWallet: value => dispatch({ type: 'SET_BCH_WALLET', value }),
setTokensInfo: value => dispatch({ type: 'SET_TOKENS_INFO', value })
}
}
+9 -1
View File
@@ -47,6 +47,13 @@ const reducer = (state, action) => {
})
}
// Get or update tokens information
if (action.type === 'SET_TOKENS_INFO') {
return Object.assign({}, state, {
tokensInfo: action.value
})
}
return state
}
@@ -85,7 +92,8 @@ const instanceWallet = () => {
const initialState = {
walletInfo: localStorageInfo, // Object wallet info
bchBalance: { bchBalance: 0, usdBalance: 0 }, // Wallet Balance
bchWallet: instanceWallet() // minimal-slp-wallet instance
bchWallet: instanceWallet(), // minimal-slp-wallet instance
tokensInfo: []
}
const createStore = () => reduxCreateStore(reducer, initialState)