diff --git a/package.json b/package.json index 4b97ea2..ede115c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ezerous/drizzle", - "version": "0.4.3", + "version": "0.5.0", "description": "A reactive data-store for web3 and smart contracts.", "license": "MIT", "author": "Ezerous ", diff --git a/src/DrizzleContract.js b/src/DrizzleContract.js index 70f0d8e..22844e6 100644 --- a/src/DrizzleContract.js +++ b/src/DrizzleContract.js @@ -25,6 +25,7 @@ class DrizzleContract { var item = this.abi[i] if (isGetterFunction(item)) { this.methods[item.name].cacheCall = this.cacheCallFunction(item.name, i) + this.methods[item.name].clearCacheCall = this.clearCacheCallFunction(item.name, i) } if (isSetterFunction(item)) { this.methods[item.name].cacheSend = this.cacheSendFunction(item.name, i) @@ -55,16 +56,13 @@ class DrizzleContract { } cacheCallFunction (fnName, fnIndex, fn) { - var contract = this + const contract = this return function () { // Collect args and hash to use as key, 0x0 if no args - var argsHash = '0x0' - var args = arguments + const args = arguments + const argsHash = args.length > 0 ? contract.generateArgsHash(args) : '0x0' - if (args.length > 0) { - argsHash = contract.generateArgsHash(args) - } const contractName = contract.contractName const functionState = contract.store.getState().contracts[contractName][ fnName @@ -92,6 +90,21 @@ class DrizzleContract { } } + clearCacheCallFunction (fnName, fnIndex) { + const contract = this + return function () { + // Collect args and hash to use as key, 0x0 if no args + const args = arguments + const argsHash = args.length > 0 ? contract.generateArgsHash(args) : '0x0' + contract.store.dispatch({ + type: ContractActions.CLEAR_CALL_CONTRACT_FN, + contractName: contract.contractName, + fnName, + argsHash + }) + } + } + cacheSendFunction (fnName, fnIndex, fn) { // NOTE: May not need fn index var contract = this diff --git a/src/contracts/constants.js b/src/contracts/constants.js index 58f51b8..4af5a39 100644 --- a/src/contracts/constants.js +++ b/src/contracts/constants.js @@ -12,6 +12,7 @@ export const CONTRACT_SYNCED = 'CONTRACT_SYNCED' export const CONTRACT_SYNC_IND = 'CONTRACT_SYNC_IND' export const ERROR_CONTRACT_VAR = 'ERROR_CONTRACT_VAR' export const CALL_CONTRACT_FN = 'CALL_CONTRACT_FN' +export const CLEAR_CALL_CONTRACT_FN = 'CLEAR_CALL_CONTRACT_FN' export const SEND_CONTRACT_TX = 'SEND_CONTRACT_TX' export const ADD_CONTRACT = 'ADD_CONTRACT' export const ERROR_ADD_CONTRACT = 'ERROR_ADD_CONTRACT' diff --git a/src/contracts/contractsReducer.js b/src/contracts/contractsReducer.js index a075c53..af54641 100644 --- a/src/contracts/contractsReducer.js +++ b/src/contracts/contractsReducer.js @@ -100,6 +100,30 @@ const contractsReducer = (state = initialState, action) => { } } + if (action.type === ContractActions.CLEAR_CALL_CONTRACT_FN) { + const { argsHash, contractName, fnName } = action; + if(argsHash !== '0x0'){ + const {[argsHash]: _, ...remainingHashes} = state[contractName][fnName]; + return { + ...state, + [contractName]: { + ...state[contractName], + [fnName]: { + ...remainingHashes + } + } + } + } + + return { + ...state, + [contractName]: { + ...state[contractName], + [fnName]: { } + } + } + } + if (action.type === ContractActions.ERROR_CONTRACT_VAR) { return { ...state,