REF: convert some stuff to typescript

This commit is contained in:
Overtorment 2022-09-05 19:34:02 +01:00
parent 0912cdc963
commit 3f6db4da69
16 changed files with 112 additions and 20 deletions

View File

@ -2,7 +2,7 @@ import { AppStorage } from './class';
import Biometric from './class/biometrics';
import { Platform } from 'react-native';
import loc from './loc';
const prompt = require('./blue_modules/prompt');
const prompt = require('./helpers/prompt');
const currency = require('./blue_modules/currency');
const BlueElectrum = require('./blue_modules/BlueElectrum'); // eslint-disable-line @typescript-eslint/no-unused-vars
BlueElectrum.connectMain();

View File

@ -87,3 +87,5 @@ export function broadcastV2(txhex: string): Promise<string>;
export function getTransactionsFullByAddress(address: string): Promise<Transaction[]>;
export function txhexToElectrumTransaction(txhes: string): Transaction;
export function isDisabled(): Promise<boolean>;

View File

@ -10,7 +10,7 @@ import loc from '../loc';
*
* @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 => {
Alert.alert(
title,

View File

@ -2,7 +2,14 @@ import { Platform } from 'react-native';
import prompt from 'react-native-prompt-android';
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';
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) => {
const buttons = isCancelable
const buttons: Array<PromptButton> = isCancelable
? [
{
text: loc._.cancel,
@ -42,6 +49,7 @@ module.exports = (title, text, isCancelable = true, type = 'secure-text', isOKDe
prompt(title, text, buttons, {
type: type,
cancelable: isCancelable,
// @ts-ignore suppressed because its supported only on ios and is absent from type definitions
keyboardType,
});
});

View File

@ -8,12 +8,19 @@
*
* @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 => {
const params = {};
params.showFileImportButton = !!showFileImportButton;
const params = {
showFileImportButton: Boolean(showFileImportButton),
onBarScanned: (data: any) => {},
onDismiss: () => {},
};
params.onBarScanned = function (data) {
params.onBarScanned = function (data: any) {
setTimeout(() => resolve(data.data || data), 1);
navigateFunc(currentScreenName);
};
@ -28,3 +35,5 @@ module.exports = function scanQrHelper(navigateFunc, currentScreenName, showFile
});
});
};
export {};

View File

@ -10,16 +10,32 @@
*
* @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) => {
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 (availableWallets) params.availableWallets = availableWallets;
if (noWalletExplanationText) params.noWalletExplanationText = noWalletExplanationText;
params.onWalletSelect = function (selectedWallet) {
params.onWalletSelect = function (selectedWallet: AbstractWallet) {
if (!selectedWallet) return;
setTimeout(() => resolve(selectedWallet), 1);

View File

@ -65,7 +65,7 @@
"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",
"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: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/*",

View File

@ -22,7 +22,7 @@ import loc, { formatBalanceWithoutSuffix, formatBalance } from '../../loc';
import Biometric from '../../class/biometrics';
import { BlueStorageContext } from '../../blue_modules/storage-context';
import alert from '../../components/Alert';
const prompt = require('../../blue_modules/prompt');
const prompt = require('../../helpers/prompt');
const currency = require('../../blue_modules/currency');
const LnurlPay = () => {

View File

@ -8,7 +8,7 @@ import { BlueLoading, BlueButton, SafeBlueArea, BlueCard, BlueText, BlueSpacing2
import loc from '../loc';
import { BlueStorageContext } from '../blue_modules/storage-context';
import alert from '../components/Alert';
const prompt = require('../blue_modules/prompt');
const prompt = require('../helpers/prompt');
const PlausibleDeniability = () => {
const { cachedPassword, isPasswordInUse, createFakeStorage, resetWallets } = useContext(BlueStorageContext);

View File

@ -42,7 +42,7 @@ import { AbstractHDElectrumWallet } from '../../class/wallets/abstract-hd-electr
import { BlueStorageContext } from '../../blue_modules/storage-context';
import ToolTipMenu from '../../components/TooltipMenu';
const currency = require('../../blue_modules/currency');
const prompt = require('../../blue_modules/prompt');
const prompt = require('../../helpers/prompt');
const fs = require('../../blue_modules/fs');
const scanqr = require('../../helpers/scan-qr');
const btcAddressRx = /^[a-zA-Z0-9]{26,35}$/;

View File

@ -10,7 +10,7 @@ import Biometric from '../../class/biometrics';
import loc from '../../loc';
import { BlueStorageContext } from '../../blue_modules/storage-context';
import alert from '../../components/Alert';
const prompt = require('../../blue_modules/prompt');
const prompt = require('../../helpers/prompt');
const EncryptStorage = () => {
const { isStorageEncrypted, encryptStorage, decryptStorage, saveToDisk } = useContext(BlueStorageContext);

View File

@ -42,7 +42,7 @@ import { encodeUR } from '../../blue_modules/ur';
import QRCodeComponent from '../../components/QRCodeComponent';
import alert from '../../components/Alert';
const prompt = require('../../blue_modules/prompt');
const prompt = require('../../helpers/prompt');
const A = require('../../blue_modules/analytics');
const fs = require('../../blue_modules/fs');
const isDesktop = getSystemName() === 'Mac OS X';

View File

@ -44,7 +44,7 @@ import { isDesktop } from '../../blue_modules/environment';
import { AbstractHDElectrumWallet } from '../../class/wallets/abstract-hd-electrum-wallet';
import alert from '../../components/Alert';
const prompt = require('../../blue_modules/prompt');
const prompt = require('../../helpers/prompt');
const styles = StyleSheet.create({
scrollViewContent: {

View File

@ -10,7 +10,7 @@ import loc from '../../loc';
import { HDSegwitBech32Wallet } from '../../class';
import startImport from '../../class/wallet-import';
import { BlueStorageContext } from '../../blue_modules/storage-context';
import prompt from '../../blue_modules/prompt';
import prompt from '../../helpers/prompt';
const ImportWalletDiscovery = () => {
const navigation = useNavigation();

View File

@ -46,7 +46,7 @@ import { encodeUR } from '../../blue_modules/ur';
import QRCodeComponent from '../../components/QRCodeComponent';
import alert from '../../components/Alert';
const fs = require('../../blue_modules/fs');
const prompt = require('../../blue_modules/prompt');
const prompt = require('../../helpers/prompt');
const ViewEditMultisigCosigners = () => {
const hasLoaded = useRef(false);

View 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;