mirror of
https://github.com/fullstack-cash/fullstack-gatsby-theme-bch-wallet.git
synced 2026-09-22 01:02:06 -07:00
Merge pull request #65 from Permissionless-Software-Foundation/feature/ReduxStore_TokenData
Use Redux store for token data
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
@@ -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 })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user