Skip to content

Commit

Permalink
Merge pull request #733 from juanky201271/dev_no_servers_working_issu…
Browse files Browse the repository at this point in the history
…e_fixed

Show error when none of the servers work
  • Loading branch information
juanky201271 authored Oct 16, 2024
2 parents aa732e6 + 2d8261e commit 8ab5ade
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 24 deletions.
62 changes: 42 additions & 20 deletions app/LoadingApp/LoadingApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ export class LoadingAppClass extends Component<LoadingAppClassProps, LoadingAppC
});
}, 1000);
// not a different one, can be the same.
await this.selectTheBestServer(false);
const someServerIsWorking = await this.selectTheBestServer(false);
console.log('some server is working?', someServerIsWorking);
}

// Second, check if a wallet exists. Do it async so the basic screen has time to render
Expand Down Expand Up @@ -650,9 +651,9 @@ export class LoadingAppClass extends Component<LoadingAppClassProps, LoadingAppC
});
};

selectTheBestServer = async (aDifferentOne: boolean) => {
selectTheBestServer = async (aDifferentOne: boolean): Promise<boolean> => {
// avoiding obsolete ones
let withMessage: boolean = true;
let someServerIsWorking: boolean = true;
const actualServer = this.state.server;
const server = await selectingServer(
serverUris(this.state.translate).filter(
Expand All @@ -664,10 +665,10 @@ export class LoadingAppClass extends Component<LoadingAppClassProps, LoadingAppC
fasterServer = { uri: server.uri, chainName: server.chainName };
} else {
fasterServer = actualServer;
// likely here there is a internet conection problem
// likely here there is a internet/wifi conection problem
// all of the servers return an error because they are unreachable probably.
// the 30 seconds timout was fired.
withMessage = false;
someServerIsWorking = false;
}
console.log(server);
console.log(fasterServer);
Expand All @@ -678,7 +679,7 @@ export class LoadingAppClass extends Component<LoadingAppClassProps, LoadingAppC
await SettingsFileImpl.writeSettings(SettingsNameEnum.server, fasterServer);
await SettingsFileImpl.writeSettings(SettingsNameEnum.selectServer, SelectServerEnum.list);
// message with the result only for advanced users
if (this.state.mode === ModeEnum.advanced && withMessage) {
if (this.state.mode === ModeEnum.advanced && someServerIsWorking) {
if (isEqual(actualServer, fasterServer)) {
this.addLastSnackbar({
message: this.state.translate('loadedapp.selectingserversame') as string,
Expand All @@ -691,13 +692,20 @@ export class LoadingAppClass extends Component<LoadingAppClassProps, LoadingAppC
});
}
}
return someServerIsWorking;
};

checkServer: (s: ServerType) => Promise<boolean> = async (server: ServerType) => {
const resp: string = await RPCModule.getLatestBlock(server.uri);
//console.log('check server', resp);

if (resp && !resp.toLowerCase().startsWith(GlobalConst.error)) {
const s = {
uri: server.uri,
chainName: server.chainName,
region: '',
default: false,
latency: null,
obsolete: false,
} as ServerUrisType;
const serverChecked = await selectingServer([s]);
if (serverChecked && serverChecked.latency) {
return true;
} else {
return false;
Expand Down Expand Up @@ -737,20 +745,34 @@ export class LoadingAppClass extends Component<LoadingAppClassProps, LoadingAppC
duration: SnackbarDurationEnum.longer,
});
// a different server.
await this.selectTheBestServer(true);
if (start) {
this.setState({
startingApp: false,
serverErrorTries: 1,
screen,
});
this.componentDidMount();
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,
Expand Down Expand Up @@ -1336,7 +1358,7 @@ export class LoadingAppClass extends Component<LoadingAppClassProps, LoadingAppC
this.setState({
startingApp: false,
});
this.componentDidMount;
this.componentDidMount();
}}
style={{ marginBottom: 10 }}
/>
Expand Down
3 changes: 2 additions & 1 deletion app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"serverfirsttry": "An error occurred while trying to connect to the above server, currently checking the servers on the list.",
"serversecondtry": "It doesn't seem to be a problem with the server. Someting else is happening.",
"alert-donation-title": "TIP ZINGOLABS",
"alert-donation-body": "Do you want to help ZingoLabs make Zcash more useful? Opt in to tip one Zenny (0.01 ZEC) to ZingoLabs with each transaction! If so, press confirm, otherwise press Cancel."
"alert-donation-body": "Do you want to help ZingoLabs make Zcash more useful? Opt in to tip one Zenny (0.01 ZEC) to ZingoLabs with each transaction! If so, press confirm, otherwise press Cancel.",
"noservers": "None of the servers on the list are available, it is probably a connection error."
},
"loadedapp": {
"about": "About Zingo",
Expand Down
3 changes: 2 additions & 1 deletion app/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"serverfirsttry": "Se produjo un error al intentar conectarse al servidor activo, actualmente verificando los servidores en la lista.",
"serversecondtry": "No parece haber ningún problema con el servidor. Ocurre algo diferente.",
"alert-donation-title": "APOYAR A ZINGOLABS",
"alert-donation-body": "¿Quieres ayudar a ZingoLabs a que Zcash sea más útil? Opta por dar una propina de un Zenny (0.01 ZEC) a ZingoLabs con cada transacción! Si es así, presione confirmar, de lo contrario presione Cancelar."
"alert-donation-body": "¿Quieres ayudar a ZingoLabs a que Zcash sea más útil? Opta por dar una propina de un Zenny (0.01 ZEC) a ZingoLabs con cada transacción! Si es así, presione confirmar, de lo contrario presione Cancelar.",
"noservers": "Ninguno de los servidores de la lista esta disponible, probablemente se trata de un error de conexion."
},
"loadedapp": {
"about": "Sobre Zingo",
Expand Down
3 changes: 2 additions & 1 deletion app/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"serverfirsttry": "Ocorreu um erro ao tentar conectar-se ao servidor acima, atualmente verificando os servidores na lista.",
"serversecondtry": "Não parece haver nenhum problema com o servidor. Algo mais está acontecendo.",
"alert-donation-title": "APOIAR A ZINGOLABS",
"alert-donation-body": "Você quer ajudar o ZingoLabs a tornar o Zcash mais útil? Opte por dar uma gorjeta de um Zenny (0.01 ZEC) para ZingoLabs em cada transação! Se sim, pressione confirmar, caso contrário, pressione Cancelar."
"alert-donation-body": "Você quer ajudar o ZingoLabs a tornar o Zcash mais útil? Opte por dar uma gorjeta de um Zenny (0.01 ZEC) para ZingoLabs em cada transação! Se sim, pressione confirmar, caso contrário, pressione Cancelar.",
"noservers": "Nenhum dos servidores da lista está disponível, provavelmente é um erro de conexão."
},
"loadedapp": {
"about": "Sobre a Zingo",
Expand Down
3 changes: 2 additions & 1 deletion app/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"serverfirsttry": "Произошла ошибка при попытке подключения к указанному выше серверу, в настоящее время проверяются серверы в списке.",
"serversecondtry": "Похоже, что с этим сервером нет никаких проблем. Проблема в чём-то другом.",
"alert-donation-title": "ПОДДЕРЖИВАЕМЫЕ ZINGOLABS",
"alert-donation-body": "Хотите помочь ZingoLabs сделать Zcash более полезным? Подпишитесь на чаевые в размере одного Zenny (0.01 ZEC) в пользу ZingoLabs за каждую транзакцию! Если да, нажмите «Подтвердить», в противном случае нажмите «Отмена»."
"alert-donation-body": "Хотите помочь ZingoLabs сделать Zcash более полезным? Подпишитесь на чаевые в размере одного Zenny (0.01 ZEC) в пользу ZingoLabs за каждую транзакцию! Если да, нажмите «Подтвердить», в противном случае нажмите «Отмена».",
"noservers": "Ни один из серверов в списке недоступен, возможно, это ошибка подключения."
},
"loadedapp": {
"about": "О Zingo",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"babel-plugin-dynamic-import-node": "^2.3.3",
"detox": "20.27.2",
"eslint": "^8.19.0",
"eslint-plugin-ft-flow": "^3.0.11",
"jest": "^29.2.1",
"metro-react-native-babel-preset": "^0.76.9",
"prettier": "^2.4.1",
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4161,6 +4161,14 @@ eslint-plugin-ft-flow@^2.0.1:
lodash "^4.17.21"
string-natural-compare "^3.0.1"

eslint-plugin-ft-flow@^3.0.11:
version "3.0.11"
resolved "https://registry.yarnpkg.com/eslint-plugin-ft-flow/-/eslint-plugin-ft-flow-3.0.11.tgz#64654dad277104fc45aef8d009c4a51057ea1250"
integrity sha512-6ZJ4KYGYjIosCcU883zBBT1nFsKP58xrTOwguiw3/HRq0EpYAyhrF1nCGbK7V23cmKtPXMpDfl8qPupt5s5W8w==
dependencies:
lodash "^4.17.21"
string-natural-compare "^3.0.1"

eslint-plugin-jest@^26.5.3:
version "26.9.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-26.9.0.tgz#7931c31000b1c19e57dbfb71bbf71b817d1bf949"
Expand Down

0 comments on commit 8ab5ade

Please sign in to comment.