Overview
DAOhaus uses higher-order functions to make calls on contracts instead of JS classes. The goal of this pattern is to minimize the state within the app as managing the state between the contract, React's contexts, and JS classes (previously used for contract interaction) was challenging and sometimes difficult to follow.
Each contract will usually carry three function calls from a service.
- Instantiation of a web3.js contract object.
await MolochService({
// web3: injectedProvider, <-- needed for write calls
daoAddress: daoid,
chainID: daochain,
version: daoOverview.version,
});
- Selection of service (function) on contract.
await MolochService({
...
})("collectTokens");
- Pass in args for handling post-process. This final call will execute the TX (except in the case of PollService).
await MolochService({
...
})("collectTokens")({ args, address, poll, onTxHash });
Here are the various services used throughout the app.
Moloch Service
await MolochService({
// web3: injectedProvider, <-- needed for write calls
daoAddress: daoid,
chainID: daochain,
version: daoOverview.version,
})("collectTokens")({ args, address, poll, onTxHash });
Token Service
await TokenService({
// web3: injectedProvider, <-- needed for write calls
tokenAddress: token,
chainID: daochain,
})("approve")({ args, address, poll, onTxHash });
Minion Service
await MinionService({
// web3: injectedProvider, <-- needed for write calls
minion: minionAddress,
chainID,
})("getAction")({ proposalId });
Summon (Moloch Factory) Service
await SummonService({
web3: injectedProvider, // always write
chainID: injectedChain.chain_id,
})("summonMoloch")({ args: summonParams, from: address, poll, onTxHash });
Minion Factory Service
await MinionFactoryService({
web3: injectedProvider, // always write
chainID: injectedChain.chain_id,
})("summonMinion")({ args: summonParams, from: address, poll, onTxHash });