Skip to content

Commit

Permalink
Finance: use attached Vault's initialization block as starting block …
Browse files Browse the repository at this point in the history
…for events (#572)
  • Loading branch information
sohkai authored Dec 17, 2018
1 parent 352a5ce commit 9ceb28f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
14 changes: 14 additions & 0 deletions apps/finance/app/src/abi/vault-getinitializationblock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"constant": true,
"inputs": [],
"name": "getInitializationBlock",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
22 changes: 19 additions & 3 deletions apps/finance/app/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import tokenDecimalsAbi from './abi/token-decimals.json'
import tokenNameAbi from './abi/token-name.json'
import tokenSymbolAbi from './abi/token-symbol.json'
import vaultBalanceAbi from './abi/vault-balance.json'
import vaultGetInitializationBlockAbi from './abi/vault-getinitializationblock.json'
import vaultEventAbi from './abi/vault-events.json'

const tokenAbi = [].concat(tokenDecimalsAbi, tokenNameAbi, tokenSymbolAbi)
const vaultAbi = [].concat(vaultBalanceAbi, vaultEventAbi)
const vaultAbi = [].concat(
vaultBalanceAbi,
vaultGetInitializationBlockAbi,
vaultEventAbi
)

const INITIALIZATION_TRIGGER = Symbol('INITIALIZATION_TRIGGER')
const TEST_TOKEN_ADDRESSES = []
Expand Down Expand Up @@ -96,7 +101,18 @@ async function initialize(vaultAddress, ethAddress) {
}

// Hook up the script as an aragon.js store
function createStore(settings) {
async function createStore(settings) {
let vaultInitializationBlock

try {
vaultInitializationBlock = await settings.vault.contract
.getInitializationBlock()
.first()
.toPromise()
} catch (err) {
console.error("Could not get attached vault's initialization block:", err)
}

return app.store(
async (state, event) => {
const { vault } = settings
Expand Down Expand Up @@ -133,7 +149,7 @@ function createStore(settings) {
// Always initialize the store with our own home-made event
of({ event: INITIALIZATION_TRIGGER }),
// Handle Vault events in case they're not always controlled by this Finance app
settings.vault.contract.events(),
settings.vault.contract.events(vaultInitializationBlock),
]
)
}
Expand Down

0 comments on commit 9ceb28f

Please sign in to comment.