Add SNT allowance to redux store

This commit is contained in:
Barry Gitarts 2018-08-14 10:10:31 -04:00
parent e176603e2f
commit 4ca9dfb592
3 changed files with 26 additions and 4 deletions

View File

@ -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 { isNil } from 'lodash'
@ -35,3 +39,14 @@ export const checkAndDispatchStatusContactCode = dispatch => {
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))
})
}

View File

@ -6,14 +6,16 @@ export const types = createTypes([
'UPDATE_DEFAULT_ACCOUNT',
'ADD_TO_SNT_TOKEN_BALANCE',
'SUBTRACT_FROM_SNT_TOKEN_BALANCE',
'RECEIVE_STATUS_CONTACT_CODE'
'RECEIVE_STATUS_CONTACT_CODE',
'RECEIVE_SNT_ALLOWANCE'
], 'ACCOUNTS')
export const actions = {
receiveAccounts: actionCreator(types.RECEIVE_ACCOUNTS, 'defaultAccount','accounts'),
updateDefaultAccount: actionCreator(types.UPDATE_DEFAULT_ACCOUNT, 'defaultAccount'),
addToSntTokenBalance: actionCreator(types.ADD_TO_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) {
@ -57,6 +59,10 @@ export default function(state = { loading: true, accounts: [] }, action) {
const { statusContactCode } = action.payload
return { ...state, statusContactCode }
}
case types.RECEIVE_SNT_ALLOWANCE: {
const { SNTAllowance } = action.payload
return { ...state, SNTAllowance }
}
default:
return state;
}

View File

@ -1,7 +1,7 @@
import web3 from "Embark/web3"
import EmbarkJS from 'Embark/EmbarkJS'
import store from './configureStore'
import { fetchAndDispatchAccountsWithBalances, checkAndDispatchStatusContactCode } from '../actions/accounts'
import { fetchAndDispatchSNTAllowance, fetchAndDispatchAccountsWithBalances, checkAndDispatchStatusContactCode } from '../actions/accounts'
const dispatch = action => store.dispatch(action)
@ -9,5 +9,6 @@ export default () => {
__embarkContext.execWhenReady(async () => {
fetchAndDispatchAccountsWithBalances(web3, dispatch)
checkAndDispatchStatusContactCode(dispatch)
fetchAndDispatchSNTAllowance(dispatch)
})
}