mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-13 19:16:52 +01:00
Merge branch 'master' into detailsitem
This commit is contained in:
commit
157bd3529a
8 changed files with 45 additions and 35 deletions
|
@ -6,6 +6,7 @@ import { checkNotifications, requestNotifications, RESULTS } from 'react-native-
|
|||
import PushNotification from 'react-native-push-notification';
|
||||
import loc from '../loc';
|
||||
import { groundControlUri } from './constants';
|
||||
import { fetch } from '../util/fetch';
|
||||
|
||||
const PUSH_TOKEN = 'PUSH_TOKEN';
|
||||
const GROUNDCONTROL_BASE_URI = 'GROUNDCONTROL_BASE_URI';
|
||||
|
@ -385,10 +386,6 @@ export const configureNotifications = async onProcessNotifications => {
|
|||
});
|
||||
};
|
||||
|
||||
const _sleep = async ms => {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates whether the provided GroundControl URI is valid by pinging it.
|
||||
*
|
||||
|
@ -396,15 +393,13 @@ const _sleep = async ms => {
|
|||
* @returns {Promise<boolean>} TRUE if valid, FALSE otherwise
|
||||
*/
|
||||
export const isGroundControlUriValid = async uri => {
|
||||
let response;
|
||||
try {
|
||||
response = await Promise.race([fetch(`${uri}/ping`, { headers: _getHeaders() }), _sleep(2000)]);
|
||||
} catch (_) {}
|
||||
|
||||
if (!response) return false;
|
||||
|
||||
const json = await response.json();
|
||||
return !!json.description;
|
||||
const response = await fetch(`${uri}/ping`, { headers: _getHeaders() });
|
||||
const json = await response.json();
|
||||
return !!json.description;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const isNotificationsCapable = hasGmsSync() || hasHmsSync() || Platform.OS !== 'android';
|
||||
|
@ -430,24 +425,21 @@ const getLevels = async () => {
|
|||
const pushToken = await getPushToken();
|
||||
if (!pushToken || !pushToken.token || !pushToken.os) return;
|
||||
|
||||
let response;
|
||||
try {
|
||||
response = await Promise.race([
|
||||
fetch(`${baseURI}/getTokenConfiguration`, {
|
||||
method: 'POST',
|
||||
headers: _getHeaders(),
|
||||
body: JSON.stringify({
|
||||
token: pushToken.token,
|
||||
os: pushToken.os,
|
||||
}),
|
||||
const response = await fetch(`${baseURI}/getTokenConfiguration`, {
|
||||
method: 'POST',
|
||||
headers: _getHeaders(),
|
||||
body: JSON.stringify({
|
||||
token: pushToken.token,
|
||||
os: pushToken.os,
|
||||
}),
|
||||
_sleep(3000),
|
||||
]);
|
||||
} catch (_) {}
|
||||
});
|
||||
|
||||
if (!response) return {};
|
||||
|
||||
return await response.json();
|
||||
if (!response) return {};
|
||||
return await response.json();
|
||||
} catch (_) {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import URL from 'url';
|
||||
import { fetch } from '../util/fetch';
|
||||
|
||||
export default class Azteco {
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@ import CryptoJS from 'crypto-js';
|
|||
// @ts-ignore theres no types for secp256k1
|
||||
import secp256k1 from 'secp256k1';
|
||||
import { parse } from 'url'; // eslint-disable-line n/no-deprecated-api
|
||||
import { fetch } from '../util/fetch';
|
||||
|
||||
const ONION_REGEX = /^(http:\/\/[^/:@]+\.onion(?::\d{1,5})?)(\/.*)?$/; // regex for onion URL
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import bolt11 from 'bolt11';
|
||||
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits';
|
||||
import { LegacyWallet } from './legacy-wallet';
|
||||
import { fetch } from '../../util/fetch';
|
||||
|
||||
export class LightningCustodianWallet extends LegacyWallet {
|
||||
static readonly type = 'lightningCustodianWallet';
|
||||
|
|
12
package-lock.json
generated
12
package-lock.json
generated
|
@ -23,7 +23,7 @@
|
|||
"@react-native-community/cli-platform-android": "15.0.1",
|
||||
"@react-native-community/cli-platform-ios": "15.0.1",
|
||||
"@react-native-community/push-notification-ios": "1.11.0",
|
||||
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#14bab79",
|
||||
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#038a9c9",
|
||||
"@react-native/gradle-plugin": "0.76.7",
|
||||
"@react-native/metro-config": "0.76.7",
|
||||
"@react-navigation/drawer": "7.1.1",
|
||||
|
@ -71,7 +71,7 @@
|
|||
"react-native-default-preference": "https://github.com/BlueWallet/react-native-default-preference.git#6338a1f1235e4130b8cfc2dd3b53015eeff2870c",
|
||||
"react-native-device-info": "14.0.2",
|
||||
"react-native-document-picker": "9.3.1",
|
||||
"react-native-draglist": "github:BlueWallet/react-native-draglist#a4af02f",
|
||||
"react-native-draglist": "github:BlueWallet/react-native-draglist#8c52785",
|
||||
"react-native-fs": "2.20.0",
|
||||
"react-native-gesture-handler": "2.23.1",
|
||||
"react-native-handoff": "github:BlueWallet/react-native-handoff#v0.0.4",
|
||||
|
@ -5636,8 +5636,8 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@react-native-menu/menu": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "git+ssh://git@github.com/BlueWallet/menu.git#14bab7900abd763ea4e48f10a4862fa6a20c23d1",
|
||||
"version": "1.2.1",
|
||||
"resolved": "git+ssh://git@github.com/BlueWallet/menu.git#038a9c962a20c58677c2db5ee963fdb4da3ddd71",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"react": "*",
|
||||
|
@ -21818,8 +21818,8 @@
|
|||
}
|
||||
},
|
||||
"node_modules/react-native-draglist": {
|
||||
"version": "3.8.0",
|
||||
"resolved": "git+ssh://git@github.com/BlueWallet/react-native-draglist.git#a4af02fec803b75508a8136e35eca564bbb1d644",
|
||||
"version": "3.8.2",
|
||||
"resolved": "git+ssh://git@github.com/BlueWallet/react-native-draglist.git#8c5278530ac19644e67166a705f20a1f547ba77c",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"react": ">=17.0.1",
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
"@react-native-community/cli-platform-android": "15.0.1",
|
||||
"@react-native-community/cli-platform-ios": "15.0.1",
|
||||
"@react-native-community/push-notification-ios": "1.11.0",
|
||||
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#14bab79",
|
||||
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#038a9c9",
|
||||
"@react-native/gradle-plugin": "0.76.7",
|
||||
"@react-native/metro-config": "0.76.7",
|
||||
"@react-navigation/drawer": "7.1.1",
|
||||
|
@ -141,7 +141,7 @@
|
|||
"react-native-default-preference": "https://github.com/BlueWallet/react-native-default-preference.git#6338a1f1235e4130b8cfc2dd3b53015eeff2870c",
|
||||
"react-native-device-info": "14.0.2",
|
||||
"react-native-document-picker": "9.3.1",
|
||||
"react-native-draglist": "github:BlueWallet/react-native-draglist#a4af02f",
|
||||
"react-native-draglist": "github:BlueWallet/react-native-draglist#8c52785",
|
||||
"react-native-fs": "2.20.0",
|
||||
"react-native-gesture-handler": "2.23.1",
|
||||
"react-native-handoff": "github:BlueWallet/react-native-handoff#v0.0.4",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import assert from 'assert';
|
||||
|
||||
import { LightningCustodianWallet } from '../../class';
|
||||
import { fetch } from '../../util/fetch';
|
||||
|
||||
jest.setTimeout(200 * 1000);
|
||||
const baseUri = 'https://lndhub-staging.herokuapp.com';
|
||||
|
|
14
util/fetch.ts
Normal file
14
util/fetch.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
const DEFAULT_TIMEOUT = 10000; // default timeout in ms
|
||||
|
||||
// protection against calling itself recursively
|
||||
const nativeFetch = globalThis.fetch.bind(globalThis);
|
||||
|
||||
export function fetch(input: RequestInfo | URL, init: RequestInit & { timeout?: number } = {}): Promise<Response> {
|
||||
if (__DEV__) {
|
||||
console.log('fetch wrapper: ', input, init);
|
||||
}
|
||||
const { timeout = DEFAULT_TIMEOUT, ...rest } = init;
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeout);
|
||||
return nativeFetch(input, { ...rest, signal: controller.signal }).finally(() => clearTimeout(timer));
|
||||
}
|
Loading…
Add table
Reference in a new issue