mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
Update BlueElectrum.js
This commit is contained in:
parent
5acbd043dc
commit
e14ca13cf0
@ -102,71 +102,7 @@ async function connectMain() {
|
||||
connectionAttempt = connectionAttempt + 1;
|
||||
mainClient.close && mainClient.close();
|
||||
if (connectionAttempt >= 5) {
|
||||
Alert.alert(
|
||||
loc.errors.network,
|
||||
loc.formatString(loc.settings.electrum_unable_to_connect, { server: `${usingPeer.host}:${usingPeer.ssl ?? usingPeer.tcp}` }),
|
||||
[
|
||||
{
|
||||
text: loc.wallets.list_tryagain,
|
||||
onPress: () => {
|
||||
connectionAttempt = 0;
|
||||
setTimeout(connectMain, 500);
|
||||
},
|
||||
style: 'default',
|
||||
},
|
||||
{
|
||||
text: loc.settings.electrum_reset,
|
||||
onPress: () => {
|
||||
Alert.alert(
|
||||
loc.settings.electrum_reset,
|
||||
loc.settings.electrum_reset_to_default,
|
||||
[
|
||||
{
|
||||
text: loc._.cancel,
|
||||
style: 'cancel',
|
||||
onPress: () => {
|
||||
connectionAttempt = 0;
|
||||
},
|
||||
},
|
||||
{
|
||||
text: loc._.ok,
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
await AsyncStorage.setItem(AppStorage.ELECTRUM_HOST, '');
|
||||
await AsyncStorage.setItem(AppStorage.ELECTRUM_TCP_PORT, '');
|
||||
await AsyncStorage.setItem(AppStorage.ELECTRUM_SSL_PORT, '');
|
||||
try {
|
||||
await DefaultPreference.setName('group.io.bluewallet.bluewallet');
|
||||
await DefaultPreference.clear(AppStorage.ELECTRUM_HOST);
|
||||
await DefaultPreference.clear(AppStorage.ELECTRUM_SSL_PORT);
|
||||
await DefaultPreference.clear(AppStorage.ELECTRUM_TCP_PORT);
|
||||
RNWidgetCenter.reloadAllTimelines();
|
||||
} catch (e) {
|
||||
// Must be running on Android
|
||||
console.log(e);
|
||||
}
|
||||
alert(loc.settings.electrum_saved);
|
||||
|
||||
connectionAttempt = 0;
|
||||
},
|
||||
},
|
||||
],
|
||||
{ cancelable: false },
|
||||
);
|
||||
connectionAttempt = 0;
|
||||
},
|
||||
style: 'destructive',
|
||||
},
|
||||
{
|
||||
text: loc._.cancel,
|
||||
onPress: () => {
|
||||
connectionAttempt = 0;
|
||||
},
|
||||
style: 'cancel',
|
||||
},
|
||||
],
|
||||
{ cancelable: false },
|
||||
);
|
||||
presentNetworkErrorAlert(usingPeer);
|
||||
} else {
|
||||
setTimeout(connectMain, 500);
|
||||
}
|
||||
@ -175,6 +111,77 @@ async function connectMain() {
|
||||
|
||||
connectMain();
|
||||
|
||||
async function presentNetworkErrorAlert(usingPeer) {
|
||||
Alert.alert(
|
||||
loc.errors.network,
|
||||
loc.formatString(
|
||||
usingPeer ? loc.settings.electrum_unable_to_connect : loc.settings.electrum_error_connect,
|
||||
usingPeer ? { server: `${usingPeer.host}:${usingPeer.ssl ?? usingPeer.tcp}` } : {},
|
||||
),
|
||||
[
|
||||
{
|
||||
text: loc.wallets.list_tryagain,
|
||||
onPress: () => {
|
||||
connectionAttempt = 0;
|
||||
mainClient.close() && mainClient.close();
|
||||
setTimeout(connectMain, 500);
|
||||
},
|
||||
style: 'default',
|
||||
},
|
||||
{
|
||||
text: loc.settings.electrum_reset,
|
||||
onPress: () => {
|
||||
Alert.alert(
|
||||
loc.settings.electrum_reset,
|
||||
loc.settings.electrum_reset_to_default,
|
||||
[
|
||||
{
|
||||
text: loc._.cancel,
|
||||
style: 'cancel',
|
||||
onPress: () => {},
|
||||
},
|
||||
{
|
||||
text: loc._.ok,
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
await AsyncStorage.setItem(AppStorage.ELECTRUM_HOST, '');
|
||||
await AsyncStorage.setItem(AppStorage.ELECTRUM_TCP_PORT, '');
|
||||
await AsyncStorage.setItem(AppStorage.ELECTRUM_SSL_PORT, '');
|
||||
try {
|
||||
await DefaultPreference.setName('group.io.bluewallet.bluewallet');
|
||||
await DefaultPreference.clear(AppStorage.ELECTRUM_HOST);
|
||||
await DefaultPreference.clear(AppStorage.ELECTRUM_SSL_PORT);
|
||||
await DefaultPreference.clear(AppStorage.ELECTRUM_TCP_PORT);
|
||||
RNWidgetCenter.reloadAllTimelines();
|
||||
} catch (e) {
|
||||
// Must be running on Android
|
||||
console.log(e);
|
||||
}
|
||||
alert(loc.settings.electrum_saved);
|
||||
setTimeout(connectMain, 500);
|
||||
},
|
||||
},
|
||||
],
|
||||
{ cancelable: true },
|
||||
);
|
||||
connectionAttempt = 0;
|
||||
mainClient.close() && mainClient.close();
|
||||
},
|
||||
style: 'destructive',
|
||||
},
|
||||
{
|
||||
text: loc._.cancel,
|
||||
onPress: () => {
|
||||
connectionAttempt = 0;
|
||||
mainClient.close() && mainClient.close();
|
||||
},
|
||||
style: 'cancel',
|
||||
},
|
||||
],
|
||||
{ cancelable: false },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns random hardcoded electrum server guaranteed to work
|
||||
* at the time of writing.
|
||||
@ -526,6 +533,8 @@ module.exports.waitTillConnected = async function () {
|
||||
|
||||
if (retriesCounter++ >= 30) {
|
||||
clearInterval(waitTillConnectedInterval);
|
||||
connectionAttempt = 0;
|
||||
presentNetworkErrorAlert();
|
||||
reject(new Error('Waiting for Electrum connection timeout'));
|
||||
}
|
||||
}, 500);
|
||||
|
Loading…
Reference in New Issue
Block a user