From 6b2e751ba8e2bfb4d09b04f701ce92e6657377ca Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Mon, 8 Oct 2018 15:25:42 -0400 Subject: [PATCH] change get contact code to new api --- app/actions/accounts.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/actions/accounts.js b/app/actions/accounts.js index 8fd8cd3..02492c9 100644 --- a/app/actions/accounts.js +++ b/app/actions/accounts.js @@ -8,9 +8,6 @@ import { isNil } from 'lodash' const { receiveAccounts, receiveStatusContactCode } = accountActions const CONTACT_CODE = 'CONTACT_CODE' -const STATUS_API_REQUEST = 'STATUS_API_REQUEST' -const hasContactCode = () => !isNil(STATUS_API) && !isNil(STATUS_API[CONTACT_CODE]) -const statusApiSuccess = event => event.detail.permissions[0] === CONTACT_CODE const getContactCode = event => event.detail.data[CONTACT_CODE] export const fetchAndDispatchAccountsWithBalances = (web3, dispatch) => { @@ -29,14 +26,14 @@ export const fetchAndDispatchAccountsWithBalances = (web3, dispatch) => { }) } export const checkAndDispatchStatusContactCode = dispatch => { - window.addEventListener('statusapi', function (event) { - if (statusApiSuccess(event)) dispatch(receiveStatusContactCode(getContactCode(event))) - }); - - setTimeout( - () => { window.postMessage({ type: STATUS_API_REQUEST, permissions: ["CONTACT_CODE", "CONTACTS"] }, '*') }, - 1000 - ) + window.web3.currentProvider.status + .getContactCode() + .then(data => { + dispatch(receiveStatusContactCode(getContactCode(data))); + }) + .catch(err => { + console.log('Error:', err); + }) } export const fetchAndDispatchSNTAllowance = dispatch => {