Add SNT allowance to redux store
This commit is contained in:
parent
e176603e2f
commit
4ca9dfb592
|
@ -1,4 +1,8 @@
|
||||||
import ERC20Token from 'Embark/contracts/ERC20Token';
|
import ERC20Token from 'Embark/contracts/ERC20Token'
|
||||||
|
import ENSSubdomainRegistry from 'Embark/contracts/ENSSubdomainRegistry'
|
||||||
|
import TestToken from 'Embark/contracts/TestToken'
|
||||||
|
|
||||||
|
import { getDefaultAccount } from '../utils/web3Helpers'
|
||||||
import { actions as accountActions } from '../reducers/accounts'
|
import { actions as accountActions } from '../reducers/accounts'
|
||||||
import { isNil } from 'lodash'
|
import { isNil } from 'lodash'
|
||||||
|
|
||||||
|
@ -35,3 +39,14 @@ export const checkAndDispatchStatusContactCode = dispatch => {
|
||||||
1000
|
1000
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const fetchAndDispatchSNTAllowance = dispatch => {
|
||||||
|
const { methods: { allowance } } = TestToken;
|
||||||
|
const { receiveSntAllowance } = accountActions;
|
||||||
|
const spender = ENSSubdomainRegistry._address;
|
||||||
|
allowance(getDefaultAccount(), spender)
|
||||||
|
.call()
|
||||||
|
.then(allowance => {
|
||||||
|
dispatch(receiveSntAllowance(allowance))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -6,14 +6,16 @@ export const types = createTypes([
|
||||||
'UPDATE_DEFAULT_ACCOUNT',
|
'UPDATE_DEFAULT_ACCOUNT',
|
||||||
'ADD_TO_SNT_TOKEN_BALANCE',
|
'ADD_TO_SNT_TOKEN_BALANCE',
|
||||||
'SUBTRACT_FROM_SNT_TOKEN_BALANCE',
|
'SUBTRACT_FROM_SNT_TOKEN_BALANCE',
|
||||||
'RECEIVE_STATUS_CONTACT_CODE'
|
'RECEIVE_STATUS_CONTACT_CODE',
|
||||||
|
'RECEIVE_SNT_ALLOWANCE'
|
||||||
], 'ACCOUNTS')
|
], 'ACCOUNTS')
|
||||||
export const actions = {
|
export const actions = {
|
||||||
receiveAccounts: actionCreator(types.RECEIVE_ACCOUNTS, 'defaultAccount','accounts'),
|
receiveAccounts: actionCreator(types.RECEIVE_ACCOUNTS, 'defaultAccount','accounts'),
|
||||||
updateDefaultAccount: actionCreator(types.UPDATE_DEFAULT_ACCOUNT, 'defaultAccount'),
|
updateDefaultAccount: actionCreator(types.UPDATE_DEFAULT_ACCOUNT, 'defaultAccount'),
|
||||||
addToSntTokenBalance: actionCreator(types.ADD_TO_SNT_TOKEN_BALANCE, 'amount'),
|
addToSntTokenBalance: actionCreator(types.ADD_TO_SNT_TOKEN_BALANCE, 'amount'),
|
||||||
subtractfromSntTokenBalance: actionCreator(types.SUBTRACT_FROM_SNT_TOKEN_BALANCE, 'amount'),
|
subtractfromSntTokenBalance: actionCreator(types.SUBTRACT_FROM_SNT_TOKEN_BALANCE, 'amount'),
|
||||||
receiveStatusContactCode: actionCreator(types.RECEIVE_STATUS_CONTACT_CODE, 'statusContactCode')
|
receiveStatusContactCode: actionCreator(types.RECEIVE_STATUS_CONTACT_CODE, 'statusContactCode'),
|
||||||
|
receiveSntAllowance: actionCreator(types.RECEIVE_SNT_ALLOWANCE, 'SNTAllowance')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function(state = { loading: true, accounts: [] }, action) {
|
export default function(state = { loading: true, accounts: [] }, action) {
|
||||||
|
@ -57,6 +59,10 @@ export default function(state = { loading: true, accounts: [] }, action) {
|
||||||
const { statusContactCode } = action.payload
|
const { statusContactCode } = action.payload
|
||||||
return { ...state, statusContactCode }
|
return { ...state, statusContactCode }
|
||||||
}
|
}
|
||||||
|
case types.RECEIVE_SNT_ALLOWANCE: {
|
||||||
|
const { SNTAllowance } = action.payload
|
||||||
|
return { ...state, SNTAllowance }
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import web3 from "Embark/web3"
|
import web3 from "Embark/web3"
|
||||||
import EmbarkJS from 'Embark/EmbarkJS'
|
import EmbarkJS from 'Embark/EmbarkJS'
|
||||||
import store from './configureStore'
|
import store from './configureStore'
|
||||||
import { fetchAndDispatchAccountsWithBalances, checkAndDispatchStatusContactCode } from '../actions/accounts'
|
import { fetchAndDispatchSNTAllowance, fetchAndDispatchAccountsWithBalances, checkAndDispatchStatusContactCode } from '../actions/accounts'
|
||||||
|
|
||||||
const dispatch = action => store.dispatch(action)
|
const dispatch = action => store.dispatch(action)
|
||||||
|
|
||||||
|
@ -9,5 +9,6 @@ export default () => {
|
||||||
__embarkContext.execWhenReady(async () => {
|
__embarkContext.execWhenReady(async () => {
|
||||||
fetchAndDispatchAccountsWithBalances(web3, dispatch)
|
fetchAndDispatchAccountsWithBalances(web3, dispatch)
|
||||||
checkAndDispatchStatusContactCode(dispatch)
|
checkAndDispatchStatusContactCode(dispatch)
|
||||||
|
fetchAndDispatchSNTAllowance(dispatch)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue