Skip to content

Commit

Permalink
feat(neuron-ui): handle current-wallet update and wallet-list update …
Browse files Browse the repository at this point in the history
…separately
  • Loading branch information
Keith-CY committed Aug 2, 2019
1 parent 5623f3b commit bd4c109
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/neuron-ui/src/containers/Main/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ export const useSubscription = ({
updateTransaction({ walletID, hash: txHash })
break
}
case 'wallet': {
case 'current-wallet': {
updateCurrentWallet()(dispatch)
break
}
case 'wallets': {
updateWalletList()(dispatch)
updateCurrentWallet()(dispatch)
break
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/types/Subject/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare namespace Subject {
}
interface DataUpdateMetaInfo {
walletID?: string
dataType: 'address' | 'transaction' | 'wallet' | 'network'
dataType: 'address' | 'transaction' | 'current-wallet' | 'wallets' | 'network'
actionType: 'create' | 'update' | 'delete'
}
type NetworkList = State.Network[]
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ app.on('ready', async () => {
WalletListSubject.pipe(debounceTime(50)).subscribe(({ currentWallet = null, currentWalletList = [] }) => {
const walletList = currentWalletList.map(({ id, name }) => ({ id, name }))
const currentWalletId = currentWallet ? currentWallet.id : null
dataUpdateSubject.next({ dataType: 'wallet', actionType: 'update' })
dataUpdateSubject.next({ dataType: 'wallets', actionType: 'update' })
updateApplicationMenu(walletList, currentWalletId)
})

CurrentWalletSubject.pipe(debounceTime(50)).subscribe(async ({ currentWallet = null, walletList = [] }) => {
updateApplicationMenu(walletList, currentWallet ? currentWallet.id : null)
if (currentWallet) {
dataUpdateSubject.next({ dataType: 'wallet', actionType: 'update' })
dataUpdateSubject.next({ dataType: 'current-wallet', actionType: 'update' })
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/models/subjects/data-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Subject } from 'rxjs'
import WindowManager from '../window-manager'

export const DataUpdateSubject = new Subject<{
dataType: 'address' | 'transaction' | 'wallet' | 'network'
dataType: 'address' | 'transaction' | 'wallets' | 'current-wallet' | 'network'
actionType: 'create' | 'update' | 'delete'
}>()

Expand Down
4 changes: 3 additions & 1 deletion packages/neuron-wallet/src/models/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default class WindowManager {
}
}

public static dataUpdated = (meta: { dataType: 'wallet' | 'address' | 'transaction' | 'network' }) => {
public static dataUpdated = (meta: {
dataType: 'current-wallet' | 'wallets' | 'address' | 'transaction' | 'network'
}) => {
if (WindowManager.mainWindow) {
WindowManager.mainWindow.webContents.send('data-updated', meta)
}
Expand Down

0 comments on commit bd4c109

Please sign in to comment.