diff --git a/src/front/shared/components/forms/FieldLabel/FieldLabel.tsx b/src/front/shared/components/forms/FieldLabel/FieldLabel.tsx index a0bc70ab4c..59fea0d9a6 100644 --- a/src/front/shared/components/forms/FieldLabel/FieldLabel.tsx +++ b/src/front/shared/components/forms/FieldLabel/FieldLabel.tsx @@ -1,22 +1,31 @@ import React from 'react' -import PropTypes from 'prop-types' import { constants } from 'helpers' - import cx from 'classnames' import cssModules from 'react-css-modules' import styles from './FieldLabel.scss' - const isDark = localStorage.getItem(constants.localStorage.isDark) -const FieldLabel = ({ children, inRow, inDropDown, positionStatic }) => ( -
{children}
-) - -FieldLabel.propTypes = { - inRow: PropTypes.bool, +interface FieldLabelProps { + children: React.ReactNode + inRow?: boolean + inDropDown?: boolean + positionStatic?: boolean } +const FieldLabel = ({ children, inRow, inDropDown, positionStatic }: FieldLabelProps) => ( +
+ {children} +
+) export default cssModules(FieldLabel, styles, { allowMultiple: true }) diff --git a/src/front/shared/components/modals/AddCustomERC20/AddCustomERC20.tsx b/src/front/shared/components/modals/AddCustomERC20/AddCustomERC20.tsx index bcaf59cb10..3aea4d71e0 100644 --- a/src/front/shared/components/modals/AddCustomERC20/AddCustomERC20.tsx +++ b/src/front/shared/components/modals/AddCustomERC20/AddCustomERC20.tsx @@ -22,20 +22,19 @@ import ReactTooltip from 'react-tooltip' import typeforce from 'swap.app/util/typeforce' import Web3 from 'web3' -const serviceURLMainnet = 'https://api.etherscan.io/api?apikey=87F9B9IH33JPVRM5ZVFEK1DQTM64FUZFMV&module=proxy&action=eth_call' -const serviceURLTestnet = 'https://api-rinkeby.etherscan.io/api?apikey=87F9B9IH33JPVRM5ZVFEK1DQTM64FUZFMV&module=proxy&action=eth_call' -const serviceURL = (process.env.MAINNET) ? serviceURLMainnet : serviceURLTestnet +const serviceURLMainnet = + 'https://api.etherscan.io/api?apikey=87F9B9IH33JPVRM5ZVFEK1DQTM64FUZFMV&module=proxy&action=eth_call' +const serviceURLTestnet = + 'https://api-rinkeby.etherscan.io/api?apikey=87F9B9IH33JPVRM5ZVFEK1DQTM64FUZFMV&module=proxy&action=eth_call' +const serviceURL = process.env.MAINNET ? serviceURLMainnet : serviceURLTestnet const nameSignature = '0x06fdde03' const decimalsSignature = '0x313ce567' const symbolSignature = '0x95d89b41' - - @injectIntl @cssModules({ ...styles, ...ownStyle }, { allowMultiple: true }) export default class AddCustomERC20 extends React.Component { - props: any static propTypes = { @@ -58,7 +57,7 @@ export default class AddCustomERC20 extends React.Component { } } - componentDidMount() { } + componentDidMount() {} async getName(address) { const response = await request.get(`${serviceURL}&to=${address}&data=${nameSignature}`) @@ -67,7 +66,7 @@ export default class AddCustomERC20 extends React.Component { return symbol.replace(/\W/g, '') } - + async getSymbol(address) { const response = await request.get(`${serviceURL}&to=${address}&data=${symbolSignature}`) const hexSymbol = response.result @@ -109,7 +108,7 @@ export default class AddCustomERC20 extends React.Component { notFound: true, isShipped: false, }) - setTimeout( () => { + setTimeout(() => { this.setState({ notFound: false, }) @@ -120,8 +119,8 @@ export default class AddCustomERC20 extends React.Component { handleConfirm = async () => { //@ts-ignore const { tokenAddress, tokenSymbol, tokenDecimals } = this.state - actions.token.AddCustomERC20( tokenAddress, tokenSymbol, tokenDecimals ) - actions.core.markCoinAsVisible( tokenSymbol.toUpperCase(), true ) + actions.token.AddCustomERC20(tokenAddress, tokenSymbol, tokenDecimals) + actions.core.markCoinAsVisible(tokenSymbol.toUpperCase(), true) //@ts-ignore this.setState({ step: 'ready', @@ -138,7 +137,7 @@ export default class AddCustomERC20 extends React.Component { return typeforce.isCoinAddress.ETH(tokenAddress) } - handleError = err => { + handleError = (err) => { console.error(err) } @@ -151,25 +150,20 @@ export default class AddCustomERC20 extends React.Component { tokenDecimals, isShipped, notFound, - //@ts-ignore + //@ts-ignore } = this.state const { name, - data: { - currency, - }, + data: { currency }, intl, - //@ts-ignore + //@ts-ignore } = this.props const linked = Link.all(this, 'tokenAddress') - const isDisabled = - !tokenAddress || isShipped - || !this.addressIsCorrect() + const isDisabled = !tokenAddress || isShipped || !this.addressIsCorrect() - const localeLabel = defineMessages({ title: { id: 'customERC20_Title', @@ -184,13 +178,15 @@ export default class AddCustomERC20 extends React.Component { return ( /* //@ts-ignore*/ - +
- { step === 'enterAddress' && + {step === 'enterAddress' && (
- {/* - //@ts-ignore */} @@ -198,45 +194,49 @@ export default class AddCustomERC20 extends React.Component { - {notFound && + {notFound && (
+ defaultMessage="По указаному адресу не найден токен ERC20" + />
- } + )} {tokenAddress && !this.addressIsCorrect() && (
+ defaultMessage="Вы ввели не коректный адрес" + />
)}
-
- } - { step === 'confirm' && + )} + {step === 'confirm' && (
- {/* - //@ts-ignore */} @@ -245,18 +245,17 @@ export default class AddCustomERC20 extends React.Component {
{tokenAddress}
- {/* - //@ts-ignore */} - +
{tokenTitle}
- {/* - //@ts-ignore */} @@ -265,32 +264,39 @@ export default class AddCustomERC20 extends React.Component {
{tokenSymbol}
- {/* - //@ts-ignore */} - +
{tokenDecimals}
-
- } - { step === 'ready' && + )} + {step === 'ready' && (

{ defaultMessage="Токен успешно добавлен" />

-
- } + )}
) } -} \ No newline at end of file +} diff --git a/src/front/shared/components/modals/Approve/Approve.tsx b/src/front/shared/components/modals/Approve/Approve.tsx index c59d3a18cb..8f17fdcc93 100644 --- a/src/front/shared/components/modals/Approve/Approve.tsx +++ b/src/front/shared/components/modals/Approve/Approve.tsx @@ -14,7 +14,6 @@ import { Button } from 'components/controls' import { FieldLabel, Input } from 'components/forms' import { FormattedMessage, injectIntl, defineMessages } from 'react-intl' - const title = defineMessages({ approveTitle: { id: 'Approve66', @@ -25,7 +24,6 @@ const title = defineMessages({ @injectIntl @cssModules(styles) export default class Offer extends React.Component { - props: any static propTypes = { @@ -39,7 +37,9 @@ export default class Offer extends React.Component { handleApprove = () => { const { amount } = this.state - const { data: { contractAddress, name } } = this.props + const { + data: { contractAddress, name }, + } = this.props const message = `Your approve ${amount} tokens on contract address ${contractAddress}` const error = `Please try again later` @@ -49,8 +49,9 @@ export default class Offer extends React.Component { }) return } - //@ts-ignore - actions.token.approve(name, amount) + actions.token + //@ts-ignore + .approve(name, amount) .then(() => { actions.loader.hide() actions.notifications.show(constants.notifications.Message, { message }) @@ -79,15 +80,20 @@ export default class Offer extends React.Component {

+ defaultMessage="Please set the amount limit that the swap smart contract can deduct from your account. We do not recommend setting any limits." + />

- {/* - //@ts-ignore */} - diff --git a/src/front/shared/components/modals/BtcMultisignConfirmTx/BtcMultisignConfirmTx.tsx b/src/front/shared/components/modals/BtcMultisignConfirmTx/BtcMultisignConfirmTx.tsx index 50859f1287..a63021d6f1 100644 --- a/src/front/shared/components/modals/BtcMultisignConfirmTx/BtcMultisignConfirmTx.tsx +++ b/src/front/shared/components/modals/BtcMultisignConfirmTx/BtcMultisignConfirmTx.tsx @@ -27,8 +27,6 @@ import links from 'helpers/links' import redirectTo from 'helpers/redirectTo' import lsDataCache from 'helpers/lsDataCache' - - const langPrefix = `multiSignConfirmTxModal` const langLabels = defineMessages({ title: { @@ -66,18 +64,13 @@ const langLabels = defineMessages({ }) @injectIntl -@connect( - ({ - user: { btcMultisigUserData }, - }) => ({ - btcData: btcMultisigUserData, - }) -) +@connect(({ user: { btcMultisigUserData } }) => ({ + btcData: btcMultisigUserData, +})) @cssModules({ ...defaultStyles, ...styles }, { allowMultiple: true }) export default class BtcMultisignConfirmTx extends React.Component { - props: any - + static propTypes = { name: PropTypes.string, data: PropTypes.object, @@ -99,21 +92,13 @@ export default class BtcMultisignConfirmTx extends React.Component { componentDidMount() { setTimeout(async () => { const { - data: { - txData, - txId, - } + data: { txData, txId }, } = this.props if (txId) { const txData = await actions.multisigTx.fetchTx(txId) - const { - destination: address, - sender: from, - amount, - } = txData - + const { destination: address, sender: from, amount } = txData const wallet = actions.btcmultisig.addressToWallet(from) @@ -124,35 +109,38 @@ export default class BtcMultisignConfirmTx extends React.Component { return } - this.setState({ - step: `txInfo`, - txId, - txData: { - ...txData, - wallet, + this.setState( + { + step: `txInfo`, + txId, + txData: { + ...txData, + wallet, + }, + address, + from, + amount, }, - address, - from, - amount, - }, () => { - // Fetching full tx info (rawTX) - actions.multisigTx.fetchRawTx( from , txId).then((txAuthedData) => { - if (txAuthedData) { - actions.btcmultisig.parseRawTX(txAuthedData.rawTx).then((txDataParsed) => { + () => { + // Fetching full tx info (rawTX) + actions.multisigTx.fetchRawTx(from, txId).then((txAuthedData) => { + if (txAuthedData) { + actions.btcmultisig.parseRawTX(txAuthedData.rawTx).then((txDataParsed) => { + this.setState({ + txRaw: txAuthedData.rawTx, + txData: txDataParsed, + isTxHolder: wallet.publicKey.toString(`Hex`) === txAuthedData.holder, + isControlFetching: false, + }) + }) + } else { this.setState({ - txRaw: txAuthedData.rawTx, - txData: txDataParsed, - isTxHolder: (wallet.publicKey.toString(`Hex`) === txAuthedData.holder), - isControlFetching: false, + step: `dinned`, }) - }) - } else { - this.setState({ - step: `dinned`, - }) - } - }) - }) + } + }) + } + ) } else { const txDataParsed = await actions.btcmultisig.parseRawTX(txData) @@ -179,32 +167,23 @@ export default class BtcMultisignConfirmTx extends React.Component { this.handleClose() } - handleConfirm = async() => { - const { - txId: useBackendId, - txRaw, - txData, - from, - address: to, - amount, - } = this.state + handleConfirm = async () => { + const { txId: useBackendId, txRaw, txData, from, address: to, amount } = this.state - const { - name, - } = this.props + const { name } = this.props this.setState({ isConfirming: true, }) - const signedTX = await actions.btcmultisig.signMultiSign( txRaw , txData.wallet ) - const btcTxId = await actions.btcmultisig.broadcastTx( signedTX ) + const signedTX = await actions.btcmultisig.signMultiSign(txRaw, txData.wallet) + const btcTxId = await actions.btcmultisig.broadcastTx(signedTX) let txId = false if (btcTxId && btcTxId.txid) txId = btcTxId.txid if (useBackendId) { - const backendId = await actions.multisigTx.confirmTx( from, useBackendId, signedTX, txId ) + const backendId = await actions.multisigTx.confirmTx(from, useBackendId, signedTX, txId) } if (txId) { @@ -235,13 +214,9 @@ export default class BtcMultisignConfirmTx extends React.Component { } handleReject = async () => { - const { - txId: useBackendId, - txData, - from, - } = this.state + const { txId: useBackendId, txData, from } = this.state if (useBackendId) { - const backendId = await actions.multisigTx.rejectTx( from, useBackendId ) + const backendId = await actions.multisigTx.rejectTx(from, useBackendId) this.handleClose() } } @@ -264,9 +239,7 @@ export default class BtcMultisignConfirmTx extends React.Component { const { name, intl, - data: { - showCloseButton, - }, + data: { showCloseButton }, } = this.props const { @@ -285,54 +258,49 @@ export default class BtcMultisignConfirmTx extends React.Component { const linked = Link.all(this, 'address', 'amount', 'from') return ( - + {step !== `dinned` && (

- +

)}
{step === `fetchgin` && (

- +

)} {step === `dinned` && (

- +

-
)} {step === `txInfo` && ( -
- {/* - //@ts-ignore */} +
- {" "} + {' '} - +
-
- {/* - //@ts-ignore */} +
- {" "} + {' '} -
+
{
- +
-
+

{txData.wallet.balance} {`BTC`}

- {/* - //@ts-ignore */}
- +
- {(isControlFetching) ? ( + {isControlFetching ? (
@@ -380,17 +337,19 @@ export default class BtcMultisignConfirmTx extends React.Component { onClick={this.handleConfirm} fullWidth > - + )}
)} diff --git a/src/front/shared/components/modals/ImportKeys/ImportKeys.tsx b/src/front/shared/components/modals/ImportKeys/ImportKeys.tsx index 21c7884df0..d929ac3193 100644 --- a/src/front/shared/components/modals/ImportKeys/ImportKeys.tsx +++ b/src/front/shared/components/modals/ImportKeys/ImportKeys.tsx @@ -18,7 +18,6 @@ import { FormattedMessage, defineMessages, injectIntl } from 'react-intl' import { localisedUrl } from 'helpers/locale' import config from 'helpers/externalConfig' - const title = defineMessages({ Import: { id: 'Import', @@ -29,7 +28,6 @@ const title = defineMessages({ @injectIntl @cssModules(styles) export default class ImportKeys extends Component { - state = { ethKey: '', btcKey: '', @@ -139,7 +137,7 @@ export default class ImportKeys extends Component { const { onCloseLink } = this.state const { isImportedBtc, isImportedEth } = this.state - if ([isImportedBtc, isImportedEth].filter(i => i).length > 1) { + if ([isImportedBtc, isImportedEth].filter((i) => i).length > 1) { this.handleGoTo(links.home) } else { this.handleGoTo(onCloseLink) @@ -166,8 +164,12 @@ export default class ImportKeys extends Component { render() { const { - isSubmittedEth, isSubmittedBtc, - isImportedEth, isImportedBtc, isDisabled, keySave, + isSubmittedEth, + isSubmittedBtc, + isImportedEth, + isImportedBtc, + isDisabled, + keySave, } = this.state const { intl, data } = this.props @@ -175,31 +177,58 @@ export default class ImportKeys extends Component { const linked = Link.all(this, 'ethKey', 'btcKey') if (isSubmittedEth) { - linked.ethKey.check((value) => value !== '', ) - linked.ethKey.check((value) => value.length > 40, ) + linked.ethKey.check( + (value) => value !== '', + + ) + linked.ethKey.check( + (value) => value.length > 40, + + ) } if (isSubmittedBtc) { - linked.btcKey.check((value) => value !== '', ) - linked.btcKey.check((value) => value.length > 27, ) - linked.btcKey.check(() => - this.handleBtcImportKey(), ) + linked.btcKey.check( + (value) => value !== '', + + ) + linked.btcKey.check( + (value) => value.length > 27, + + ) + linked.btcKey.check( + () => this.handleBtcImportKey(), + + ) } return ( /* //@ts-ignore */ - +

- +

{(!config.opts.curEnabled || config.opts.curEnabled.eth) && ( <> - {/* - //@ts-ignore */} - + { )} {(!config.opts.curEnabled || config.opts.curEnabled.btc) && ( <> - {/* - //@ts-ignore */} - + { /> )} - { - !keySave && ( - - - - ) - } + {!keySave && ( + + + + )} diff --git a/src/front/shared/components/modals/InvoiceModal/InvoiceModal.tsx b/src/front/shared/components/modals/InvoiceModal/InvoiceModal.tsx index e52b4e4489..da6112e053 100644 --- a/src/front/shared/components/modals/InvoiceModal/InvoiceModal.tsx +++ b/src/front/shared/components/modals/InvoiceModal/InvoiceModal.tsx @@ -33,33 +33,31 @@ import { links } from 'helpers' import { localisedUrl } from 'helpers/locale' import redirectTo from 'helpers/redirectTo' - - const localeLabel = defineMessages({ title: { id: 'invoiceModal_Title', - defaultMessage: 'Выставление счета на пополнение' + defaultMessage: 'Выставление счета на пополнение', }, addressPlaceholder: { id: 'invoiceModal_addressPlaceholder', - defaultMessage: 'Введите адрес {currency} кошелька' + defaultMessage: 'Введите адрес {currency} кошелька', }, destiAddressPlaceholder: { id: 'invoiceModal_destiAddressPlaceholder', - defaultMessage: 'Введите адрес {currency} кошелька' + defaultMessage: 'Введите адрес {currency} кошелька', }, amountPlaceholder: { id: 'invoiceModal_amountPlaceholder', - defaultMessage: 'Введите сумму' + defaultMessage: 'Введите сумму', }, contactPlaceholder: { id: 'invoiceModal_contactPlaceholder', - defaultMessage: 'Обязательное поле' + defaultMessage: 'Обязательное поле', }, labelPlaceholder: { id: 'invoiceModal_labelPlaceholder', - defaultMessage: 'Укажите комментарий к счету' - } + defaultMessage: 'Укажите комментарий к счету', + }, }) @injectIntl @@ -74,28 +72,20 @@ const localeLabel = defineMessages({ btcMultisigSMSData, btcMultisigUserData, tokensData, - } + }, }) => ({ currencies: currencies.items, - items: [ - ethData, - btcData, - ghostData, - nextData, - btcMultisigSMSData, - btcMultisigUserData, - ], - tokenItems: [...Object.keys(tokensData).map(k => tokensData[k])] + items: [ethData, btcData, ghostData, nextData, btcMultisigSMSData, btcMultisigUserData], + tokenItems: [...Object.keys(tokensData).map((k) => tokensData[k])], }) ) @cssModules({ ...styles, ...ownStyle }, { allowMultiple: true }) export default class InvoiceModal extends React.Component { - props: any static propTypes = { name: PropTypes.string, - data: PropTypes.object + data: PropTypes.object, } constructor(data) { @@ -110,7 +100,7 @@ export default class InvoiceModal extends React.Component { } = data let infoAboutCurrency - items.map(item => { + items.map((item) => { if (item.currency === currency) { infoAboutCurrency = item.infoAboutCurrency } @@ -118,14 +108,15 @@ export default class InvoiceModal extends React.Component { const currentDecimals = constants.tokenDecimals[currency.toLowerCase()] - const multiplier = (infoAboutCurrency && infoAboutCurrency.price_fiat) ? infoAboutCurrency.price_fiat : 1 + const multiplier = + infoAboutCurrency && infoAboutCurrency.price_fiat ? infoAboutCurrency.price_fiat : 1 this.state = { isShipped: false, payerAddress, openScanCam: '', address: toAddress || '', - toAddressEnabled: !(!toAddress), + toAddressEnabled: !!toAddress, destination: address, amount: '', minus: '', @@ -136,7 +127,7 @@ export default class InvoiceModal extends React.Component { error: false, infoAboutCurrency, multiplier, - rubRates: 62.34 + rubRates: 62.34, } this.getRubRates() @@ -147,13 +138,13 @@ export default class InvoiceModal extends React.Component { getRubRates() { request .get('https://www.cbr-xml-daily.ru/daily_json.js', { - cacheResponse: 60 * 60 * 1000 + cacheResponse: 60 * 60 * 1000, }) - .then(rates => { + .then((rates) => { if (rates && rates.Valute && rates.Valute.USD) { const rubRates = rates.Valute.USD.Value this.setState({ - rubRates + rubRates, }) } }) @@ -166,7 +157,7 @@ export default class InvoiceModal extends React.Component { if (isShipped) return this.setState({ - isShipped: true + isShipped: true, }) let currency = getCurrencyKey(data.currency, true).toUpperCase() @@ -193,7 +184,7 @@ export default class InvoiceModal extends React.Component { } this.setState({ - isShipped: false + isShipped: false, }) } @@ -203,7 +194,7 @@ export default class InvoiceModal extends React.Component { addressIsCorrect(otherAddress) { const { - data: { currency } + data: { currency }, } = this.props const { address, isEthToken } = this.state const checkAddress = otherAddress ? otherAddress : address @@ -220,56 +211,56 @@ export default class InvoiceModal extends React.Component { const { openScanCam } = this.state this.setState(() => ({ - openScanCam: !openScanCam + openScanCam: !openScanCam, })) } - handleDollarValue = value => { + handleDollarValue = (value) => { const { rubRates, currentDecimals, multiplier } = this.state this.setState({ amountUSD: value, amountRUB: value ? (value * rubRates).toFixed(0) : '', - amount: value ? (value / multiplier).toFixed(currentDecimals) : '' + amount: value ? (value / multiplier).toFixed(currentDecimals) : '', }) } - handleRubValue = value => { + handleRubValue = (value) => { const { rubRates, currentDecimals, multiplier } = this.state this.setState({ amountRUB: value, amountUSD: value ? (value / rubRates).toFixed(2) : '', - amount: value ? (value / multiplier / rubRates).toFixed(currentDecimals) : '' + amount: value ? (value / multiplier / rubRates).toFixed(currentDecimals) : '', }) } - handleAmount = value => { + handleAmount = (value) => { const { rubRates, multiplier } = this.state this.setState({ amountRUB: value ? (value * multiplier * rubRates).toFixed(0) : '', amountUSD: value ? (value * multiplier).toFixed(2) : '', - amount: value + amount: value, }) } - handleError = err => { + handleError = (err) => { console.error(err) } - handleScan = data => { + handleScan = (data) => { if (data) { this.setState(() => ({ - address: data.includes(':') ? data.split(':')[1] : data + address: data.includes(':') ? data.split(':')[1] : data, })) this.openScan() } } - handleBuyCurrencySelect = value => { + handleBuyCurrencySelect = (value) => { this.setState({ - selectedValue: value.name + selectedValue: value.name, }) } @@ -294,13 +285,23 @@ export default class InvoiceModal extends React.Component { const { name, data: { currency }, - intl + intl, } = this.props - const linked = Link.all(this, 'address', 'destination', 'amountUSD', 'amountRUB', 'amount', 'contact', 'label') + const linked = Link.all( + this, + 'address', + 'destination', + 'amountUSD', + 'amountRUB', + 'amount', + 'contact', + 'label' + ) - //@ts-ignore - const isDisabled = !amount || isShipped || !destination || !contact || (address && !this.addressIsCorrect()) + const isDisabled = + //@ts-ignore + !amount || isShipped || !destination || !contact || (address && !this.addressIsCorrect()) return ( { disableClose={this.props.data.disableClose} > {openScanCam && ( - + )}
{toAddressEnabled && (
- {/* - //@ts-ignore */} - - + + { valueLink={linked.address} focusOnInit pattern="0-9a-zA-Z:" - placeholder={intl.formatMessage(localeLabel.addressPlaceholder, { currency: currency.toUpperCase() })} + placeholder={intl.formatMessage(localeLabel.addressPlaceholder, { + currency: currency.toUpperCase(), + })} qr openScan={this.openScan} /> @@ -333,16 +341,20 @@ export default class InvoiceModal extends React.Component { //@ts-ignore */} {address && !this.addressIsCorrect() && (
- +
)}
)}
- {/* - //@ts-ignore */} - - + + { withMargin pattern="0-9a-zA-Z:" placeholder={intl.formatMessage(localeLabel.destiAddressPlaceholder, { - currency: currency.toUpperCase() + currency: currency.toUpperCase(), })} qr openScan={this.openScan} @@ -366,9 +378,7 @@ export default class InvoiceModal extends React.Component { )}
- {/* - //@ts-ignore */} - + @@ -384,8 +394,8 @@ export default class InvoiceModal extends React.Component { onKeyDown={inputReplaceCommaWithDot} /> ) : ( - '' - )} + '' + )} {this.state.selectedValue === 'RUB' ? ( { onKeyDown={inputReplaceCommaWithDot} /> ) : ( - '' - )} + '' + )} {this.state.selectedValue === 'USD' ? ( { onKeyDown={inputReplaceCommaWithDot} /> ) : ( - '' - )} + '' + )} {/* //@ts-ignore */} @@ -423,6 +433,7 @@ export default class InvoiceModal extends React.Component { selectedValue={selectedValue} onSelect={this.handleBuyCurrencySelect} selectedItemRender={(item) => item.fullTitle} + //@ts-ignore isToggleActive currencies={[ { @@ -430,31 +441,32 @@ export default class InvoiceModal extends React.Component { icon: 'rub', name: 'RUB', title: 'RUB', - value: 'RUB' + value: 'RUB', }, { fullTitle: 'bitcoin', icon: 'btc', name: 'BTC', title: 'BTC', - value: 'BTC' + value: 'BTC', }, { fullTitle: 'USD', icon: 'usd', name: 'USD', title: 'USD', - value: 'USD' - } + value: 'USD', + }, ]} />
- {/* - //@ts-ignore */} - + - + { />
- {/* - //@ts-ignore */} - + @@ -486,10 +496,10 @@ export default class InvoiceModal extends React.Component { ) : ( - - - - )} + + + + )} {error && (
@@ -500,7 +510,7 @@ export default class InvoiceModal extends React.Component { errorName: intl.formatMessage(error.name), errorMessage: intl.formatMessage(error.message), br:
, - currency: `${currency}` + currency: `${currency}`, }} />
diff --git a/src/front/shared/components/modals/RegisterPINProtected/RegisterPINProtected.tsx b/src/front/shared/components/modals/RegisterPINProtected/RegisterPINProtected.tsx index e9fa35b8c0..fefe318da9 100644 --- a/src/front/shared/components/modals/RegisterPINProtected/RegisterPINProtected.tsx +++ b/src/front/shared/components/modals/RegisterPINProtected/RegisterPINProtected.tsx @@ -10,7 +10,6 @@ import cssModules from 'react-css-modules' import styles from '../Styles/default.scss' import ownStyle from './RegisterPINProtected.scss' - import { BigNumber } from 'bignumber.js' import Modal from 'components/modal/Modal/Modal' import FieldLabel from 'components/forms/FieldLabel/FieldLabel' @@ -48,7 +47,7 @@ const langs = defineMessages({ }, pleaseSaveMnemonicToContinue: { id: `${langPrefix}_SaveYourMnemonic`, - defaultMessage: `Пожалуйста сохраните свою секретную фразу.` + defaultMessage: `Пожалуйста сохраните свою секретную фразу.`, }, buttonSaveMnemonic: { id: `${langPrefix}_ButtonSaveMnemonic`, @@ -176,7 +175,6 @@ const langs = defineMessages({ }, }) - @injectIntl @connect(({ user: { btcData, btcMultisigPinData } }) => ({ btcData, @@ -184,30 +182,25 @@ const langs = defineMessages({ })) @cssModules({ ...styles, ...ownStyle }, { allowMultiple: true }) export default class RegisterPINProtected extends React.Component { - props: any static propTypes = { name: PropTypes.string, - data: PropTypes.object - }; + data: PropTypes.object, + } constructor(props) { super(props) - const { - data: { - initStep, - }, + data: { initStep }, } = props const generatedKey = localStorage.getItem(constants.privateKeyNames.btcSmsMnemonicKeyGenerated) const mnemonic = localStorage.getItem(constants.privateKeyNames.twentywords) - const mnemonicSaved = (mnemonic === `-`) - const useGeneratedKeyEnabled = !(!generatedKey) - + const mnemonicSaved = mnemonic === `-` + const useGeneratedKeyEnabled = !!generatedKey let step = 'enterPinCode' if (useGeneratedKeyEnabled && !mnemonicSaved) step = 'saveMnemonicWords' @@ -245,90 +238,104 @@ export default class RegisterPINProtected extends React.Component { } handleRestoreWallet = async () => { - const { - mnemonic, - } = this.state + const { mnemonic } = this.state - this.setState({ - error: false, - isShipped: true, - }, async () => { - if (!mnemonic || !actions.btc.validateMnemonicWords(mnemonic.trim())) { - this.setState({ - error: , - isShipped: false, - }) - return - } + this.setState( + { + error: false, + isShipped: true, + }, + async () => { + if (!mnemonic || !actions.btc.validateMnemonicWords(mnemonic.trim())) { + this.setState({ + error: , + isShipped: false, + }) + return + } + + if (!actions.btcmultisig.checkPinCanRestory(mnemonic.trim())) { + this.setState({ + error: , + isShipped: false, + }) + return + } + + await actions.btcmultisig.addPinWallet(mnemonic.trim()) + + this.generateRestoreInstruction() - if (!actions.btcmultisig.checkPinCanRestory(mnemonic.trim())) { this.setState({ - error: , isShipped: false, + step: 'ready', }) - return } - - await actions.btcmultisig.addPinWallet(mnemonic.trim()) - - this.generateRestoreInstruction() - - this.setState({ - isShipped: false, - step: 'ready', - }) - }) + ) } handleCopyMnemonic = async () => { - this.setState({ - isMnemonicCopied: true, - }, () => { - setTimeout(() => { - this.setState({ - isMnemonicCopied: false, - }) - }, 1000) - }) + this.setState( + { + isMnemonicCopied: true, + }, + () => { + setTimeout(() => { + this.setState({ + isMnemonicCopied: false, + }) + }, 1000) + } + ) } handleCopyInstruction = async () => { - this.setState({ - isInstructionCopied: true, - }, () => { - setTimeout(() => { - this.setState({ - isInstructionCopied: false, - }) - }, 1000) - }) + this.setState( + { + isInstructionCopied: true, + }, + () => { + setTimeout(() => { + this.setState({ + isInstructionCopied: false, + }) + }, 1000) + } + ) } handleDownloadInstruction = async () => { - const { - restoreInstruction, - } = this.state - - this.setState({ - isInstructionDownloaded: true, - }, () => { - const element = document.createElement('a') - const message = 'Check your browser downloads' - - element.setAttribute('href', `data:text/plaincharset=utf-8,${encodeURIComponent(restoreInstruction)}`) - element.setAttribute('download', `${window.location.hostname}_btc_sms_protected_keys_${moment().format('DD.MM.YYYY')}.txt`) - - element.style.display = 'none' - document.body.appendChild(element) - element.click() - document.body.removeChild(element) + const { restoreInstruction } = this.state - setTimeout(() => { - this.setState({ - isInstructionDownloaded: false, - }) - }, 1000) - }) + this.setState( + { + isInstructionDownloaded: true, + }, + () => { + const element = document.createElement('a') + const message = 'Check your browser downloads' + + element.setAttribute( + 'href', + `data:text/plaincharset=utf-8,${encodeURIComponent(restoreInstruction)}` + ) + element.setAttribute( + 'download', + `${window.location.hostname}_btc_sms_protected_keys_${moment().format('DD.MM.YYYY')}.txt` + ) + + element.style.display = 'none' + document.body.appendChild(element) + element.click() + document.body.removeChild(element) + + setTimeout(() => { + this.setState({ + isInstructionDownloaded: false, + }) + }, 1000) + } + ) } handleUsePin = () => { @@ -351,17 +358,20 @@ export default class RegisterPINProtected extends React.Component { } handleGenerateMnemonic = async () => { - this.setState({ - isMnemonicGenerated: true, - isMnemonicValid: true, - mnemonic: actions.btc.getRandomMnemonicWords(), - }, () => { - setTimeout(() => { - this.setState({ - isMnemonicGenerated: false, - }) - }, 1000) - }) + this.setState( + { + isMnemonicGenerated: true, + isMnemonicValid: true, + mnemonic: actions.btc.getRandomMnemonicWords(), + }, + () => { + setTimeout(() => { + this.setState({ + isMnemonicGenerated: false, + }) + }, 1000) + } + ) } handleFinish = async () => { @@ -387,14 +397,14 @@ export default class RegisterPINProtected extends React.Component { actions.modals.open(constants.modals.SaveMnemonicModal, { onClose: () => { const mnemonic = localStorage.getItem(constants.privateKeyNames.twentywords) - const mnemonicSaved = (mnemonic === `-`) - const step = (mnemonicSaved) ? 'enterPhoneAndMnemonic' : 'saveMnemonicWords' + const mnemonicSaved = mnemonic === `-` + const step = mnemonicSaved ? 'enterPhoneAndMnemonic' : 'saveMnemonicWords' this.setState({ mnemonicSaved, step, }) - } + }, }) } @@ -413,51 +423,46 @@ export default class RegisterPINProtected extends React.Component { } generateRestoreInstruction = () => { - const { - mnemonic, - mnemonicWallet, - useGeneratedKey, - generatedKey, - } = this.state + const { mnemonic, mnemonicWallet, useGeneratedKey, generatedKey } = this.state - const { - btcData, - btcMultisigPinData, - } = this.props + const { btcData, btcMultisigPinData } = this.props let restoreInstruction = '' restoreInstruction = `Wallet address:\r\n` - restoreInstruction+= `${btcMultisigPinData.address}\r\n` - restoreInstruction+= `To withdraw funds create transaction using this code https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts#L193\r\n` - restoreInstruction+= `\r\n` - restoreInstruction+= `Public keys for create Multisig (2of3) wallet:\r\n` - if (btcMultisigPinData.publicKeys[0]) restoreInstruction+=`${btcMultisigPinData.publicKeys[0].toString('Hex')}\r\n` - if (btcMultisigPinData.publicKeys[1]) restoreInstruction+=`${btcMultisigPinData.publicKeys[1].toString('Hex')}\r\n` - if (btcMultisigPinData.publicKeys[2]) restoreInstruction+=`${btcMultisigPinData.publicKeys[2].toString('Hex')}\r\n` - restoreInstruction+= `\r\n` - restoreInstruction+= `Hot wallet private key (WIF) (first of three for sign tx):\r\n` - restoreInstruction+= `Wallet delivery path from your secret phrase:\r\n` - restoreInstruction+= `m/44'/0'/0'/0/0\r\n` - restoreInstruction+= `${btcData.privateKey}\r\n` - restoreInstruction+= `*** (this private key stored in your browser)\r\n` - restoreInstruction+= `\r\n` + restoreInstruction += `${btcMultisigPinData.address}\r\n` + restoreInstruction += `To withdraw funds create transaction using this code https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts#L193\r\n` + restoreInstruction += `\r\n` + restoreInstruction += `Public keys for create Multisig (2of3) wallet:\r\n` + if (btcMultisigPinData.publicKeys[0]) + restoreInstruction += `${btcMultisigPinData.publicKeys[0].toString('Hex')}\r\n` + if (btcMultisigPinData.publicKeys[1]) + restoreInstruction += `${btcMultisigPinData.publicKeys[1].toString('Hex')}\r\n` + if (btcMultisigPinData.publicKeys[2]) + restoreInstruction += `${btcMultisigPinData.publicKeys[2].toString('Hex')}\r\n` + restoreInstruction += `\r\n` + restoreInstruction += `Hot wallet private key (WIF) (first of three for sign tx):\r\n` + restoreInstruction += `Wallet delivery path from your secret phrase:\r\n` + restoreInstruction += `m/44'/0'/0'/0/0\r\n` + restoreInstruction += `${btcData.privateKey}\r\n` + restoreInstruction += `*** (this private key stored in your browser)\r\n` + restoreInstruction += `\r\n` if (!useGeneratedKey) { - restoreInstruction+= `Secret mnemonic:\r\n` - restoreInstruction+= `${mnemonic}\r\n` - restoreInstruction+= `Wallet delivery path for mnemonic:\r\n` - restoreInstruction+= `m/44'/0'/0'/0/0\r\n` - restoreInstruction+= `Private key (WIF) of wallet, generated from mnemonic:\r\n` - restoreInstruction+= `(DELETE THIS LINE!) ${mnemonicWallet.WIF}\r\n` - restoreInstruction+= `*** (this private key does not stored anywhere! but in case if our 2fa server does down, you can withdraw your fond using this private key)\r\n` + restoreInstruction += `Secret mnemonic:\r\n` + restoreInstruction += `${mnemonic}\r\n` + restoreInstruction += `Wallet delivery path for mnemonic:\r\n` + restoreInstruction += `m/44'/0'/0'/0/0\r\n` + restoreInstruction += `Private key (WIF) of wallet, generated from mnemonic:\r\n` + restoreInstruction += `(DELETE THIS LINE!) ${mnemonicWallet.WIF}\r\n` + restoreInstruction += `*** (this private key does not stored anywhere! but in case if our 2fa server does down, you can withdraw your fond using this private key)\r\n` } else { - restoreInstruction+= `Second of three for sign tx:\r\n` - restoreInstruction+= `Wallet delivery path from your secret phrase:\r\n` - restoreInstruction+= `m/44'/0'/0'/0/1\r\n` - restoreInstruction+= `\r\n` + restoreInstruction += `Second of three for sign tx:\r\n` + restoreInstruction += `Wallet delivery path from your secret phrase:\r\n` + restoreInstruction += `m/44'/0'/0'/0/1\r\n` + restoreInstruction += `\r\n` } - restoreInstruction+= `If our service is unavailable, use a local copy of the wallet.\r\n` - restoreInstruction+= `https://swaponline.github.io/2fa_wallet.zip\r\n` + restoreInstruction += `If our service is unavailable, use a local copy of the wallet.\r\n` + restoreInstruction += `https://swaponline.github.io/2fa_wallet.zip\r\n` this.setState({ restoreInstruction, @@ -474,66 +479,69 @@ export default class RegisterPINProtected extends React.Component { generatedKey, } = this.state - this.setState({ - error: false, - isShipped: true, - pinServerOffline: false, - isWalletLockedOtherPin: false, - }, async () => { - if (!pinCode || pinCode.length < 4) { - this.setState({ - error: , - isShipped: false, - }) - return - } - if (pinCode != pinCodeConfirm) { - this.setState({ - error: , - isShipped: false, - }) - return - } - const result = await actions.btcmultisig.register_PIN( - pinCode, - (mnemonic) ? mnemonic.trim() : false, - (useGeneratedKey && useGeneratedKeyEnabled) ? generatedKey : false - ) + this.setState( + { + error: false, + isShipped: true, + pinServerOffline: false, + isWalletLockedOtherPin: false, + }, + async () => { + if (!pinCode || pinCode.length < 4) { + this.setState({ + error: , + isShipped: false, + }) + return + } + if (pinCode != pinCodeConfirm) { + this.setState({ + error: , + isShipped: false, + }) + return + } + const result = await actions.btcmultisig.register_PIN( + pinCode, + mnemonic ? mnemonic.trim() : false, + useGeneratedKey && useGeneratedKeyEnabled ? generatedKey : false + ) - if (result && result.answer && result.answer == 'ok') { - this.generateRestoreInstruction() - this.setState({ - isShipped: false, - step: 'ready', - }) - } else { - if (result && result.error == 'Already registered') { + if (result && result.answer && result.answer == 'ok') { this.generateRestoreInstruction() this.setState({ isShipped: false, step: 'ready', }) } else { - if (result && result.error == 'This wallet already locked by other pin code') { - // Кошелек зарегистрирован на другой номер телефона - // Может быть так, что человек потерял телефон или забыл его - // Даем возможность подключить кошелек, чтобы если у клиента есть - // валидный mnemonic - он мог разблокировать средства + if (result && result.error == 'Already registered') { + this.generateRestoreInstruction() this.setState({ isShipped: false, - isWalletLockedOtherPin: true, + step: 'ready', }) } else { - const pinServerOffline = (result === false) - this.setState({ - isShipped: false, - pinServerOffline, - error: (result && result.error) ? result.error : 'Unknown error', - }) + if (result && result.error == 'This wallet already locked by other pin code') { + // Кошелек зарегистрирован на другой номер телефона + // Может быть так, что человек потерял телефон или забыл его + // Даем возможность подключить кошелек, чтобы если у клиента есть + // валидный mnemonic - он мог разблокировать средства + this.setState({ + isShipped: false, + isWalletLockedOtherPin: true, + }) + } else { + const pinServerOffline = result === false + this.setState({ + isShipped: false, + pinServerOffline, + error: result && result.error ? result.error : 'Unknown error', + }) + } } } } - }) + ) } render() { @@ -559,17 +567,10 @@ export default class RegisterPINProtected extends React.Component { showFinalInstruction, } = this.state - const { - name, - intl, - btcData, - btcMultisigPinData, - } = this.props + const { name, intl, btcData, btcMultisigPinData } = this.props const linked = Link.all(this, 'pinCode', 'pinCodeConfirm', 'mnemonic') - - return (
@@ -578,19 +579,19 @@ export default class RegisterPINProtected extends React.Component {

- +
- +

@@ -605,9 +606,7 @@ export default class RegisterPINProtected extends React.Component {

- {/* - //@ts-ignore */} - + {

- +
- +

{isWalletLockedOtherPin && (
@@ -651,9 +650,7 @@ export default class RegisterPINProtected extends React.Component {
)}
- {/* - //@ts-ignore */} - + { />
- {/* - //@ts-ignore */} - + { )} )} - {step === "ready" && ( + {step === 'ready' && (
finish
- +
@@ -725,16 +727,21 @@ export default class RegisterPINProtected extends React.Component {
{restoreInstruction}
- +
- - -
- ); + ) } } diff --git a/src/front/shared/components/modals/RegisterSMSProtected/RegisterSMSProtected.tsx b/src/front/shared/components/modals/RegisterSMSProtected/RegisterSMSProtected.tsx index 6b13109e29..2c211bef37 100644 --- a/src/front/shared/components/modals/RegisterSMSProtected/RegisterSMSProtected.tsx +++ b/src/front/shared/components/modals/RegisterSMSProtected/RegisterSMSProtected.tsx @@ -1,30 +1,29 @@ -import React, { Fragment } from "react"; -import PropTypes from "prop-types"; -import { constants } from "helpers"; -import actions from "redux/actions"; -import Link from "local_modules/sw-valuelink"; -import { connect } from "redaction"; - -import cssModules from "react-css-modules"; -import styles from "../Styles/default.scss"; +import React, { Fragment } from 'react' +import PropTypes from 'prop-types' +import { constants } from 'helpers' +import actions from 'redux/actions' +import Link from 'local_modules/sw-valuelink' +import { connect } from 'redaction' + +import cssModules from 'react-css-modules' +import styles from '../Styles/default.scss' import ownStyle from './RegisterSMSProtected.scss' import { isValidPhoneNumber } from 'react-phone-number-input' -import Modal from "components/modal/Modal/Modal"; -import FieldLabel from "components/forms/FieldLabel/FieldLabel"; -import Input from "components/forms/Input/Input"; -import { PhoneInput } from "components/forms/PhoneInput" -import Button from "components/controls/Button/Button"; -import { FormattedMessage, injectIntl, defineMessages } from "react-intl"; +import Modal from 'components/modal/Modal/Modal' +import FieldLabel from 'components/forms/FieldLabel/FieldLabel' +import Input from 'components/forms/Input/Input' +import { PhoneInput } from 'components/forms/PhoneInput' +import Button from 'components/controls/Button/Button' +import { FormattedMessage, injectIntl, defineMessages } from 'react-intl' -import typeforce from "swap.app/util/typeforce"; +import typeforce from 'swap.app/util/typeforce' // import { isCoinAddress } from 'swap.app/util/typeforce' import CopyToClipboard from 'react-copy-to-clipboard' import moment from 'moment/moment' import finishSvg from './images/finish.svg' - @injectIntl @connect(({ user: { btcData, btcMultisigSMSData } }) => ({ btcData, @@ -32,32 +31,27 @@ import finishSvg from './images/finish.svg' })) @cssModules({ ...styles, ...ownStyle }, { allowMultiple: true }) export default class RegisterSMSProtected extends React.Component { - props: any static propTypes = { name: PropTypes.string, - data: PropTypes.object - }; + data: PropTypes.object, + } constructor(props) { super(props) let { - data: { - version, - initStep, - }, + data: { version, initStep }, } = this.props - version = (version) ? version : '2of3' // 2of2 + version = version ? version : '2of3' // 2of2 const generatedKey = localStorage.getItem(constants.privateKeyNames.btcSmsMnemonicKeyGenerated) const mnemonic = localStorage.getItem(constants.privateKeyNames.twentywords) - const mnemonicSaved = (mnemonic === `-`) - const useGeneratedKeyEnabled = !(!generatedKey) - + const mnemonicSaved = mnemonic === `-` + const useGeneratedKeyEnabled = !!generatedKey let step = 'enterPhoneAndMnemonic' // "enterPhone", if (useGeneratedKeyEnabled && !mnemonicSaved) step = 'saveMnemonicWords' @@ -74,7 +68,7 @@ export default class RegisterSMSProtected extends React.Component { phone: window.DefaultCountryCode || '', step, error: false, - smsCode: "", + smsCode: '', smsConfirmed: false, isShipped: false, showFinalInstruction, @@ -82,7 +76,7 @@ export default class RegisterSMSProtected extends React.Component { generatedKey, useGeneratedKeyEnabled, mnemonicSaved, - mnemonic: (version === '2of3') ? actions.btc.getRandomMnemonicWords() : false, + mnemonic: version === '2of3' ? actions.btc.getRandomMnemonicWords() : false, mnemonicWallet: false, isMnemonicCopied: false, isMnemonicGenerated: false, @@ -127,7 +121,12 @@ export default class RegisterSMSProtected extends React.Component { if (!phone) { this.setState({ - error: , + error: ( + + ), }) return } @@ -139,8 +138,8 @@ export default class RegisterSMSProtected extends React.Component { const result = await actions.btcmultisig.beginRegisterSMS( phone, - (mnemonic) ? mnemonic.trim() : false, - (useGeneratedKey && useGeneratedKeyEnabled) ? generatedKey : false + mnemonic ? mnemonic.trim() : false, + useGeneratedKey && useGeneratedKeyEnabled ? generatedKey : false ) if (result && result.answer && result.answer == 'ok') { @@ -149,11 +148,11 @@ export default class RegisterSMSProtected extends React.Component { step: 'enterCode', }) } else { - console.log("One step set", result) - const smsServerOffline = (result === false) + console.log('One step set', result) + const smsServerOffline = result === false this.setState({ isShipped: false, - error: (result && result.error) ? result.error : 'Unknown error', + error: result && result.error ? result.error : 'Unknown error', smsServerOffline, }) } @@ -171,7 +170,12 @@ export default class RegisterSMSProtected extends React.Component { if (!smsCode) { this.setState({ - error: , + error: ( + + ), }) return } @@ -186,8 +190,8 @@ export default class RegisterSMSProtected extends React.Component { const result = await actions.btcmultisig.confirmRegisterSMS( phone, smsCode, - (mnemonic) ? mnemonic.trim() : false, - (useGeneratedKey && useGeneratedKeyEnabled) ? generatedKey : false + mnemonic ? mnemonic.trim() : false, + useGeneratedKey && useGeneratedKeyEnabled ? generatedKey : false ) if (result && result.answer && result.answer == 'ok') { @@ -214,21 +218,19 @@ export default class RegisterSMSProtected extends React.Component { isWalletLockedOtherPhone: true, }) } else { - const smsServerOffline = (result === false) + const smsServerOffline = result === false this.setState({ isShipped: false, smsServerOffline, - error: (result && result.error) ? result.error : 'Unknown error', + error: result && result.error ? result.error : 'Unknown error', }) } } } - }; + } handleRestoreWallet = async () => { - const { - mnemonic, - } = this.state + const { mnemonic } = this.state if (!mnemonic || !actions.btc.validateMnemonicWords(mnemonic.trim())) { this.setState({ @@ -257,68 +259,84 @@ export default class RegisterSMSProtected extends React.Component { } handleCopyMnemonic = async () => { - this.setState({ - isMnemonicCopied: true, - }, () => { - setTimeout(() => { - this.setState({ - isMnemonicCopied: false, - }) - }, 1000) - }) + this.setState( + { + isMnemonicCopied: true, + }, + () => { + setTimeout(() => { + this.setState({ + isMnemonicCopied: false, + }) + }, 1000) + } + ) } handleCopyInstruction = async () => { - this.setState({ - isInstructionCopied: true, - }, () => { - setTimeout(() => { - this.setState({ - isInstructionCopied: false, - }) - }, 1000) - }) + this.setState( + { + isInstructionCopied: true, + }, + () => { + setTimeout(() => { + this.setState({ + isInstructionCopied: false, + }) + }, 1000) + } + ) } handleDownloadInstruction = async () => { - const { - restoreInstruction, - } = this.state - - this.setState({ - isInstructionDownloaded: true, - }, () => { - const element = document.createElement('a') - const message = 'Check your browser downloads' - - element.setAttribute('href', `data:text/plaincharset=utf-8,${encodeURIComponent(restoreInstruction)}`) - element.setAttribute('download', `${window.location.hostname}_btc_sms_protected_keys_${moment().format('DD.MM.YYYY')}.txt`) - - element.style.display = 'none' - document.body.appendChild(element) - element.click() - document.body.removeChild(element) + const { restoreInstruction } = this.state - setTimeout(() => { - this.setState({ - isInstructionDownloaded: false, - }) - }, 1000) - }) + this.setState( + { + isInstructionDownloaded: true, + }, + () => { + const element = document.createElement('a') + const message = 'Check your browser downloads' + + element.setAttribute( + 'href', + `data:text/plaincharset=utf-8,${encodeURIComponent(restoreInstruction)}` + ) + element.setAttribute( + 'download', + `${window.location.hostname}_btc_sms_protected_keys_${moment().format('DD.MM.YYYY')}.txt` + ) + + element.style.display = 'none' + document.body.appendChild(element) + element.click() + document.body.removeChild(element) + + setTimeout(() => { + this.setState({ + isInstructionDownloaded: false, + }) + }, 1000) + } + ) } handleGenerateMnemonic = async () => { - this.setState({ - isMnemonicGenerated: true, - isMnemonicValid: true, - mnemonic: actions.btc.getRandomMnemonicWords(), - }, () => { - setTimeout(() => { - this.setState({ - isMnemonicGenerated: false, - }) - }, 1000) - }) + this.setState( + { + isMnemonicGenerated: true, + isMnemonicValid: true, + mnemonic: actions.btc.getRandomMnemonicWords(), + }, + () => { + setTimeout(() => { + this.setState({ + isMnemonicGenerated: false, + }) + }, 1000) + } + ) } handleFinish = async () => { @@ -344,14 +362,14 @@ export default class RegisterSMSProtected extends React.Component { actions.modals.open(constants.modals.SaveMnemonicModal, { onClose: () => { const mnemonic = localStorage.getItem(constants.privateKeyNames.twentywords) - const mnemonicSaved = (mnemonic === `-`) - const step = (mnemonicSaved) ? 'enterPhoneAndMnemonic' : 'saveMnemonicWords' + const mnemonicSaved = mnemonic === `-` + const step = mnemonicSaved ? 'enterPhoneAndMnemonic' : 'saveMnemonicWords' this.setState({ mnemonicSaved, step, }) - } + }, }) } @@ -370,16 +388,9 @@ export default class RegisterSMSProtected extends React.Component { } generateRestoreInstruction = () => { - const { - mnemonic, - mnemonicWallet, - useGeneratedKey, - } = this.state + const { mnemonic, mnemonicWallet, useGeneratedKey } = this.state - const { - btcData, - btcMultisigSMSData, - } = this.props + const { btcData, btcMultisigSMSData } = this.props let restoreInstruction = '' @@ -388,13 +399,16 @@ export default class RegisterSMSProtected extends React.Component { restoreInstruction += `To withdraw funds create transaction using this code https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts#L193\r\n` restoreInstruction += `\r\n` restoreInstruction += `Public keys for create Multisig (2of3) wallet:\r\n` - if (btcMultisigSMSData.publicKeys[0]) restoreInstruction += `${btcMultisigSMSData.publicKeys[0].toString('Hex')}\r\n` - if (btcMultisigSMSData.publicKeys[1]) restoreInstruction += `${btcMultisigSMSData.publicKeys[1].toString('Hex')}\r\n` - if (btcMultisigSMSData.publicKeys[2]) restoreInstruction += `${btcMultisigSMSData.publicKeys[2].toString('Hex')}\r\n` + if (btcMultisigSMSData.publicKeys[0]) + restoreInstruction += `${btcMultisigSMSData.publicKeys[0].toString('Hex')}\r\n` + if (btcMultisigSMSData.publicKeys[1]) + restoreInstruction += `${btcMultisigSMSData.publicKeys[1].toString('Hex')}\r\n` + if (btcMultisigSMSData.publicKeys[2]) + restoreInstruction += `${btcMultisigSMSData.publicKeys[2].toString('Hex')}\r\n` restoreInstruction += `\r\n` - restoreInstruction+= `Hot wallet private key (WIF) (first of three for sign tx):\r\n` - restoreInstruction+= `Wallet delivery path from your secret phrase:\r\n` - restoreInstruction+= `m/44'/0'/0'/0/0\r\n` + restoreInstruction += `Hot wallet private key (WIF) (first of three for sign tx):\r\n` + restoreInstruction += `Wallet delivery path from your secret phrase:\r\n` + restoreInstruction += `m/44'/0'/0'/0/0\r\n` restoreInstruction += `${btcData.privateKey}\r\n` restoreInstruction += `*** (this private key stored in your browser)\r\n` restoreInstruction += `\r\n` @@ -407,10 +421,10 @@ export default class RegisterSMSProtected extends React.Component { restoreInstruction += `(DELETE THIS LINE!) ${mnemonicWallet.WIF}\r\n` restoreInstruction += `*** (this private key does not stored anywhere! but in case if our 2fa server does down, you can withdraw your fond using this private key)\r\n` } else { - restoreInstruction+= `Second of three for sign tx:\r\n` - restoreInstruction+= `Wallet delivery path from your secret phrase:\r\n` - restoreInstruction+= `m/44'/0'/0'/0/1\r\n` - restoreInstruction+= `\r\n` + restoreInstruction += `Second of three for sign tx:\r\n` + restoreInstruction += `Wallet delivery path from your secret phrase:\r\n` + restoreInstruction += `m/44'/0'/0'/0/1\r\n` + restoreInstruction += `\r\n` } restoreInstruction += `If our service is unavailable, use a local copy of the wallet.\r\n` restoreInstruction += `https://swaponline.github.io/2fa_wallet.zip\r\n` @@ -450,7 +464,7 @@ export default class RegisterSMSProtected extends React.Component { const langs = defineMessages({ registerSMSModal: { - id: "registerSMSProtectedTitle", + id: 'registerSMSProtectedTitle', defaultMessage: `Activate SMS Protected Wallet`, }, mnemonicPlaceholder: { @@ -471,7 +485,7 @@ export default class RegisterSMSProtected extends React.Component { }, pleaseSaveMnemonicToContinue: { id: 'registerSMS_SaveYourMnemonic', - defaultMessage: `Пожалуйста сохраните свою секретную фразу.` + defaultMessage: `Пожалуйста сохраните свою секретную фразу.`, }, buttonSaveMnemonic: { id: 'registerSMS_ButtonSaveMnemonic', @@ -481,18 +495,21 @@ export default class RegisterSMSProtected extends React.Component { id: 'registerSMS_ButtonCancel', defaultMessage: `Cancel`, }, - }); + }) - const sentBtnDisabled = isShipped || !phone || phone && !isValidPhoneNumber(phone) + const sentBtnDisabled = isShipped || !phone || (phone && !isValidPhoneNumber(phone)) return (
-