diff --git a/BlueApp.js b/BlueApp.js index 065680388..55ac200f6 100644 --- a/BlueApp.js +++ b/BlueApp.js @@ -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(); diff --git a/blue_modules/BlueElectrum.d.ts b/blue_modules/BlueElectrum.d.ts index ad2c8ed10..d45fdb7e4 100644 --- a/blue_modules/BlueElectrum.d.ts +++ b/blue_modules/BlueElectrum.d.ts @@ -87,3 +87,5 @@ export function broadcastV2(txhex: string): Promise; export function getTransactionsFullByAddress(address: string): Promise; export function txhexToElectrumTransaction(txhes: string): Transaction; + +export function isDisabled(): Promise; diff --git a/helpers/confirm.js b/helpers/confirm.ts similarity index 89% rename from helpers/confirm.js rename to helpers/confirm.ts index b7bc2d86c..2aa49c33d 100644 --- a/helpers/confirm.js +++ b/helpers/confirm.ts @@ -10,7 +10,7 @@ import loc from '../loc'; * * @return {Promise} */ -module.exports = function (title = 'Are you sure?', text = '') { +module.exports = function (title = 'Are you sure?', text = ''): Promise { return new Promise(resolve => { Alert.alert( title, diff --git a/blue_modules/prompt.js b/helpers/prompt.ts similarity index 75% rename from blue_modules/prompt.js rename to helpers/prompt.ts index a83bd4356..aad0d27bd 100644 --- a/blue_modules/prompt.js +++ b/helpers/prompt.ts @@ -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 => { 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 = 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, }); }); diff --git a/helpers/scan-qr.js b/helpers/scan-qr.ts similarity index 63% rename from helpers/scan-qr.js rename to helpers/scan-qr.ts index 128193ad4..433bbed63 100644 --- a/helpers/scan-qr.js +++ b/helpers/scan-qr.ts @@ -8,12 +8,19 @@ * * @return {Promise} */ -module.exports = function scanQrHelper(navigateFunc, currentScreenName, showFileImportButton = true) { +module.exports = function scanQrHelper( + navigateFunc: (scr: string, params?: any) => void, + currentScreenName: string, + showFileImportButton = true, +): Promise { 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 {}; diff --git a/helpers/select-wallet.js b/helpers/select-wallet.ts similarity index 66% rename from helpers/select-wallet.js rename to helpers/select-wallet.ts index e7ddfd317..4838eac00 100644 --- a/helpers/select-wallet.js +++ b/helpers/select-wallet.ts @@ -10,16 +10,32 @@ * * @returns {Promise} */ -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 { 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); diff --git a/package.json b/package.json index 647063959..369aeca08 100644 --- a/package.json +++ b/package.json @@ -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/*", diff --git a/screen/lnd/lnurlPay.js b/screen/lnd/lnurlPay.js index e0f153d7c..3dff129bd 100644 --- a/screen/lnd/lnurlPay.js +++ b/screen/lnd/lnurlPay.js @@ -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 = () => { diff --git a/screen/plausibledeniability.js b/screen/plausibledeniability.js index 458c7f77b..d88c718b4 100644 --- a/screen/plausibledeniability.js +++ b/screen/plausibledeniability.js @@ -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); diff --git a/screen/send/details.js b/screen/send/details.js index 8b458c452..afa0ddc3e 100644 --- a/screen/send/details.js +++ b/screen/send/details.js @@ -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}$/; diff --git a/screen/settings/encryptStorage.js b/screen/settings/encryptStorage.js index 018c55c60..73bcfad83 100644 --- a/screen/settings/encryptStorage.js +++ b/screen/settings/encryptStorage.js @@ -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); diff --git a/screen/wallets/addMultisigStep2.js b/screen/wallets/addMultisigStep2.js index b7540b39c..b6f812f63 100644 --- a/screen/wallets/addMultisigStep2.js +++ b/screen/wallets/addMultisigStep2.js @@ -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'; diff --git a/screen/wallets/details.js b/screen/wallets/details.js index 37471959d..24b96e33b 100644 --- a/screen/wallets/details.js +++ b/screen/wallets/details.js @@ -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: { diff --git a/screen/wallets/importDiscovery.js b/screen/wallets/importDiscovery.js index 180316634..dffbbb20a 100644 --- a/screen/wallets/importDiscovery.js +++ b/screen/wallets/importDiscovery.js @@ -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(); diff --git a/screen/wallets/viewEditMultisigCosigners.js b/screen/wallets/viewEditMultisigCosigners.js index e4ea8f931..4b04c87ef 100644 --- a/screen/wallets/viewEditMultisigCosigners.js +++ b/screen/wallets/viewEditMultisigCosigners.js @@ -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); diff --git a/typings/react-native-prompt-android.d.ts b/typings/react-native-prompt-android.d.ts new file mode 100644 index 000000000..52ae81499 --- /dev/null +++ b/typings/react-native-prompt-android.d.ts @@ -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 +// 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, + options?: PromptOptions, +): void;