mirror of
https://github.com/trezor/trezor-wallet
synced 2025-02-05 12:51:44 +00:00
wallet: navigator.onLine status
This commit is contained in:
parent
21a299fd0e
commit
9efe52b568
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import * as WALLET from './constants/wallet';
|
import * as WALLET from './constants/wallet';
|
||||||
|
|
||||||
import type { RouterLocationState } from '../flowtype';
|
import type { RouterLocationState, ThunkAction, Dispatch, GetState } from '../flowtype';
|
||||||
|
|
||||||
export type WalletAction = {
|
export type WalletAction = {
|
||||||
type: typeof WALLET.SET_INITIAL_URL,
|
type: typeof WALLET.SET_INITIAL_URL,
|
||||||
@ -14,6 +14,23 @@ export type WalletAction = {
|
|||||||
opened: boolean
|
opened: boolean
|
||||||
} | {
|
} | {
|
||||||
type: typeof WALLET.ON_BEFORE_UNLOAD
|
type: typeof WALLET.ON_BEFORE_UNLOAD
|
||||||
|
} | {
|
||||||
|
type: typeof WALLET.ONLINE_STATUS,
|
||||||
|
online: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const init = (): ThunkAction => {
|
||||||
|
return (dispatch: Dispatch, getState: GetState): void => {
|
||||||
|
|
||||||
|
const updateOnlineStatus = (event) => {
|
||||||
|
dispatch({
|
||||||
|
type: WALLET.ONLINE_STATUS,
|
||||||
|
online: navigator.onLine
|
||||||
|
})
|
||||||
|
}
|
||||||
|
window.addEventListener('online', updateOnlineStatus);
|
||||||
|
window.addEventListener('offline', updateOnlineStatus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onBeforeUnload = (): WalletAction => {
|
export const onBeforeUnload = (): WalletAction => {
|
||||||
|
@ -4,3 +4,4 @@
|
|||||||
export const ON_BEFORE_UNLOAD: 'wallet__on_before_unload' = 'wallet__on_before_unload';
|
export const ON_BEFORE_UNLOAD: 'wallet__on_before_unload' = 'wallet__on_before_unload';
|
||||||
export const TOGGLE_DEVICE_DROPDOWN: 'wallet__toggle_dropdown' = 'wallet__toggle_dropdown';
|
export const TOGGLE_DEVICE_DROPDOWN: 'wallet__toggle_dropdown' = 'wallet__toggle_dropdown';
|
||||||
export const SET_INITIAL_URL: 'wallet__set_initial_url' = 'wallet__set_initial_url';
|
export const SET_INITIAL_URL: 'wallet__set_initial_url' = 'wallet__set_initial_url';
|
||||||
|
export const ONLINE_STATUS: 'wallet__online_status' = 'wallet__online_status';
|
@ -15,13 +15,20 @@ import ModalContainer from '../modal';
|
|||||||
import Notifications from '../common/Notification';
|
import Notifications from '../common/Notification';
|
||||||
import Log from '../common/Log';
|
import Log from '../common/Log';
|
||||||
|
|
||||||
|
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
||||||
import type { State, Dispatch } from '../../flowtype';
|
import type { State, Dispatch } from '../../flowtype';
|
||||||
|
|
||||||
type Props = {
|
type WalletContainerProps = {
|
||||||
children: React.Node
|
wallet: $ElementType<State, 'wallet'>,
|
||||||
|
children?: React.Node
|
||||||
}
|
}
|
||||||
|
|
||||||
const Content = (props: Props) => {
|
type ContentProps = {
|
||||||
|
children?: React.Node
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Content = (props: ContentProps) => {
|
||||||
return (
|
return (
|
||||||
<article>
|
<article>
|
||||||
<nav>
|
<nav>
|
||||||
@ -36,10 +43,11 @@ const Content = (props: Props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Wallet = (props: Props) => {
|
const Wallet = (props: WalletContainerProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="app">
|
<div className="app">
|
||||||
<Header />
|
<Header />
|
||||||
|
{/* <div>{ props.wallet.online ? "ONLINE" : "OFFLINE" }</div> */}
|
||||||
<main>
|
<main>
|
||||||
<AsideContainer />
|
<AsideContainer />
|
||||||
<Content>
|
<Content>
|
||||||
@ -51,6 +59,12 @@ const Wallet = (props: Props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapStateToProps: MapStateToProps<State, {}, WalletContainerProps> = (state: State, own: {}): WalletContainerProps => {
|
||||||
|
return {
|
||||||
|
wallet: state.wallet
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default withRouter(
|
export default withRouter(
|
||||||
connect(null, null)(Wallet)
|
connect(mapStateToProps, null)(Wallet)
|
||||||
);
|
);
|
||||||
|
@ -13,6 +13,7 @@ import type { Action, RouterLocationState, TrezorDevice } from '../flowtype';
|
|||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
ready: boolean;
|
ready: boolean;
|
||||||
|
online: boolean;
|
||||||
dropdownOpened: boolean;
|
dropdownOpened: boolean;
|
||||||
initialParams: ?RouterLocationState;
|
initialParams: ?RouterLocationState;
|
||||||
initialPathname: ?string;
|
initialPathname: ?string;
|
||||||
@ -21,6 +22,7 @@ type State = {
|
|||||||
|
|
||||||
const initialState: State = {
|
const initialState: State = {
|
||||||
ready: false,
|
ready: false,
|
||||||
|
online: navigator.onLine,
|
||||||
dropdownOpened: false,
|
dropdownOpened: false,
|
||||||
initialParams: null,
|
initialParams: null,
|
||||||
initialPathname: null,
|
initialPathname: null,
|
||||||
@ -43,6 +45,12 @@ export default function wallet(state: State = initialState, action: Action): Sta
|
|||||||
ready: true
|
ready: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case WALLET.ONLINE_STATUS :
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
online: action.online
|
||||||
|
}
|
||||||
|
|
||||||
case WALLET.TOGGLE_DEVICE_DROPDOWN :
|
case WALLET.TOGGLE_DEVICE_DROPDOWN :
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import * as LocalStorageActions from '../actions/LocalStorageActions';
|
import * as LocalStorageActions from '../actions/LocalStorageActions';
|
||||||
|
import * as WalletActions from '../actions/WalletActions';
|
||||||
|
|
||||||
import { DEVICE } from 'trezor-connect';
|
import { DEVICE } from 'trezor-connect';
|
||||||
import * as CONNECT from '../actions/constants/TrezorConnect';
|
import * as CONNECT from '../actions/constants/TrezorConnect';
|
||||||
@ -90,6 +91,7 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar
|
|||||||
if (action.type === LOCATION_CHANGE) {
|
if (action.type === LOCATION_CHANGE) {
|
||||||
const { location } = api.getState().router;
|
const { location } = api.getState().router;
|
||||||
if (!location) {
|
if (!location) {
|
||||||
|
api.dispatch( WalletActions.init() );
|
||||||
// load data from config.json and local storage
|
// load data from config.json and local storage
|
||||||
api.dispatch( LocalStorageActions.loadData() );
|
api.dispatch( LocalStorageActions.loadData() );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user