Skip to content

Commit

Permalink
feat(neuron-ui): close the tx detail dialog on wallet switching
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Aug 2, 2019
1 parent bea4b20 commit 5623f3b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/neuron-ui/src/components/Transaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { RouteComponentProps } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Stack, DetailsList, Text, DetailsListLayoutMode, CheckboxVisibility, IColumn } from 'office-ui-fabric-react'

import { isMainWindow, getWinID } from 'services/remote'

import { AppActions, StateWithDispatch } from 'states/stateProvider/reducer'
import { updateTransaction } from 'states/stateProvider/actionCreators'
import chainState from 'states/initStates/chain'
Expand Down Expand Up @@ -101,6 +103,11 @@ const Transaction = ({
dispatch,
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps<{ hash: string }>>) => {
const [t] = useTranslation()
useEffect(() => {
if ((walletID && !isMainWindow(getWinID())) || !walletID) {
window.close()
}
}, [walletID])

useEffect(() => {
dispatch({
Expand Down
5 changes: 5 additions & 0 deletions packages/neuron-ui/src/services/remote/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ export const showTransactionDetails = controllerMethodWrapper(CONTROLLER_NAME)(c
controller.showTransactionDetails(hash)
)

export const isMainWindow = controllerMethodWrapper(CONTROLLER_NAME)(controller => (winID: number) =>
controller.isMainWindow(winID)
)

export default {
getNeuronWalletState,
handleViewError,
contextMenu,
showTransactionDetails,
isMainWindow,
}
4 changes: 4 additions & 0 deletions packages/neuron-wallet/src/controllers/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export default class AppController {
}
}

public static isMainWindow = (winID: number) => {
return WindowManager.mainWindow && winID === WindowManager.mainWindow.id
}

public static showMessageBox(
options: MessageBoxOptions,
callback?: (response: number, checkboxChecked: boolean) => void
Expand Down

0 comments on commit 5623f3b

Please sign in to comment.