Skip to content

Commit

Permalink
feat: Send address db changed event when address store
Browse files Browse the repository at this point in the history
updates any content
  • Loading branch information
ashchan committed Nov 13, 2019
1 parent 6003676 commit 617a9a3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/neuron-wallet/src/database/address/dao.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { remote } from 'electron'
import { AddressType } from 'models/keys/address'
import { TransactionsService } from 'services/tx'
import CellsService from 'services/cells'
Expand All @@ -7,6 +8,7 @@ import { OutputStatus } from 'services/tx/params'
import { AddressVersion } from './entities/address'
import NodeService from 'services/node'
import Store from 'models/store'
import AddressDbChangedSubject from 'models/subjects/address-db-changed-subject'

export interface Address {
walletId: string
Expand Down Expand Up @@ -183,6 +185,11 @@ export default class AddressDao {
}
}

const isRenderer = process && process.type === 'renderer'
const addressDbChangedSubject = isRenderer
? remote.require('./models/subjects/address-db-changed-subject').default.getSubject()
: AddressDbChangedSubject.getSubject()

/// Persist all addresses as array in `addresses/index.json`.
class AddressStore {
static MODULE_NAME = 'addresses'
Expand All @@ -196,6 +203,7 @@ class AddressStore {

static updateAll(addresses: Address[]) {
AddressStore.store.writeSync(AddressStore.ROOT_KEY, addresses)
AddressStore.changed()
}

static add(addresses: Address[]): Address[] {
Expand Down Expand Up @@ -224,4 +232,8 @@ class AddressStore {

return address
}

static changed() {
addressDbChangedSubject.next("Updated")
}
}

0 comments on commit 617a9a3

Please sign in to comment.