mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +01:00
REF: convert some stuff to typescript
This commit is contained in:
parent
0912cdc963
commit
3f6db4da69
@ -2,7 +2,7 @@ import { AppStorage } from './class';
|
|||||||
import Biometric from './class/biometrics';
|
import Biometric from './class/biometrics';
|
||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
import loc from './loc';
|
import loc from './loc';
|
||||||
const prompt = require('./blue_modules/prompt');
|
const prompt = require('./helpers/prompt');
|
||||||
const currency = require('./blue_modules/currency');
|
const currency = require('./blue_modules/currency');
|
||||||
const BlueElectrum = require('./blue_modules/BlueElectrum'); // eslint-disable-line @typescript-eslint/no-unused-vars
|
const BlueElectrum = require('./blue_modules/BlueElectrum'); // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
BlueElectrum.connectMain();
|
BlueElectrum.connectMain();
|
||||||
|
2
blue_modules/BlueElectrum.d.ts
vendored
2
blue_modules/BlueElectrum.d.ts
vendored
@ -87,3 +87,5 @@ export function broadcastV2(txhex: string): Promise<string>;
|
|||||||
export function getTransactionsFullByAddress(address: string): Promise<Transaction[]>;
|
export function getTransactionsFullByAddress(address: string): Promise<Transaction[]>;
|
||||||
|
|
||||||
export function txhexToElectrumTransaction(txhes: string): Transaction;
|
export function txhexToElectrumTransaction(txhes: string): Transaction;
|
||||||
|
|
||||||
|
export function isDisabled(): Promise<boolean>;
|
||||||
|
@ -10,7 +10,7 @@ import loc from '../loc';
|
|||||||
*
|
*
|
||||||
* @return {Promise<boolean>}
|
* @return {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
module.exports = function (title = 'Are you sure?', text = '') {
|
module.exports = function (title = 'Are you sure?', text = ''): Promise<boolean> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
title,
|
title,
|
@ -2,7 +2,14 @@ import { Platform } from 'react-native';
|
|||||||
import prompt from 'react-native-prompt-android';
|
import prompt from 'react-native-prompt-android';
|
||||||
import loc from '../loc';
|
import loc from '../loc';
|
||||||
|
|
||||||
module.exports = (title, text, isCancelable = true, type = 'secure-text', isOKDestructive = false, continueButtonText = loc._.ok) => {
|
module.exports = (
|
||||||
|
title: string,
|
||||||
|
text: string,
|
||||||
|
isCancelable = true,
|
||||||
|
type: PromptType | PromptTypeIOS | PromptTypeAndroid = 'secure-text',
|
||||||
|
isOKDestructive = false,
|
||||||
|
continueButtonText = loc._.ok,
|
||||||
|
): Promise<string> => {
|
||||||
const keyboardType = type === 'numeric' ? 'numeric' : 'default';
|
const keyboardType = type === 'numeric' ? 'numeric' : 'default';
|
||||||
|
|
||||||
if (Platform.OS === 'ios' && type === 'numeric') {
|
if (Platform.OS === 'ios' && type === 'numeric') {
|
||||||
@ -11,7 +18,7 @@ module.exports = (title, text, isCancelable = true, type = 'secure-text', isOKDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const buttons = isCancelable
|
const buttons: Array<PromptButton> = isCancelable
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
text: loc._.cancel,
|
text: loc._.cancel,
|
||||||
@ -42,6 +49,7 @@ module.exports = (title, text, isCancelable = true, type = 'secure-text', isOKDe
|
|||||||
prompt(title, text, buttons, {
|
prompt(title, text, buttons, {
|
||||||
type: type,
|
type: type,
|
||||||
cancelable: isCancelable,
|
cancelable: isCancelable,
|
||||||
|
// @ts-ignore suppressed because its supported only on ios and is absent from type definitions
|
||||||
keyboardType,
|
keyboardType,
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -8,12 +8,19 @@
|
|||||||
*
|
*
|
||||||
* @return {Promise<string>}
|
* @return {Promise<string>}
|
||||||
*/
|
*/
|
||||||
module.exports = function scanQrHelper(navigateFunc, currentScreenName, showFileImportButton = true) {
|
module.exports = function scanQrHelper(
|
||||||
|
navigateFunc: (scr: string, params?: any) => void,
|
||||||
|
currentScreenName: string,
|
||||||
|
showFileImportButton = true,
|
||||||
|
): Promise<string | null> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const params = {};
|
const params = {
|
||||||
params.showFileImportButton = !!showFileImportButton;
|
showFileImportButton: Boolean(showFileImportButton),
|
||||||
|
onBarScanned: (data: any) => {},
|
||||||
|
onDismiss: () => {},
|
||||||
|
};
|
||||||
|
|
||||||
params.onBarScanned = function (data) {
|
params.onBarScanned = function (data: any) {
|
||||||
setTimeout(() => resolve(data.data || data), 1);
|
setTimeout(() => resolve(data.data || data), 1);
|
||||||
navigateFunc(currentScreenName);
|
navigateFunc(currentScreenName);
|
||||||
};
|
};
|
||||||
@ -28,3 +35,5 @@ module.exports = function scanQrHelper(navigateFunc, currentScreenName, showFile
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export {};
|
@ -10,16 +10,32 @@
|
|||||||
*
|
*
|
||||||
* @returns {Promise<AbstractWallet>}
|
* @returns {Promise<AbstractWallet>}
|
||||||
*/
|
*/
|
||||||
module.exports = function (navigateFunc, currentScreenName, chainType, availableWallets, noWalletExplanationText = '') {
|
import { AbstractWallet } from '../class';
|
||||||
|
|
||||||
|
module.exports = function (
|
||||||
|
navigateFunc: (scr: string, params?: any) => void,
|
||||||
|
currentScreenName: string,
|
||||||
|
chainType: string | null,
|
||||||
|
availableWallets?: AbstractWallet[],
|
||||||
|
noWalletExplanationText = '',
|
||||||
|
): Promise<AbstractWallet> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!currentScreenName) return reject(new Error('currentScreenName is not provided'));
|
if (!currentScreenName) return reject(new Error('currentScreenName is not provided'));
|
||||||
|
|
||||||
const params = {};
|
const params: {
|
||||||
|
chainType: string | null;
|
||||||
|
availableWallets?: AbstractWallet[];
|
||||||
|
noWalletExplanationText?: string;
|
||||||
|
onWalletSelect: (selectedWallet: AbstractWallet) => void;
|
||||||
|
} = {
|
||||||
|
chainType: null,
|
||||||
|
onWalletSelect: (selectedWallet: AbstractWallet) => {},
|
||||||
|
};
|
||||||
if (chainType) params.chainType = chainType;
|
if (chainType) params.chainType = chainType;
|
||||||
if (availableWallets) params.availableWallets = availableWallets;
|
if (availableWallets) params.availableWallets = availableWallets;
|
||||||
if (noWalletExplanationText) params.noWalletExplanationText = noWalletExplanationText;
|
if (noWalletExplanationText) params.noWalletExplanationText = noWalletExplanationText;
|
||||||
|
|
||||||
params.onWalletSelect = function (selectedWallet) {
|
params.onWalletSelect = function (selectedWallet: AbstractWallet) {
|
||||||
if (!selectedWallet) return;
|
if (!selectedWallet) return;
|
||||||
|
|
||||||
setTimeout(() => resolve(selectedWallet), 1);
|
setTimeout(() => resolve(selectedWallet), 1);
|
@ -65,7 +65,7 @@
|
|||||||
"e2e:release-build": "detox build -c android.release",
|
"e2e:release-build": "detox build -c android.release",
|
||||||
"e2e:release-test": "detox test -c android.release --record-videos all --record-logs all --take-screenshots all --headless -d 200000",
|
"e2e:release-test": "detox test -c android.release --record-videos all --record-logs all --take-screenshots all --headless -d 200000",
|
||||||
"tslint": "tsc",
|
"tslint": "tsc",
|
||||||
"lint": "eslint --ext .js,.ts,.tsx '*.@(js|ts|tsx)' screen 'blue_modules/*.@(js|ts|tsx)' class models loc tests components",
|
"lint": "eslint --ext .js,.ts,.tsx '*.@(js|ts|tsx)' screen 'blue_modules/*.@(js|ts|tsx)' class models loc tests components && npm run tslint",
|
||||||
"lint:fix": "npm run lint -- --fix",
|
"lint:fix": "npm run lint -- --fix",
|
||||||
"lint:quickfix": "git status --porcelain | grep -v '\\.json' | grep -E '\\.js|\\.ts' --color=never | awk '{print $2}' | xargs eslint --fix; exit 0",
|
"lint:quickfix": "git status --porcelain | grep -v '\\.json' | grep -E '\\.js|\\.ts' --color=never | awk '{print $2}' | xargs eslint --fix; exit 0",
|
||||||
"unit": "jest -b -i tests/unit/*",
|
"unit": "jest -b -i tests/unit/*",
|
||||||
|
@ -22,7 +22,7 @@ import loc, { formatBalanceWithoutSuffix, formatBalance } from '../../loc';
|
|||||||
import Biometric from '../../class/biometrics';
|
import Biometric from '../../class/biometrics';
|
||||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||||
import alert from '../../components/Alert';
|
import alert from '../../components/Alert';
|
||||||
const prompt = require('../../blue_modules/prompt');
|
const prompt = require('../../helpers/prompt');
|
||||||
const currency = require('../../blue_modules/currency');
|
const currency = require('../../blue_modules/currency');
|
||||||
|
|
||||||
const LnurlPay = () => {
|
const LnurlPay = () => {
|
||||||
|
@ -8,7 +8,7 @@ import { BlueLoading, BlueButton, SafeBlueArea, BlueCard, BlueText, BlueSpacing2
|
|||||||
import loc from '../loc';
|
import loc from '../loc';
|
||||||
import { BlueStorageContext } from '../blue_modules/storage-context';
|
import { BlueStorageContext } from '../blue_modules/storage-context';
|
||||||
import alert from '../components/Alert';
|
import alert from '../components/Alert';
|
||||||
const prompt = require('../blue_modules/prompt');
|
const prompt = require('../helpers/prompt');
|
||||||
|
|
||||||
const PlausibleDeniability = () => {
|
const PlausibleDeniability = () => {
|
||||||
const { cachedPassword, isPasswordInUse, createFakeStorage, resetWallets } = useContext(BlueStorageContext);
|
const { cachedPassword, isPasswordInUse, createFakeStorage, resetWallets } = useContext(BlueStorageContext);
|
||||||
|
@ -42,7 +42,7 @@ import { AbstractHDElectrumWallet } from '../../class/wallets/abstract-hd-electr
|
|||||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||||
import ToolTipMenu from '../../components/TooltipMenu';
|
import ToolTipMenu from '../../components/TooltipMenu';
|
||||||
const currency = require('../../blue_modules/currency');
|
const currency = require('../../blue_modules/currency');
|
||||||
const prompt = require('../../blue_modules/prompt');
|
const prompt = require('../../helpers/prompt');
|
||||||
const fs = require('../../blue_modules/fs');
|
const fs = require('../../blue_modules/fs');
|
||||||
const scanqr = require('../../helpers/scan-qr');
|
const scanqr = require('../../helpers/scan-qr');
|
||||||
const btcAddressRx = /^[a-zA-Z0-9]{26,35}$/;
|
const btcAddressRx = /^[a-zA-Z0-9]{26,35}$/;
|
||||||
|
@ -10,7 +10,7 @@ import Biometric from '../../class/biometrics';
|
|||||||
import loc from '../../loc';
|
import loc from '../../loc';
|
||||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||||
import alert from '../../components/Alert';
|
import alert from '../../components/Alert';
|
||||||
const prompt = require('../../blue_modules/prompt');
|
const prompt = require('../../helpers/prompt');
|
||||||
|
|
||||||
const EncryptStorage = () => {
|
const EncryptStorage = () => {
|
||||||
const { isStorageEncrypted, encryptStorage, decryptStorage, saveToDisk } = useContext(BlueStorageContext);
|
const { isStorageEncrypted, encryptStorage, decryptStorage, saveToDisk } = useContext(BlueStorageContext);
|
||||||
|
@ -42,7 +42,7 @@ import { encodeUR } from '../../blue_modules/ur';
|
|||||||
import QRCodeComponent from '../../components/QRCodeComponent';
|
import QRCodeComponent from '../../components/QRCodeComponent';
|
||||||
import alert from '../../components/Alert';
|
import alert from '../../components/Alert';
|
||||||
|
|
||||||
const prompt = require('../../blue_modules/prompt');
|
const prompt = require('../../helpers/prompt');
|
||||||
const A = require('../../blue_modules/analytics');
|
const A = require('../../blue_modules/analytics');
|
||||||
const fs = require('../../blue_modules/fs');
|
const fs = require('../../blue_modules/fs');
|
||||||
const isDesktop = getSystemName() === 'Mac OS X';
|
const isDesktop = getSystemName() === 'Mac OS X';
|
||||||
|
@ -44,7 +44,7 @@ import { isDesktop } from '../../blue_modules/environment';
|
|||||||
import { AbstractHDElectrumWallet } from '../../class/wallets/abstract-hd-electrum-wallet';
|
import { AbstractHDElectrumWallet } from '../../class/wallets/abstract-hd-electrum-wallet';
|
||||||
import alert from '../../components/Alert';
|
import alert from '../../components/Alert';
|
||||||
|
|
||||||
const prompt = require('../../blue_modules/prompt');
|
const prompt = require('../../helpers/prompt');
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
scrollViewContent: {
|
scrollViewContent: {
|
||||||
|
@ -10,7 +10,7 @@ import loc from '../../loc';
|
|||||||
import { HDSegwitBech32Wallet } from '../../class';
|
import { HDSegwitBech32Wallet } from '../../class';
|
||||||
import startImport from '../../class/wallet-import';
|
import startImport from '../../class/wallet-import';
|
||||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||||
import prompt from '../../blue_modules/prompt';
|
import prompt from '../../helpers/prompt';
|
||||||
|
|
||||||
const ImportWalletDiscovery = () => {
|
const ImportWalletDiscovery = () => {
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
|
@ -46,7 +46,7 @@ import { encodeUR } from '../../blue_modules/ur';
|
|||||||
import QRCodeComponent from '../../components/QRCodeComponent';
|
import QRCodeComponent from '../../components/QRCodeComponent';
|
||||||
import alert from '../../components/Alert';
|
import alert from '../../components/Alert';
|
||||||
const fs = require('../../blue_modules/fs');
|
const fs = require('../../blue_modules/fs');
|
||||||
const prompt = require('../../blue_modules/prompt');
|
const prompt = require('../../helpers/prompt');
|
||||||
|
|
||||||
const ViewEditMultisigCosigners = () => {
|
const ViewEditMultisigCosigners = () => {
|
||||||
const hasLoaded = useRef(false);
|
const hasLoaded = useRef(false);
|
||||||
|
57
typings/react-native-prompt-android.d.ts
vendored
Normal file
57
typings/react-native-prompt-android.d.ts
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// Type definitions for react-native-prompt-android 0.3.1
|
||||||
|
// Project: https://github.com/shimohq/react-native-prompt-android
|
||||||
|
// Definitions by: Krystof Celba <https://github.com/krystofcelba>
|
||||||
|
// TypeScript Version: 2.6.1
|
||||||
|
|
||||||
|
type PromptButton = {
|
||||||
|
text?: string;
|
||||||
|
onPress?: (message: string) => void;
|
||||||
|
|
||||||
|
/** @platform ios */
|
||||||
|
style?: 'default' | 'cancel' | 'destructive';
|
||||||
|
};
|
||||||
|
|
||||||
|
type PromptType = 'default' | 'plain-text' | 'secure-text';
|
||||||
|
type PromptTypeIOS = 'login-password';
|
||||||
|
type PromptTypeAndroid = 'numeric' | 'email-address' | 'phone-pad';
|
||||||
|
|
||||||
|
type PromptStyleAndroid = 'default' | 'shimo';
|
||||||
|
|
||||||
|
interface PromptOptions {
|
||||||
|
/**
|
||||||
|
* * Cross platform:
|
||||||
|
*
|
||||||
|
* - `'default'`
|
||||||
|
* - `'plain-text'`
|
||||||
|
* - `'secure-text'`
|
||||||
|
*
|
||||||
|
* * iOS only:
|
||||||
|
*
|
||||||
|
* - `'login-password'`
|
||||||
|
*
|
||||||
|
* * Android only:
|
||||||
|
*
|
||||||
|
* - `'numeric'`
|
||||||
|
* - `'email-address'`
|
||||||
|
* - `'phone-pad'`
|
||||||
|
*/
|
||||||
|
type?: PromptType | PromptTypeIOS | PromptTypeAndroid;
|
||||||
|
|
||||||
|
defaultValue?: string;
|
||||||
|
|
||||||
|
/** @platform android */
|
||||||
|
placeholder?: string;
|
||||||
|
|
||||||
|
/** @platform android */
|
||||||
|
cancelable?: boolean;
|
||||||
|
|
||||||
|
/** @platform android */
|
||||||
|
style?: PromptStyleAndroid;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare function prompt(
|
||||||
|
title?: string,
|
||||||
|
message?: string,
|
||||||
|
callbackOrButtons?: ((value: string) => void) | Array<PromptButton>,
|
||||||
|
options?: PromptOptions,
|
||||||
|
): void;
|
Loading…
Reference in New Issue
Block a user