From 4ca9dfb5922bba169e5b520089df8f6335a1649f Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Tue, 14 Aug 2018 10:10:31 -0400 Subject: [PATCH] Add SNT allowance to redux store --- app/actions/accounts.js | 17 ++++++++++++++++- app/reducers/accounts.js | 10 ++++++++-- app/store/init.js | 3 ++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/actions/accounts.js b/app/actions/accounts.js index 8ab8599..757199a 100644 --- a/app/actions/accounts.js +++ b/app/actions/accounts.js @@ -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)) + }) +} diff --git a/app/reducers/accounts.js b/app/reducers/accounts.js index d6a4547..b97ee28 100644 --- a/app/reducers/accounts.js +++ b/app/reducers/accounts.js @@ -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; } diff --git a/app/store/init.js b/app/store/init.js index e133b7f..6f85448 100644 --- a/app/store/init.js +++ b/app/store/init.js @@ -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) }) }