diff --git a/__mocks__/dataMocks/mockAddresses.ts b/__mocks__/dataMocks/mockAddresses.ts index 187b16793..edabd33a4 100644 --- a/__mocks__/dataMocks/mockAddresses.ts +++ b/__mocks__/dataMocks/mockAddresses.ts @@ -5,21 +5,18 @@ export const mockAddresses: AddressClass[] = [ uaAddress: 'UA-12345678901234567890', address: 'UA-12345678901234567890', addressKind: AddressKindEnum.u, - containsPending: false, receivers: ReceiverEnum.o + ReceiverEnum.z + ReceiverEnum.t, }, { uaAddress: 'UA-12345678901234567890', address: 'sapling-12345678901234567890', addressKind: AddressKindEnum.z, - containsPending: false, receivers: ReceiverEnum.z, }, { uaAddress: 'UA-12345678901234567890', address: 'transparent-12345678901234567890', addressKind: AddressKindEnum.t, - containsPending: false, receivers: ReceiverEnum.t, }, ]; diff --git a/__tests__/Send.snapshot.tsx b/__tests__/Send.snapshot.tsx index fef504880..9b4c31408 100644 --- a/__tests__/Send.snapshot.tsx +++ b/__tests__/Send.snapshot.tsx @@ -100,6 +100,8 @@ describe('Component Send - test', () => { setScrollToTop={onFunction} setScrollToBottom={onFunction} setServerOption={onFunction} + clearTimers={onFunction} + configure={onFunction} /> , ); @@ -130,6 +132,8 @@ describe('Component Send - test', () => { setScrollToTop={onFunction} setScrollToBottom={onFunction} setServerOption={onFunction} + clearTimers={onFunction} + configure={onFunction} /> , ); diff --git a/__tests__/__snapshots__/Header.snapshot.tsx.snap b/__tests__/__snapshots__/Header.snapshot.tsx.snap index 80ed7e9a9..feaa36073 100644 --- a/__tests__/__snapshots__/Header.snapshot.tsx.snap +++ b/__tests__/__snapshots__/Header.snapshot.tsx.snap @@ -32,139 +32,71 @@ exports[`Component Header - test Header Complex - snapshot 1`] = ` style={ { "alignItems": "center", - "borderColor": undefined, - "borderRadius": 10, - "borderWidth": 1, "justifyContent": "center", "margin": 0, "marginRight": 5, "minHeight": 25, "minWidth": 25, - "padding": 1, + "padding": 0, } } > - - < - icon={ - { - "icon": [ - 640, - 512, - [ - "wifi-3", - "wifi-strong", - ], - "f1eb", - "M54.2 202.9C123.2 136.7 216.8 96 320 96s196.8 40.7 265.8 106.9c12.8 12.2 33 11.8 45.2-.9s11.8-33-.9-45.2C549.7 79.5 440.4 32 320 32S90.3 79.5 9.8 156.7C-2.9 169-3.3 189.2 8.9 202s32.5 13.2 45.2 .9zM320 256c56.8 0 108.6 21.1 148.2 56c13.3 11.7 33.5 10.4 45.2-2.8s10.4-33.5-2.8-45.2C459.8 219.2 393 192 320 192s-139.8 27.2-190.5 72c-13.3 11.7-14.5 31.9-2.8 45.2s31.9 14.5 45.2 2.8c39.5-34.9 91.3-56 148.2-56zm64 160a64 64 0 1 0 -128 0 64 64 0 1 0 128 0z", + "icon": [ + 640, + 512, + [ + 62337, + "cloud-download", + "cloud-download-alt", ], - "iconName": "wifi", - "prefix": "fas", - } - } - size={18} - /> - - - - - < - color="red" - icon={ - { - "icon": [ - 640, - 512, - [ - 62337, - "cloud-download", - "cloud-download-alt", + "f0ed", + "M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9c-.1-2.7-.2-5.4-.2-8.1c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128l-368 0zm79-167l80 80c9.4 9.4 24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-39 39L344 184c0-13.3-10.7-24-24-24s-24 10.7-24 24l0 134.1-39-39c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9z", ], - "f0ed", - "M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9c-.1-2.7-.2-5.4-.2-8.1c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128l-368 0zm79-167l80 80c9.4 9.4 24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-39 39L344 184c0-13.3-10.7-24-24-24s-24 10.7-24 24l0 134.1-39-39c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9z", - ], - "iconName": "cloud-arrow-down", - "prefix": "fas", + "iconName": "cloud-arrow-down", + "prefix": "fas", + } } - } - size={20} - /> + size={20} + /> + - - < - color="#5a8c5a" - icon={ - { - "icon": [ - 640, - 512, - [ - "wifi-3", - "wifi-strong", - ], - "f1eb", - "M54.2 202.9C123.2 136.7 216.8 96 320 96s196.8 40.7 265.8 106.9c12.8 12.2 33 11.8 45.2-.9s11.8-33-.9-45.2C549.7 79.5 440.4 32 320 32S90.3 79.5 9.8 156.7C-2.9 169-3.3 189.2 8.9 202s32.5 13.2 45.2 .9zM320 256c56.8 0 108.6 21.1 148.2 56c13.3 11.7 33.5 10.4 45.2-2.8s10.4-33.5-2.8-45.2C459.8 219.2 393 192 320 192s-139.8 27.2-190.5 72c-13.3 11.7-14.5 31.9-2.8 45.2s31.9 14.5 45.2 2.8c39.5-34.9 91.3-56 148.2-56zm64 160a64 64 0 1 0 -128 0 64 64 0 1 0 128 0z", + "icon": [ + 640, + 512, + [ + 62337, + "cloud-download", + "cloud-download-alt", ], - "iconName": "wifi", - "prefix": "fas", - } - } - size={18} - /> - - - - - < - color="red" - icon={ - { - "icon": [ - 640, - 512, - [ - 62337, - "cloud-download", - "cloud-download-alt", + "f0ed", + "M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9c-.1-2.7-.2-5.4-.2-8.1c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128l-368 0zm79-167l80 80c9.4 9.4 24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-39 39L344 184c0-13.3-10.7-24-24-24s-24 10.7-24 24l0 134.1-39-39c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9z", ], - "f0ed", - "M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9c-.1-2.7-.2-5.4-.2-8.1c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128l-368 0zm79-167l80 80c9.4 9.4 24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-39 39L344 184c0-13.3-10.7-24-24-24s-24 10.7-24 24l0 134.1-39-39c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9z", - ], - "iconName": "cloud-arrow-down", - "prefix": "fas", + "iconName": "cloud-arrow-down", + "prefix": "fas", + } } - } - size={20} - /> + size={20} + /> + + > + + < + color="red" + icon={ + { + "icon": [ + 640, + 512, + [ + 62337, + "cloud-download", + "cloud-download-alt", + ], + "f0ed", + "M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9c-.1-2.7-.2-5.4-.2-8.1c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128l-368 0zm79-167l80 80c9.4 9.4 24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-39 39L344 184c0-13.3-10.7-24-24-24s-24 10.7-24 24l0 134.1-39-39c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9z", + ], + "iconName": "cloud-arrow-down", + "prefix": "fas", + } + } + size={20} + /> + + - - < - color="#5a8c5a" - icon={ - { - "icon": [ - 640, - 512, - [ - "wifi-3", - "wifi-strong", - ], - "f1eb", - "M54.2 202.9C123.2 136.7 216.8 96 320 96s196.8 40.7 265.8 106.9c12.8 12.2 33 11.8 45.2-.9s11.8-33-.9-45.2C549.7 79.5 440.4 32 320 32S90.3 79.5 9.8 156.7C-2.9 169-3.3 189.2 8.9 202s32.5 13.2 45.2 .9zM320 256c56.8 0 108.6 21.1 148.2 56c13.3 11.7 33.5 10.4 45.2-2.8s10.4-33.5-2.8-45.2C459.8 219.2 393 192 320 192s-139.8 27.2-190.5 72c-13.3 11.7-14.5 31.9-2.8 45.2s31.9 14.5 45.2 2.8c39.5-34.9 91.3-56 148.2-56zm64 160a64 64 0 1 0 -128 0 64 64 0 1 0 128 0z", + "icon": [ + 640, + 512, + [ + 62337, + "cloud-download", + "cloud-download-alt", ], - "iconName": "wifi", - "prefix": "fas", - } - } - size={18} - /> - - - - - < - color="red" - icon={ - { - "icon": [ - 640, - 512, - [ - 62337, - "cloud-download", - "cloud-download-alt", + "f0ed", + "M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9c-.1-2.7-.2-5.4-.2-8.1c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128l-368 0zm79-167l80 80c9.4 9.4 24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-39 39L344 184c0-13.3-10.7-24-24-24s-24 10.7-24 24l0 134.1-39-39c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9z", ], - "f0ed", - "M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9c-.1-2.7-.2-5.4-.2-8.1c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128l-368 0zm79-167l80 80c9.4 9.4 24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-39 39L344 184c0-13.3-10.7-24-24-24s-24 10.7-24 24l0 134.1-39-39c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9z", - ], - "iconName": "cloud-arrow-down", - "prefix": "fas", + "iconName": "cloud-arrow-down", + "prefix": "fas", + } } - } - size={20} - /> + size={20} + /> + + > + + < + color="red" + icon={ + { + "icon": [ + 640, + 512, + [ + 62337, + "cloud-download", + "cloud-download-alt", + ], + "f0ed", + "M144 480C64.5 480 0 415.5 0 336c0-62.8 40.2-116.2 96.2-135.9c-.1-2.7-.2-5.4-.2-8.1c0-88.4 71.6-160 160-160c59.3 0 111 32.2 138.7 80.2C409.9 102 428.3 96 448 96c53 0 96 43 96 96c0 12.2-2.3 23.8-6.4 34.6C596 238.4 640 290.1 640 352c0 70.7-57.3 128-128 128l-368 0zm79-167l80 80c9.4 9.4 24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-39 39L344 184c0-13.3-10.7-24-24-24s-24 10.7-24 24l0 134.1-39-39c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9z", + ], + "iconName": "cloud-arrow-down", + "prefix": "fas", + } + } + size={20} + /> + + + + + + < + color="rgb(216, 216, 216)" + icon={ + { + "icon": [ + 512, + 512, + [ + 128308, + 128309, + 128992, + 128993, + 128994, + 128995, + 128996, + 9679, + 9898, + 9899, + 11044, + 61708, + 61915, + ], + "f111", + "M464 256A208 208 0 1 0 48 256a208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256z", + ], + "iconName": "circle", + "prefix": "far", + } + } + size={20} + /> + + text translated + + + + + + + text translated + + { - //console.log('LOADED', 'prior', this.state.appState, 'next', nextAppState); + //console.log('LOADED', 'prior', this.state.appStateStatus, 'next', nextAppState); + // let's catch the prior value + const priorAppState = this.state.appStateStatus; if (Platform.OS === GlobalConst.platformOSios) { if ( - (this.state.appStateStatus === AppStateStatusEnum.inactive && nextAppState === AppStateStatusEnum.active) || - (this.state.appStateStatus === AppStateStatusEnum.active && nextAppState === AppStateStatusEnum.inactive) + (priorAppState === AppStateStatusEnum.inactive && nextAppState === AppStateStatusEnum.active) || + (priorAppState === AppStateStatusEnum.active && nextAppState === AppStateStatusEnum.inactive) ) { //console.log('LOADED SAVED IOS do nothing', nextAppState); this.setState({ appStateStatus: nextAppState }); return; } - if ( - this.state.appStateStatus === AppStateStatusEnum.inactive && - nextAppState === AppStateStatusEnum.background - ) { + if (priorAppState === AppStateStatusEnum.inactive && nextAppState === AppStateStatusEnum.background) { //console.log('App LOADED IOS is gone to the background!'); + this.setState({ appStateStatus: nextAppState }); // re-activate the interruption sync flag await RPC.rpcSetInterruptSyncAfterBatch(GlobalConst.true); // setting value for background task Android @@ -514,13 +517,17 @@ export class LoadedAppClass extends Component => { + setServerOption = async ( + value: ServerType, + selectServer: SelectServerEnum, + toast: boolean, + sameServerChainName: boolean, + ): Promise => { // here I know the server was changed, clean all the tasks before anything. await this.rpc.clearTimers(); this.setSyncingStatus(new SyncingStatusClass()); @@ -1185,7 +1198,7 @@ export class LoadedAppClass extends Component { + await this.rpc.clearTimers(); + }; + + configure = async () => { + await this.rpc.configure(); + }; + onClickOKChangeWallet = async (state: any) => { const { server } = this.state; @@ -1390,8 +1415,10 @@ export class LoadedAppClass extends Component { - if (this.state.newServer) { + if (this.state.newServer && this.state.newSelectServer) { const beforeServer = this.state.server; - const resultStr: string = await RPCModule.execute(CommandEnum.changeserver, this.state.newServer.uri); - if (resultStr.toLowerCase().startsWith(GlobalConst.error)) { + + const resultStrServerPromise = RPCModule.execute(CommandEnum.changeserver, this.state.newServer.uri); + const timeoutServerPromise = new Promise((_, reject) => { + setTimeout(() => { + reject(new Error('Promise changeserver Timeout 30 seconds')); + }, 30000); + }); + + const resultStrServer: string = await Promise.race([resultStrServerPromise, timeoutServerPromise]); + //console.log(resultStrServer); + + if (!resultStrServer || resultStrServer.toLowerCase().startsWith(GlobalConst.error)) { //console.log(`Error change server ${value} - ${resultStr}`); this.addLastSnackbar({ - message: `${this.state.translate('loadedapp.changeservernew-error')} ${resultStr}`, + message: `${this.state.translate('loadedapp.changeservernew-error')} ${resultStrServer}`, }); return; } else { @@ -1457,9 +1494,12 @@ export class LoadedAppClass extends Component {!readOnly && + selectServer !== SelectServerEnum.offline && (mode === ModeEnum.advanced || (!!totalBalance && totalBalance.spendableOrchard + totalBalance.spendablePrivate > 0) || (!!totalBalance && @@ -2015,6 +2057,8 @@ export class LoadedAppClass extends Component )} diff --git a/app/LoadedApp/components/Menu.tsx b/app/LoadedApp/components/Menu.tsx index 2d797be9b..d3089c00d 100644 --- a/app/LoadedApp/components/Menu.tsx +++ b/app/LoadedApp/components/Menu.tsx @@ -13,7 +13,7 @@ import moment from 'moment'; import 'moment/locale/es'; import 'moment/locale/pt'; import 'moment/locale/ru'; -import { GlobalConst, MenuItemEnum, ModeEnum } from '../../AppState'; +import { GlobalConst, MenuItemEnum, ModeEnum, SelectServerEnum } from '../../AppState'; type MenuProps = { onItemSelected: (item: MenuItemEnum) => Promise; @@ -22,7 +22,18 @@ type MenuProps = { const Menu: React.FunctionComponent = ({ onItemSelected, updateMenuState }) => { const context = useContext(ContextAppLoaded); - const { translate, readOnly, mode, valueTransfers, addLastSnackbar, security, language, rescanMenu } = context; + const { + translate, + readOnly, + mode, + valueTransfers, + addLastSnackbar, + security, + language, + rescanMenu, + selectServer, + netInfo, + } = context; const { colors } = useTheme() as unknown as ThemeType; moment.locale(language); @@ -89,7 +100,7 @@ const Menu: React.FunctionComponent = ({ onItemSelected, updateMenuSt {translate('loadedapp.about') as string} - {mode !== ModeEnum.basic && ( + {mode !== ModeEnum.basic && selectServer !== SelectServerEnum.offline && ( onItemSelectedWrapper(MenuItemEnum.Info)} style={item}> {translate('loadedapp.info') as string} @@ -121,13 +132,13 @@ const Menu: React.FunctionComponent = ({ onItemSelected, updateMenuSt )} - {mode !== ModeEnum.basic && rescanMenu && ( + {mode !== ModeEnum.basic && rescanMenu && selectServer !== SelectServerEnum.offline && ( onItemSelectedWrapper(MenuItemEnum.Rescan)} style={item}> {translate('loadedapp.rescanwallet') as string} )} - {mode !== ModeEnum.basic && ( + {mode !== ModeEnum.basic && selectServer !== SelectServerEnum.offline && ( onItemSelectedWrapper(MenuItemEnum.SyncReport)} @@ -148,7 +159,7 @@ const Menu: React.FunctionComponent = ({ onItemSelected, updateMenuSt )} - {mode !== ModeEnum.basic && ( + {mode !== ModeEnum.basic && netInfo.isConnected && selectServer !== SelectServerEnum.offline && ( onItemSelectedWrapper(MenuItemEnum.ChangeWallet)} @@ -165,15 +176,19 @@ const Menu: React.FunctionComponent = ({ onItemSelected, updateMenuSt {translate('loadedapp.restorebackupwallet') as string} )} - {mode === ModeEnum.basic && valueTransfers && valueTransfers.length === 0 && ( - onItemSelectedWrapper(MenuItemEnum.LoadWalletFromSeed)} - style={item}> - {translate('loadedapp.loadwalletfromseed-basic') as string} - - )} - {mode === ModeEnum.basic && !readOnly && ( + {mode === ModeEnum.basic && + valueTransfers && + valueTransfers.length === 0 && + netInfo.isConnected && + selectServer !== SelectServerEnum.offline && ( + onItemSelectedWrapper(MenuItemEnum.LoadWalletFromSeed)} + style={item}> + {translate('loadedapp.loadwalletfromseed-basic') as string} + + )} + {mode === ModeEnum.basic && !readOnly && selectServer !== SelectServerEnum.offline && ( onItemSelectedWrapper(MenuItemEnum.TipZingoLabs)} @@ -181,7 +196,7 @@ const Menu: React.FunctionComponent = ({ onItemSelected, updateMenuSt {translate('loadedapp.tipzingolabs-basic') as string} )} - {mode !== ModeEnum.basic && !readOnly && ( + {mode !== ModeEnum.basic && !readOnly && selectServer !== SelectServerEnum.offline && ( onItemSelectedWrapper(MenuItemEnum.VoteForNym)} diff --git a/app/LoadingApp/LoadingApp.tsx b/app/LoadingApp/LoadingApp.tsx index bda4d7881..eaaa2797d 100644 --- a/app/LoadingApp/LoadingApp.tsx +++ b/app/LoadingApp/LoadingApp.tsx @@ -14,6 +14,7 @@ import { NativeEventSubscription, TextInput, ActivityIndicator, + TouchableOpacity, } from 'react-native'; import Clipboard from '@react-native-community/clipboard'; import { useTheme } from '@react-navigation/native'; @@ -25,7 +26,7 @@ import NetInfo, { NetInfoStateType, NetInfoSubscription } from '@react-native-co import OptionsMenu from 'react-native-option-menu'; import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'; -import { faEllipsisV } from '@fortawesome/free-solid-svg-icons'; +import { faEllipsisV, faWifi } from '@fortawesome/free-solid-svg-icons'; import RPCModule from '../RPCModule'; import { @@ -90,6 +91,7 @@ import ImportUfvk from '../../components/Ufvk/ImportUfvk'; import ChainTypeToggle from '../../components/Components/ChainTypeToggle'; import { sendEmail } from '../sendEmail'; import { RPCWalletKindEnum } from '../rpc/enums/RPCWalletKindEnum'; +import FadeText from '../../components/Components/FadeText'; const en = require('../translations/en.json'); const es = require('../translations/es.json'); @@ -252,7 +254,8 @@ export default function LoadingApp(props: LoadingAppProps) { if ( settings.selectServer === SelectServerEnum.auto || settings.selectServer === SelectServerEnum.custom || - settings.selectServer === SelectServerEnum.list + settings.selectServer === SelectServerEnum.list || + settings.selectServer === SelectServerEnum.offline ) { setSelectServer(settings.selectServer); } else { @@ -389,6 +392,7 @@ export class LoadingAppClass extends Component create a new wallet & go directly to history screen. // no seed screen. - this.createNewWallet(false); - this.setState({ actionButtonsDisabled: false }); - this.navigateToLoadedApp(); - //console.log('navigate to LoadedApp'); + if (!netInfoState.isConnected || this.state.selectServer === SelectServerEnum.offline) { + this.setState({ + screen: 1, + walletExists: false, + actionButtonsDisabled: false, + }); + } else { + this.createNewWallet(false); + this.setState({ actionButtonsDisabled: false }); + this.navigateToLoadedApp(); + //console.log('navigate to LoadedApp'); + } } } else { // if no wallet file & advanced mode -> go to the initial menu. @@ -625,13 +630,15 @@ export class LoadingAppClass extends Component { - //console.log('LOADING', 'next', nextAppState, 'prior', this.state.appState); + //console.log('LOADING', 'prior', this.state.appStateStatus, 'next', nextAppState); + // let's catch the prior value + const priorAppState = this.state.appStateStatus; + this.setState({ appStateStatus: nextAppState }); if ( - (this.state.appStateStatus === AppStateStatusEnum.inactive || - this.state.appStateStatus === AppStateStatusEnum.background) && + (priorAppState === AppStateStatusEnum.inactive || priorAppState === AppStateStatusEnum.background) && nextAppState === AppStateStatusEnum.active ) { - //console.log('App LOADING has come to the foreground!'); + console.log('App LOADING has come to the foreground!'); // reading background task info this.fetchBackgroundSyncing(); // setting value for background task Android @@ -643,13 +650,12 @@ export class LoadingAppClass extends Component { @@ -667,25 +673,42 @@ export class LoadingAppClass extends Component this.componentDidMount(), 1000); + this.setState({ + screen: screen === 3 ? 3 : screen !== 0 ? 1 : 0, + }); } } } } }); + + // if it is offline & there is no wallet file + // the screen is going to be empty + // show the custom server component + if (netInfoState.isConnected && this.state.selectServer === SelectServerEnum.offline && !this.state.walletExists) { + this.setState({ + customServerShow: true, + }); + } }; componentWillUnmount = () => { @@ -779,15 +802,15 @@ export class LoadingAppClass extends Component { // first check the actual server // if the server is not working properly sometimes can take more than one minute to fail. - if (start) { + if (start && this.state.netInfo.isConnected && this.state.selectServer !== SelectServerEnum.offline) { this.addLastSnackbar({ message: this.state.translate('restarting') as string, duration: SnackbarDurationEnum.long, }); } - const workingServer = await this.checkServer(this.state.server); - if (workingServer) { - // the server is working -> this error is something not related with the server availability + // if no internet connection -> show the error. + // if Offline mode -> show the error. + if (!this.state.netInfo.isConnected || this.state.selectServer === SelectServerEnum.offline) { createAlert( this.setBackgroundError, this.addLastSnackbar, @@ -800,30 +823,58 @@ export class LoadingAppClass extends Component this error is something not related with the server availability + createAlert( + this.setBackgroundError, + this.addLastSnackbar, + title, + result, + false, + this.state.translate, + sendEmail, + this.state.info.zingolib, + ); + this.setState({ actionButtonsDisabled: false, serverErrorTries: 0, screen }); + } else { + // let's change to another server + if (this.state.serverErrorTries === 0) { + // first try + this.setState({ screen, actionButtonsDisabled: true }); + this.addLastSnackbar({ + message: this.state.translate('loadingapp.serverfirsttry') as string, + duration: SnackbarDurationEnum.longer, + }); + // a different server. + const someServerIsWorking = await this.selectTheBestServer(true); + if (someServerIsWorking) { + if (start) { + this.setState({ + startingApp: false, + serverErrorTries: 1, + screen, + }); + this.componentDidMount(); + } else { + createAlert( + this.setBackgroundError, + this.addLastSnackbar, + title, + result, + false, + this.state.translate, + sendEmail, + this.state.info.zingolib, + ); + this.setState({ actionButtonsDisabled: false, serverErrorTries: 0, screen }); + } } else { createAlert( this.setBackgroundError, this.addLastSnackbar, title, - result, + this.state.translate('loadingapp.noservers') as string, false, this.state.translate, sendEmail, @@ -832,37 +883,25 @@ export class LoadingAppClass extends Component { + createAlert( + this.setBackgroundError, + this.addLastSnackbar, + title, + result, + false, + this.state.translate, + sendEmail, + this.state.info.zingolib, + ); + this.setState({ actionButtonsDisabled: false, serverErrorTries: 0, screen }); + }, 1000); } - } else { - // second try - this.addLastSnackbar({ - message: this.state.translate('loadingapp.serversecondtry') as string, - duration: SnackbarDurationEnum.longer, - }); - setTimeout(() => { - createAlert( - this.setBackgroundError, - this.addLastSnackbar, - title, - result, - false, - this.state.translate, - sendEmail, - this.state.info.zingolib, - ); - this.setState({ actionButtonsDisabled: false, serverErrorTries: 0, screen }); - }, 1000); } } }; @@ -875,41 +914,60 @@ export class LoadingAppClass extends Component { - if (!this.state.customServerUri) { + if (!this.state.customServerUri && !this.state.customServerOffline) { return; } this.setState({ actionButtonsDisabled: true }); - const uri: string = parseServerURI(this.state.customServerUri, this.state.translate); - const chainName = this.state.customServerChainName; - if (uri.toLowerCase().startsWith(GlobalConst.error)) { - this.addLastSnackbar({ message: this.state.translate('settings.isuri') as string }); - this.setState({ actionButtonsDisabled: false }); - return; - } - - this.state.addLastSnackbar({ message: this.state.translate('loadedapp.tryingnewserver') as string }); - - const cs = { - uri: uri, - chainName: chainName, - region: '', - default: false, - latency: null, - obsolete: false, - } as ServerUrisType; - const serverChecked = await selectingServer([cs]); - if (serverChecked && serverChecked.latency) { - await SettingsFileImpl.writeSettings(SettingsNameEnum.server, { uri, chainName }); + if (this.state.customServerOffline) { + await SettingsFileImpl.writeSettings(SettingsNameEnum.server, { + uri: '', + chainName: this.state.server.chainName, + }); + await SettingsFileImpl.writeSettings(SettingsNameEnum.selectServer, SelectServerEnum.offline); this.setState({ - server: { uri, chainName }, + selectServer: SelectServerEnum.offline, + server: { uri: '', chainName: this.state.server.chainName }, customServerShow: false, customServerUri: '', - customServerChainName: ChainNameEnum.mainChainName, + customServerChainName: this.state.server.chainName, + customServerOffline: false, }); } else { - this.state.addLastSnackbar({ - message: (this.state.translate('loadedapp.changeservernew-error') as string) + uri, - }); + const uri: string = parseServerURI(this.state.customServerUri, this.state.translate); + const chainName = this.state.customServerChainName; + if (uri.toLowerCase().startsWith(GlobalConst.error)) { + this.addLastSnackbar({ message: this.state.translate('settings.isuri') as string }); + this.setState({ actionButtonsDisabled: false }); + return; + } + + this.state.addLastSnackbar({ message: this.state.translate('loadedapp.tryingnewserver') as string }); + + const cs = { + uri: uri, + chainName: chainName, + region: '', + default: false, + latency: null, + obsolete: false, + } as ServerUrisType; + const serverChecked = await selectingServer([cs]); + if (serverChecked && serverChecked.latency) { + await SettingsFileImpl.writeSettings(SettingsNameEnum.server, { uri, chainName }); + await SettingsFileImpl.writeSettings(SettingsNameEnum.selectServer, SelectServerEnum.custom); + this.setState({ + selectServer: SelectServerEnum.custom, + server: { uri, chainName }, + customServerShow: false, + customServerUri: '', + customServerChainName: this.state.server.chainName, + customServerOffline: false, + }); + } else { + this.state.addLastSnackbar({ + message: (this.state.translate('loadedapp.changeservernew-error') as string) + uri, + }); + } } this.setState({ actionButtonsDisabled: false }); }; @@ -923,6 +981,10 @@ export class LoadingAppClass extends Component { + if (!this.state.netInfo.isConnected || this.state.selectServer === SelectServerEnum.offline) { + this.addLastSnackbar({ message: this.state.translate('loadedapp.connection-error') as string }); + return; + } this.setState({ actionButtonsDisabled: true }); setTimeout(async () => { let seed: string = await RPCModule.createNewWallet(this.state.server.uri, this.state.server.chainName); @@ -1124,17 +1186,17 @@ export class LoadingAppClass extends Component { - if (this.state.netInfo.isConnected) { - this.setState({ customServerShow: true }); - } else { - this.addLastSnackbar({ message: this.state.translate('loadedapp.connection-error') as string }); - } + this.setState({ customServerShow: true }); }; onPressServerChainName = (chain: ChainNameEnum) => { this.setState({ customServerChainName: chain }); }; + onPressServerOffline = (value: boolean) => { + this.setState({ customServerOffline: value }); + }; + addLastSnackbar = (snackbar: SnackbarType) => { const newSnackbars = this.state.snackbars; // if the last one is the same don't do anything. @@ -1198,12 +1260,14 @@ export class LoadingAppClass extends Component )} + {!netInfo.isConnected && hasRecoveryWalletInfoSaved && !actionButtonsDisabled && ( + } + buttonStyle={{ width: 40, padding: 10, resizeMode: 'contain' }} + destructiveIndex={5} + options={[translate('loadingapp.recoverkeys'), translate('cancel')]} + actions={[() => this.recoverRecoveryWalletInfo(true)]} + /> + )} - {netInfo.isConnected && ( + {selectServer !== SelectServerEnum.offline && ( <> {`${translate('loadingapp.actualserver') as string} [${ @@ -1349,6 +1422,16 @@ export class LoadingAppClass extends Component{server.uri} )} + {selectServer === SelectServerEnum.offline && ( + + + {translate('loadingapp.actualserver') as string} + + + {' ' + (translate('settings.server-offline') as string)} + + + )} {customServerShow && ( - - - this.setState({ customServerUri: text })} - editable={true} - maxLength={100} - /> - + alignItems: 'center', + justifyContent: 'center', + margin: 0, + marginBottom: 10, + paddingHorizontal: 5, + paddingVertical: 1, + borderColor: customServerOffline ? colors.primary : colors.zingo, + borderWidth: customServerOffline ? 2 : 1, + borderRadius: 10, + minWidth: 25, + minHeight: 25, + }}> + this.onPressServerOffline(!customServerOffline)}> + + + + {translate('settings.server-offline') as string} + + + + + )} + {!customServerOffline && ( + <> + + + this.setState({ customServerUri: text })} + editable={!actionButtonsDisabled} + maxLength={100} + /> + + + )}