From 00f479900be66449b83a67d8ac8ffefa0fbe6d20 Mon Sep 17 00:00:00 2001 From: Philip London Date: Tue, 14 Jul 2020 15:26:49 +0200 Subject: [PATCH 1/5] feat(lift): remove a lot of dupe by typing lift --- .../Form/CoinBalanceDropdown/index.tsx | 2 +- .../src/data/components/borrow/sagas.ts | 5 +- .../src/data/components/borrow/selectors.ts | 5 +- .../src/data/components/borrow/types.ts | 12 --- .../src/data/components/interest/sagas.ts | 3 +- .../data/components/interest/sagas.utils.ts | 2 +- .../src/data/components/interest/selectors.ts | 6 +- .../src/data/components/simpleBuy/reducers.ts | 3 +- .../src/data/modules/profile/sagas.ts | 3 +- .../src/data/modules/profile/selectors.ts | 9 +- .../src/modals/Borrow/AddCollateral/index.tsx | 3 +- .../CollateralizationBar/index.tsx | 3 +- .../src/modals/Borrow/BorrowDetails/index.tsx | 21 +--- .../modals/Borrow/BorrowDetails/selectors.ts | 7 +- .../Borrow/BorrowForm/Summary/index.tsx | 4 +- .../src/modals/Borrow/BorrowForm/index.tsx | 3 +- .../src/modals/Borrow/ConfirmBorrow/index.tsx | 3 +- .../src/modals/Borrow/RepayLoanForm/index.tsx | 3 +- .../src/modals/Eth/TransferEth/index.tsx | 10 +- .../src/modals/Eth/TransferEth/selectors.ts | 4 +- .../modals/Interest/AccountSummary/index.tsx | 19 +--- .../Interest/AccountSummary/selectors.ts | 11 ++- .../src/modals/Interest/DepositForm/index.tsx | 4 +- .../Interest/DepositForm/template.success.tsx | 3 +- .../modals/Interest/WithdrawalForm/index.tsx | 5 +- .../src/modals/SimpleBuy/AddCard/index.tsx | 20 +--- .../src/modals/SimpleBuy/AddCard/selectors.ts | 14 ++- .../modals/SimpleBuy/BillingAddress/index.tsx | 6 +- .../SimpleBuy/BillingAddress/selectors.ts | 11 ++- .../CryptoSelector/CryptoItem/index.tsx | 98 +++++-------------- .../CryptoSelector/CryptoItem/selectors.ts | 14 +++ .../CryptoItem/template.success.tsx | 76 ++++++++++++++ .../CryptoSelection/CryptoSelector/index.tsx | 3 +- .../SimpleBuy/CryptoSelection/index.tsx | 24 +---- .../SimpleBuy/CryptoSelection/selectors.ts | 48 ++------- .../CryptoSelection/template.success.tsx | 4 +- .../CryptoSelection/template.unsupported.tsx | 4 +- .../Checkout/ActionButton/index.tsx | 6 +- .../SimpleBuy/EnterAmount/Checkout/index.tsx | 41 ++------ .../EnterAmount/Checkout/selectors.ts | 50 +++------- .../src/scenes/Borrow/BorrowHistory/index.tsx | 23 +---- .../scenes/Borrow/BorrowHistory/selectors.ts | 11 ++- .../Borrow/BorrowHistory/template.success.tsx | 7 +- .../Borrow/InitBorrowForm/Amount/index.tsx | 18 +--- .../Borrow/InitBorrowForm/Amount/selectors.ts | 8 +- .../src/scenes/Interest/SummaryCard/index.tsx | 20 +--- .../scenes/Interest/SummaryCard/selectors.ts | 11 ++- .../scenes/Interest/TransactionList/index.tsx | 22 +---- .../Interest/TransactionList/selectors.ts | 7 +- .../src/scenes/TheExchange/index.tsx | 2 +- .../Transactions/CoinIntroduction/index.tsx | 9 +- .../CoinIntroduction/selectors.ts | 1 - .../WalletBalanceDropdown/selectors.ts | 1 + .../src/exchange/index.ts | 3 +- .../src/redux/data/algo/types.ts | 3 +- .../src/redux/data/misc/selectors.ts | 3 +- .../src/redux/data/misc/types.ts | 13 +++ .../blockchain-wallet-v4/src/types/index.ts | 1 + typings/ramda.d.ts | 11 +++ 59 files changed, 312 insertions(+), 434 deletions(-) create mode 100644 packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/selectors.ts create mode 100644 packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/template.success.tsx create mode 100644 packages/blockchain-wallet-v4/src/redux/data/misc/types.ts create mode 100644 typings/ramda.d.ts diff --git a/packages/blockchain-wallet-v4-frontend/src/components/Form/CoinBalanceDropdown/index.tsx b/packages/blockchain-wallet-v4-frontend/src/components/Form/CoinBalanceDropdown/index.tsx index 629ae125a3c..eba594e9f1f 100644 --- a/packages/blockchain-wallet-v4-frontend/src/components/Form/CoinBalanceDropdown/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/components/Form/CoinBalanceDropdown/index.tsx @@ -1,6 +1,7 @@ import { AccountTypes, CoinType, + RatesType, RemoteDataType, SupportedCoinsType, SupportedCoinType @@ -9,7 +10,6 @@ import { connect, ConnectedProps } from 'react-redux' import { Field } from 'redux-form' import { getData } from './selectors' import { Icon, Text } from 'blockchain-info-components' -import { RatesType } from 'data/types' import { RootState } from 'data/rootReducer' import CoinDisplay from 'components/Display/CoinDisplay' import FiatDisplay from 'components/Display/FiatDisplay' diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/sagas.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/sagas.ts index 1a3323d82f9..46e59fb2297 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/sagas.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/sagas.ts @@ -3,7 +3,7 @@ import * as S from './selectors' import { actions, selectors } from 'data' import { all, call, put, select } from 'redux-saga/effects' import { APIType } from 'blockchain-wallet-v4/src/network/api' -import { BorrowFormValuesType, RatesType, RepayLoanFormType } from './types' +import { BorrowFormValuesType, RepayLoanFormType } from './types' import { convertBaseToStandard, convertStandardToBase @@ -22,7 +22,8 @@ import { LoanFinancialsType, LoanType, PaymentType, - PaymentValue + PaymentValue, + RatesType } from 'core/types' import BigNumber from 'bignumber.js' import EthUtil from 'ethereumjs-util' diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/selectors.ts index e6cf2465479..ba77d5918d7 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/selectors.ts @@ -1,5 +1,4 @@ -import { RatesType } from './types' -import { RemoteDataType } from 'core/types' +import { RatesType, RemoteDataType } from 'core/types' import { RootState } from '../../rootReducer' import { selectors } from 'data' @@ -23,7 +22,7 @@ export const getBorrowHistory = (state: RootState) => export const getRates = ( state: RootState -): RemoteDataType => { +): RemoteDataType => { const coinType = getCoinType(state) return selectors.core.data.misc.getRatesSelector(coinType, state) diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/types.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/types.ts index b5270ea2a0a..1caa14dc927 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/types.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/borrow/types.ts @@ -2,7 +2,6 @@ import * as AT from './actionTypes' import { AccountTypes, CoinType, - FiatType, LoanTransactionsType, LoanType, NabuApiErrorType, @@ -35,17 +34,6 @@ export enum BorrowSteps { 'REPAY_LOAN' } -// TODO: move to ticker -export type RatesType = { - [key in FiatType]: { - '15m': number - buy: number - last: number - sell: number - symbol: '$' - } -} - export type RepayLoanFormType = { amount?: string 'repay-method': 'principal' | 'collateral' diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/interest/sagas.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/interest/sagas.ts index 6ad8e0d36a4..6149201d37e 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/interest/sagas.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/interest/sagas.ts @@ -7,7 +7,7 @@ import { actions, model, selectors } from 'data' import { APIType } from 'core/network/api' import { convertStandardToBase } from '../exchange/services' import { errorHandler } from 'blockchain-wallet-v4/src/utils' -import { PaymentType, PaymentValue } from 'core/types' +import { PaymentType, PaymentValue, RatesType } from 'core/types' import { Remote } from 'blockchain-wallet-v4/src' import * as A from './actions' @@ -15,7 +15,6 @@ import * as AT from './actionTypes' import * as S from './selectors' import { DEFAULT_INTEREST_BALANCES } from './model' import { InterestDepositFormType } from './types' -import { RatesType } from '../borrow/types' import exchangeSagaUtils from '../exchange/sagas.utils' import profileSagas from '../../modules/profile/sagas' import utils from './sagas.utils' diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/interest/sagas.utils.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/interest/sagas.utils.ts index 9e419137a90..b10346fbd80 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/interest/sagas.utils.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/interest/sagas.utils.ts @@ -7,13 +7,13 @@ import { FiatType, PaymentType, PaymentValue, + RatesType, RemoteDataType } from 'core/types' import { convertBaseToStandard } from '../exchange/services' import { Exchange } from 'blockchain-wallet-v4/src' import { INVALID_COIN_TYPE } from 'blockchain-wallet-v4/src/model' import { promptForSecondPassword } from 'services/SagaService' -import { RatesType } from '../borrow/types' import { selectors } from 'data' export default ({ coreSagas, networks }: { coreSagas: any; networks: any }) => { diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/interest/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/interest/selectors.ts index ee750087f83..a378da592f0 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/interest/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/interest/selectors.ts @@ -1,9 +1,7 @@ -import { FiatType, RemoteDataType } from 'core/types' +import { FiatType, RatesType, RemoteDataType } from 'core/types' import { RootState } from 'data/rootReducer' import { selectors } from 'data' -import { RatesType } from '../borrow/types' - export const getInterestAccountBalance = (state: RootState) => state.components.interest.accountBalance @@ -43,7 +41,7 @@ export const getPayment = (state: RootState) => export const getRates = ( state: RootState -): RemoteDataType => { +): RemoteDataType => { const coinType = getCoinType(state) return selectors.core.data.misc.getRatesSelector(coinType, state) diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/reducers.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/reducers.ts index e1de462b048..d0692cacb5e 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/reducers.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/simpleBuy/reducers.ts @@ -105,10 +105,11 @@ export function simpleBuyReducer ( ...state, card: Remote.Success(action.payload.card) } + // cards fetch fails so often in staging that this is a temp fix case AT.FETCH_SB_CARDS_FAILURE: { return { ...state, - cards: Remote.Failure(action.payload.error) + cards: Remote.Success([]) } } case AT.FETCH_SB_CARDS_LOADING: diff --git a/packages/blockchain-wallet-v4-frontend/src/data/modules/profile/sagas.ts b/packages/blockchain-wallet-v4-frontend/src/data/modules/profile/sagas.ts index c065711b005..bd2c485c608 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/modules/profile/sagas.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/modules/profile/sagas.ts @@ -14,6 +14,7 @@ import { take } from 'redux-saga/effects' import { compose, equals, lift, prop, sortBy, tail } from 'ramda' +import { ExtractSuccess } from 'core/types' import { KYC_STATES, USER_ACTIVATION_STATES } from './model' import { promptForSecondPassword } from 'services/SagaService' import { Remote } from 'blockchain-wallet-v4/src' @@ -264,7 +265,7 @@ export default ({ api, coreSagas, networks }) => { if (!userId || !lifetimeToken) return call(generateAuthCredentials) return authCredentials }) - .getOrElse({}) + .getOrElse({} as ExtractSuccess) yield call(setSession, userId, lifetimeToken, email, guid) } diff --git a/packages/blockchain-wallet-v4-frontend/src/data/modules/profile/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/data/modules/profile/selectors.ts index e134065e8bd..a4efa97a592 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/modules/profile/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/modules/profile/selectors.ts @@ -23,6 +23,7 @@ import { KYC_STATES, TIERS_STATES, USER_ACTIVATION_STATES } from './model' import { RemoteDataType } from 'core/types' import { RootState } from 'data/rootReducer' import { selectors } from 'data' +import { UserDataType } from './types' export const getUserData = (state: RootState) => state.profile.userData export const getUserCampaigns = (state: RootState) => @@ -34,7 +35,9 @@ export const getWalletAddresses = compose( getUserData ) export const getUserActivationState = compose(lift(prop('state')), getUserData) -export const getUserKYCState = compose(lift(prop('kycState')), getUserData) +export const getUserKYCState = compose(lift(prop('kycState')), getUserData) as ( + state: RootState +) => RemoteDataType export const getTags = compose(lift(path(['tags'])), getUserData) export const getSunRiverTag = compose( lift(path(['tags', 'SUNRIVER'])), @@ -177,8 +180,8 @@ export const isExchangeAccountLinked = ( // suggest to the linking saga that a relink should be attempted export const isExchangeRelinkRequired = ( state -): RemoteDataType => - lift(user => { +): RemoteDataType => + lift((user: UserDataType) => { return ( not(isNil(prop('settings', user))) && length(getRemainingCoins(state)) ) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/AddCollateral/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/AddCollateral/index.tsx index 2fbf411a0d5..02fb8e62970 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/AddCollateral/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/AddCollateral/index.tsx @@ -1,11 +1,12 @@ import { actions } from 'data' import { bindActionCreators, compose, Dispatch } from 'redux' -import { BorrowMinMaxType, RatesType } from 'data/types' +import { BorrowMinMaxType } from 'data/types' import { CoinType, LoanType, OfferType, PaymentValue, + RatesType, RemoteDataType, SupportedCoinsType } from 'core/types' diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/CollateralizationBar/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/CollateralizationBar/index.tsx index 9317d2a4933..84e77e0a94c 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/CollateralizationBar/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/CollateralizationBar/index.tsx @@ -1,6 +1,5 @@ -import { LoanType, OfferType, SupportedCoinsType } from 'core/types' +import { LoanType, OfferType, RatesType, SupportedCoinsType } from 'core/types' import { model } from 'data' -import { RatesType } from 'data/types' import { Text } from 'blockchain-info-components' import React from 'react' import styled from 'styled-components' diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/index.tsx index c426b22890c..bbe915c1a4b 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/index.tsx @@ -2,14 +2,7 @@ import { actions } from 'data' import { bindActionCreators, Dispatch } from 'redux' import { connect, ConnectedProps } from 'react-redux' import { getData } from './selectors' -import { - LoanTransactionsType, - LoanType, - OfferType, - RemoteDataType, - SupportedCoinsType -} from 'core/types' -import { RatesType } from 'data/types' +import { LoanType, OfferType } from 'core/types' import { RootState } from 'data/rootReducer' import Loading from './template.loading' import React, { PureComponent } from 'react' @@ -33,7 +26,7 @@ class BorrowDetails extends PureComponent { } } -const mapStateToProps = (state: RootState): LinkStatePropsType => ({ +const mapStateToProps = (state: RootState) => ({ data: getData(state) }) @@ -48,14 +41,8 @@ type OwnProps = { loan: LoanType offer: OfferType } -export type SuccessStateType = { - loanTransactions: Array - rates: RatesType - supportedCoins: SupportedCoinsType -} -type LinkStatePropsType = { - data: RemoteDataType -} +export type SuccessStateType = ReturnType['data'] + export type Props = OwnProps & ConnectedProps export default connector(BorrowDetails) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/selectors.ts index ccfc04751b4..f2ff230b170 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/selectors.ts @@ -1,3 +1,4 @@ +import { ExtractSuccess, SupportedCoinsType } from 'core/types' import { lift } from 'ramda' import { RootState } from 'data/rootReducer' import { selectors } from 'data' @@ -9,7 +10,11 @@ export const getData = (state: RootState) => { const ratesR = selectors.components.borrow.getRates(state) const supportedCoinsR = selectors.core.walletOptions.getSupportedCoins(state) - const transform = (loanTransactions, rates, supportedCoins) => ({ + const transform = ( + loanTransactions: ExtractSuccess, + rates: ExtractSuccess, + supportedCoins: SupportedCoinsType + ) => ({ loanTransactions, rates, supportedCoins diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowForm/Summary/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowForm/Summary/index.tsx index e38ea0a613b..d5da384892b 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowForm/Summary/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowForm/Summary/index.tsx @@ -1,11 +1,11 @@ -import { BorrowFormValuesType, RatesType } from 'data/types' +import { BorrowFormValuesType } from 'data/types' import { coinToString, fiatToString, formatFiat } from 'blockchain-wallet-v4/src/exchange/currency' import { FormattedMessage } from 'react-intl' -import { OfferType } from 'core/types' +import { OfferType, RatesType } from 'core/types' import { TableRow, Title, Value } from 'components/Borrow' import { Text, TooltipHost, TooltipIcon } from 'blockchain-info-components' import React from 'react' diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowForm/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowForm/index.tsx index 5037639256d..504b4155844 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowForm/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowForm/index.tsx @@ -1,10 +1,11 @@ import { actions } from 'data' import { bindActionCreators, compose, Dispatch } from 'redux' -import { BorrowMinMaxType, RatesType } from 'data/types' +import { BorrowMinMaxType } from 'data/types' import { CoinType, OfferType, PaymentValue, + RatesType, RemoteDataType, SupportedCoinsType } from 'core/types' diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/ConfirmBorrow/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/ConfirmBorrow/index.tsx index 12328668b5b..2f2056420df 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/ConfirmBorrow/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/ConfirmBorrow/index.tsx @@ -2,8 +2,7 @@ import { actions } from 'data' import { bindActionCreators, compose, Dispatch } from 'redux' import { connect } from 'react-redux' import { getData } from './selectors' -import { OfferType, PaymentValue, RemoteDataType } from 'core/types' -import { RatesType } from 'data/types' +import { OfferType, PaymentValue, RatesType, RemoteDataType } from 'core/types' import { RootState } from 'data/rootReducer' import DataError from 'components/DataError' import Loading from './template.loading' diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/RepayLoanForm/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/RepayLoanForm/index.tsx index 379f73c90b9..3925aba027c 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/RepayLoanForm/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Borrow/RepayLoanForm/index.tsx @@ -1,6 +1,6 @@ import { actions } from 'data' import { bindActionCreators, Dispatch } from 'redux' -import { BorrowMinMaxType, RatesType } from 'data/types' +import { BorrowMinMaxType } from 'data/types' import { connect, ConnectedProps } from 'react-redux' import { getData } from './selectors' import { @@ -8,6 +8,7 @@ import { LoanType, OfferType, PaymentValue, + RatesType, RemoteDataType, SupportedCoinsType } from 'core/types' diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Eth/TransferEth/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Eth/TransferEth/index.tsx index 60d724d1c0b..5804e69f4c4 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Eth/TransferEth/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Eth/TransferEth/index.tsx @@ -7,6 +7,12 @@ import modalEnhancer from 'providers/ModalEnhancer' import React from 'react' import TransferEth from './template' +const DEFAULTS = { + txFee: '0', + ethBalance: '0', + ethAddr: '' +} + class TransferEthContainer extends React.PureComponent { componentDidMount () { this.props.transferEthActions.initialized({ @@ -17,7 +23,7 @@ class TransferEthContainer extends React.PureComponent { componentDidUpdate () { if (Remote.Success.is(this.props.data)) { - const { txFee, ethBalance } = this.props.data.getOrElse({}) + const { txFee, ethBalance } = this.props.data.getOrElse(DEFAULTS) if (parseFloat(txFee) > parseFloat(ethBalance)) { this.props.modalActions.closeAllModals() } @@ -25,7 +31,7 @@ class TransferEthContainer extends React.PureComponent { } handleSubmit = () => { - const { ethAddr, ethBalance } = this.props.data.getOrElse({}) + const { ethAddr, ethBalance } = this.props.data.getOrElse(DEFAULTS) this.props.transferEthActions.confirmTransferEth({ to: ethAddr, effectiveBalance: ethBalance diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Eth/TransferEth/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/Eth/TransferEth/selectors.ts index 479ee9f2f28..e1f30c5b823 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Eth/TransferEth/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Eth/TransferEth/selectors.ts @@ -12,8 +12,8 @@ export const getData = state => { const transform = (ethAddr, payment) => ({ ethAddr, - ethBalance: propOr('0', 'effectiveBalance', payment), - txFee: propOr('0', 'fee', payment) + ethBalance: propOr('0', 'effectiveBalance', payment) as string, + txFee: propOr('0', 'fee', payment) as string }) return lift(transform)(defaultAccountR, paymentR) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/AccountSummary/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/AccountSummary/index.tsx index 7822d7c73ab..13fd14be435 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/AccountSummary/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/AccountSummary/index.tsx @@ -4,15 +4,7 @@ import { includes } from 'ramda' import React, { PureComponent } from 'react' import { actions } from 'data' -import { - CoinType, - FiatType, - InterestAccountBalanceType, - InterestLimitsType, - InterestRateType, - RemoteDataType, - SupportedCoinsType -} from 'core/types' +import { CoinType, FiatType, RemoteDataType } from 'core/types' import { InterestStepMetadata } from 'data/types' import DataError from 'components/DataError' @@ -91,14 +83,7 @@ export type LinkDispatchPropsType = { simpleBuyActions: typeof actions.components.simpleBuy } -export type SuccessStateType = { - accountBalances: InterestAccountBalanceType - availToWithdraw: number - interestLimits: InterestLimitsType - interestRate: InterestRateType - supportedCoins: SupportedCoinsType - walletCurrency: FiatType -} +export type SuccessStateType = ReturnType['data'] type LinkStatePropsType = { data: RemoteDataType diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/AccountSummary/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/AccountSummary/selectors.ts index 8bafba559ff..5554c51ef3b 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/AccountSummary/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/AccountSummary/selectors.ts @@ -1,5 +1,6 @@ import { lift } from 'ramda' +import { ExtractSuccess, FiatType, SupportedCoinsType } from 'core/types' import { selectors } from 'data' export const getData = state => { @@ -13,11 +14,11 @@ export const getData = state => { return lift( ( - accountBalances, - interestLimits, - interestRate, - supportedCoins, - walletCurrency + accountBalances: ExtractSuccess, + interestLimits: ExtractSuccess, + interestRate: ExtractSuccess, + supportedCoins: SupportedCoinsType, + walletCurrency: FiatType ) => ({ accountBalances, interestLimits, diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/DepositForm/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/DepositForm/index.tsx index d20133ef0aa..c02739abf59 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/DepositForm/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/DepositForm/index.tsx @@ -8,10 +8,11 @@ import { FiatType, InterestLimitsType, InterestRateType, + RatesType, RemoteDataType, SupportedCoinsType } from 'core/types' -import { InterestMinMaxType, RatesType } from 'data/types' +import { InterestMinMaxType } from 'data/types' import DataError from 'components/DataError' import { getData } from './selectors' @@ -91,7 +92,6 @@ export type LinkDispatchPropsType = { interestActions: typeof actions.components.interest } export type SuccessStateType = { - coin: CoinType depositLimits: InterestMinMaxType displayCoin: boolean formErrors: { depositAmount?: 'ABOVE_MAX' | 'BELOW_MIN' | boolean } diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/DepositForm/template.success.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/DepositForm/template.success.tsx index e23077ae9bf..d267e777b24 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/DepositForm/template.success.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/DepositForm/template.success.tsx @@ -58,7 +58,7 @@ import { maxFiat } from '../conversions' import { maxDepositAmount, minDepositAmount } from './validation' -import { SuccessStateType } from '.' +import { OwnProps as ParentOwnProps, SuccessStateType } from '.' import TabMenuTimeFrame from './TabMenuTimeFrame' const FORM_NAME = 'interestDepositForm' @@ -574,6 +574,7 @@ type LinkStatePropsType = { export type Props = SuccessStateType & ConnectedProps & + ParentOwnProps & FormProps type FormProps = { diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/WithdrawalForm/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/WithdrawalForm/index.tsx index efe59dd2dbf..e20256c1e21 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/Interest/WithdrawalForm/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/Interest/WithdrawalForm/index.tsx @@ -8,14 +8,15 @@ import { FiatType, InterestAccountBalanceType, InterestLimitsType, + RatesType, RemoteDataType, SupportedCoinsType, WithdrawalMinimumType } from 'core/types' -import { RatesType } from 'data/types' import DataError from 'components/DataError' import { getData } from './selectors' +import BigNumber from 'bignumber.js' import Loading from './template.loading' import WithdrawalForm from './template.success' @@ -74,7 +75,7 @@ const connector = connect(mapStateToProps, mapDispatchToProps) export type SuccessStateType = { accountBalances: InterestAccountBalanceType - availToWithdraw: number + availToWithdraw: BigNumber coin: CoinType displayCoin: boolean interestLimits: InterestLimitsType diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/AddCard/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/AddCard/index.tsx index e1839192020..5a4345647bc 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/AddCard/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/AddCard/index.tsx @@ -1,17 +1,9 @@ import { actions, selectors } from 'data' import { bindActionCreators, Dispatch } from 'redux' import { connect, ConnectedProps } from 'react-redux' -import { - FiatType, - RemoteDataType, - SBBuyOrderType, - SBPaymentMethodsType, - SBSellOrderType -} from 'core/types' import { getData } from './selectors' import { Remote } from 'core' import { RootState } from 'data/rootReducer' -import { SBAddCardFormValuesType } from 'data/types' import DataError from 'components/DataError' import Loading from './template.loading' import React, { PureComponent } from 'react' @@ -45,7 +37,7 @@ class AddCard extends PureComponent { } } -const mapStateToProps = (state: RootState): LinkStatePropsType => ({ +const mapStateToProps = (state: RootState) => ({ data: getData(state), fiatCurrency: selectors.components.simpleBuy.getFiatCurrency(state) || 'EUR' }) @@ -62,15 +54,7 @@ type OwnProps = { type LinkDispatchPropsType = { simpleBuyActions: typeof actions.components.simpleBuy } -type LinkStatePropsType = { - data: RemoteDataType - fiatCurrency: FiatType -} -export type SuccessStateType = { - formValues?: SBAddCardFormValuesType - order: SBBuyOrderType | SBSellOrderType | undefined - paymentMethods: SBPaymentMethodsType -} +export type SuccessStateType = ReturnType['data'] export type Props = OwnProps & ConnectedProps export default connect(mapStateToProps, mapDispatchToProps)(AddCard) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/AddCard/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/AddCard/selectors.ts index d57290b8c17..d079d508cfb 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/AddCard/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/AddCard/selectors.ts @@ -1,15 +1,21 @@ +import { ExtractSuccess } from 'core/types' import { lift } from 'ramda' import { RootState } from 'data/rootReducer' +import { SBAddCardFormValuesType } from 'data/types' import { selectors } from 'data' export const getData = (state: RootState) => { - const formValues = selectors.form.getFormValues('addCCForm')(state) + const formValues = selectors.form.getFormValues('addCCForm')( + state + ) as SBAddCardFormValuesType const order = selectors.components.simpleBuy.getSBOrder(state) const paymentMethodsR = selectors.components.simpleBuy.getSBPaymentMethods( state ) - return lift(paymentMethods => ({ formValues, order, paymentMethods }))( - paymentMethodsR - ) + return lift((paymentMethods: ExtractSuccess) => ({ + formValues, + order, + paymentMethods + }))(paymentMethodsR) } diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/BillingAddress/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/BillingAddress/index.tsx index 13f81bcd0cb..17272c104d0 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/BillingAddress/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/BillingAddress/index.tsx @@ -4,7 +4,6 @@ import { connect, ConnectedProps } from 'react-redux' import { getData } from './selectors' import { RemoteDataType } from 'core/types' import { RootState } from 'data/rootReducer' -import { SBBillingAddressFormValuesType, UserDataType } from 'data/types' import DataError from 'components/DataError' import Loading from './template.loading' import React, { PureComponent } from 'react' @@ -50,10 +49,7 @@ const connector = connect(mapStateToProps, mapDispatchToProps) type OwnProps = { handleClose: () => void } -export type SuccessStateType = { - formValues: SBBillingAddressFormValuesType - userData: UserDataType -} +export type SuccessStateType = ReturnType['data'] type LinkStatePropsType = { data: RemoteDataType } diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/BillingAddress/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/BillingAddress/selectors.ts index de84b063ba9..8211472ae67 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/BillingAddress/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/BillingAddress/selectors.ts @@ -1,10 +1,17 @@ +import { ExtractSuccess } from 'core/types' import { lift } from 'ramda' import { RootState } from 'data/rootReducer' +import { SBBillingAddressFormValuesType } from 'data/types' import { selectors } from 'data' export const getData = (state: RootState) => { - const formValues = selectors.form.getFormValues('ccBillingAddress')(state) + const formValues = selectors.form.getFormValues('ccBillingAddress')( + state + ) as SBBillingAddressFormValuesType const userDataR = selectors.modules.profile.getUserData(state) - return lift(userData => ({ formValues, userData }))(userDataR) + return lift((userData: ExtractSuccess) => ({ + formValues, + userData + }))(userDataR) } diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/index.tsx index e1174c449dc..e1a7f848da3 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/index.tsx @@ -1,81 +1,35 @@ -import { Icon } from 'blockchain-info-components' -import React from 'react' -import styled from 'styled-components' +import { connect, ConnectedProps } from 'react-redux' +import { getData } from './selectors' +import { RootState } from 'data/rootReducer' +import { SBPairType, SupportedCoinsType } from 'core/types' +import React, { PureComponent } from 'react' +import Success from './template.success' -import { - CoinType, - SBPairType, - SupportedCoinsType, - SupportedCoinType -} from 'core/types' -import { fiatToString } from 'core/exchange/currency' -import { - getCoinFromPair, - getFiatFromPair -} from 'data/components/simpleBuy/model' -import { RatesType } from 'data/types' -import { Title, Value } from 'components/Flyout' +class CryptoItem extends PureComponent { + state = {} -const DisplayContainer = styled.div<{ - coinType: SupportedCoinType -}>` - display: flex; - width: 100%; - align-items: center; - box-sizing: border-box; - padding: 16px 40px; - border-bottom: 1px solid ${props => props.theme.grey000}; - &hover { - background-color: ${props => props.theme.grey100}; + render () { + return this.props.data.cata({ + Success: val => , + Failure: () => null, + Loading: () => null, + NotAsked: () => null + }) } -` -const Display = styled.div` - position: relative; - display: flex; - flex-direction: column; - margin-left: 12px; - width: 100%; - cursor: pointer; - font-size: 16px; - font-weight: 500; - color: ${props => props.theme.grey800}; -` +} + +const mapStateToProps = (state: RootState, ownProps: OwnProps) => ({ + data: getData(state, ownProps) +}) + +const connector = connect(mapStateToProps) -export type Props = { +export type OwnProps = { onClick: (string) => void - rates: { [key in CoinType]: RatesType } supportedCoins: SupportedCoinsType value: SBPairType } +export type SuccessStateType = ReturnType['data'] +export type Props = OwnProps & ConnectedProps -const CryptoItem: React.FC = props => { - const coin = getCoinFromPair(props.value.pair) - const fiat = getFiatFromPair(props.value.pair) - const coinType = props.supportedCoins[coin] - const displayName = coinType.displayName - const icon = coinType.icons.circleFilled - const color = coinType.colorCode - - return ( - - - - {displayName} - - {fiatToString({ - value: props.rates[coin][fiat].last, - unit: fiat - })} - - - - - ) -} - -export default CryptoItem +export default connector(CryptoItem) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/selectors.ts new file mode 100644 index 00000000000..337d4e5d868 --- /dev/null +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/selectors.ts @@ -0,0 +1,14 @@ +import { ExtractSuccess } from 'core/types' +import { getCoinFromPair } from 'data/components/simpleBuy/model' +import { getRatesSelector } from 'core/redux/data/misc/selectors' +import { lift } from 'ramda' +import { RootState } from 'data/rootReducer' + +import { OwnProps } from '.' + +export const getData = (state: RootState, ownProps: OwnProps) => { + const coin = getCoinFromPair(ownProps.value.pair) + const ratesR = getRatesSelector(coin, state) + + return lift((rates: ExtractSuccess) => ({ rates }))(ratesR) +} diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/template.success.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/template.success.tsx new file mode 100644 index 00000000000..4059a33d142 --- /dev/null +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/template.success.tsx @@ -0,0 +1,76 @@ +import { Icon } from 'blockchain-info-components' +import React from 'react' +import styled from 'styled-components' + +import { fiatToString } from 'core/exchange/currency' +import { + getCoinFromPair, + getFiatFromPair +} from 'data/components/simpleBuy/model' +import { SupportedCoinType } from 'core/types' +import { Title, Value } from 'components/Flyout' + +import { + Props as OwnProps, + OwnProps as ParentOwnProps, + SuccessStateType +} from '.' + +const DisplayContainer = styled.div<{ + coinType: SupportedCoinType +}>` + display: flex; + width: 100%; + align-items: center; + box-sizing: border-box; + padding: 16px 40px; + border-bottom: 1px solid ${props => props.theme.grey000}; + &hover { + background-color: ${props => props.theme.grey100}; + } +` +const Display = styled.div` + position: relative; + display: flex; + flex-direction: column; + margin-left: 12px; + width: 100%; + cursor: pointer; + font-size: 16px; + font-weight: 500; + color: ${props => props.theme.grey800}; +` + +type Props = OwnProps & ParentOwnProps & SuccessStateType + +const Success: React.FC = props => { + const coin = getCoinFromPair(props.value.pair) + const fiat = getFiatFromPair(props.value.pair) + const coinType = props.supportedCoins[coin] + const displayName = coinType.displayName + const icon = coinType.icons.circleFilled + const color = coinType.colorCode + + return ( + + + + {displayName} + + {fiatToString({ + value: props.rates[fiat].last, + unit: fiat + })} + + + + + ) +} + +export default Success diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/index.tsx index 9093be76afc..119cc0a8057 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/index.tsx @@ -71,9 +71,8 @@ const CryptoSelector: React.FC & {props.pairs.map((value, index) => ( handleSubmit(value as SBPairType)} /> ))} diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/index.tsx index ffe4e9959c4..742e4d56a20 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/index.tsx @@ -1,17 +1,7 @@ import { actions, selectors } from 'data' import { bindActionCreators, Dispatch } from 'redux' -import { - CoinType, - FiatEligibleType, - FiatType, - RemoteDataType, - SBCardType, - SBPairType, - SupportedCoinsType -} from 'core/types' import { connect, ConnectedProps } from 'react-redux' import { getData } from './selectors' -import { RatesType } from 'data/types' import { RootState } from 'data/rootReducer' import Failure from './template.failure' import Loading from './template.loading' @@ -36,7 +26,7 @@ class CryptoSelection extends PureComponent { } } -const mapStateToProps = (state: RootState): LinkStatePropsType => ({ +const mapStateToProps = (state: RootState) => ({ data: getData(state), fiatCurrency: selectors.components.simpleBuy.getFiatCurrency(state) || 'USD' }) @@ -52,17 +42,7 @@ const connector = connect(mapStateToProps, mapDispatchToProps) export type OwnProps = { handleClose: () => void } -export type SuccessStateType = { - cards: Array - eligibility: FiatEligibleType - pairs: Array - rates: { [key in CoinType]: RatesType } - supportedCoins: SupportedCoinsType -} -export type LinkStatePropsType = { - data: RemoteDataType - fiatCurrency: FiatType -} +export type SuccessStateType = ReturnType['data'] export type LinkDispatchPropsType = ReturnType export type Props = OwnProps & ConnectedProps diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/selectors.ts index dc511f76c1b..0a593f9d95c 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/selectors.ts @@ -1,3 +1,4 @@ +import { ExtractSuccess, SupportedCoinsType } from 'core/types' import { lift } from 'ramda' import { selectors } from 'data' @@ -6,46 +7,15 @@ export const getData = state => { const pairsR = selectors.components.simpleBuy.getSBPairs(state) const supportedCoinsR = selectors.core.walletOptions.getSupportedCoins(state) - const bchRatesR = selectors.core.data.bch.getRates(state) - const btcRatesR = selectors.core.data.btc.getRates(state) - const ethRatesR = selectors.core.data.eth.getRates(state) - const paxRatesR = selectors.core.data.eth.getErc20Rates(state, 'pax') - const usdtRatesR = selectors.core.data.eth.getErc20Rates(state, 'usdt') - const xlmRatesR = selectors.core.data.xlm.getRates(state) - const algoRatesR = selectors.core.data.algo.getRates(state) - - const ratesR = lift( + return lift( ( - bchRates, - btcRates, - ethRates, - paxRates, - xlmRates, - usdtRates, - algoRates + eligibility: ExtractSuccess, + pairs: ExtractSuccess, + supportedCoins: SupportedCoinsType ) => ({ - BCH: bchRates, - BTC: btcRates, - ETH: ethRates, - PAX: paxRates, - XLM: xlmRates, - USDT: usdtRates, - ALGO: algoRates + eligibility, + pairs, + supportedCoins }) - )( - bchRatesR, - btcRatesR, - ethRatesR, - paxRatesR, - xlmRatesR, - usdtRatesR, - algoRatesR - ) - - return lift((eligibility, pairs, supportedCoins, rates) => ({ - eligibility, - pairs, - supportedCoins, - rates - }))(eligibilityR, pairsR, supportedCoinsR, ratesR) + )(eligibilityR, pairsR, supportedCoinsR) } diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/template.success.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/template.success.tsx index 12e831dbc6c..ab84758f655 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/template.success.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/template.success.tsx @@ -1,6 +1,6 @@ import React, { useEffect } from 'react' -import { LinkStatePropsType, Props as OwnProps, SuccessStateType } from '.' +import { Props as OwnProps, SuccessStateType } from '.' import CryptoSelector from './CryptoSelector' import Unsupported from './template.unsupported' @@ -26,6 +26,6 @@ const Success: React.FC = props => { ) } -export type Props = OwnProps & SuccessStateType & LinkStatePropsType +export type Props = OwnProps & SuccessStateType export default Success diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/template.unsupported.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/template.unsupported.tsx index 0518bbc1033..7161770f047 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/template.unsupported.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/template.unsupported.tsx @@ -1,11 +1,11 @@ import { Button, Icon, Image, Text } from 'blockchain-info-components' import { FlyoutWrapper } from 'components/Flyout' import { FormattedMessage } from 'react-intl' -import { LinkStatePropsType, Props as OwnProps, SuccessStateType } from '.' +import { Props as OwnProps, SuccessStateType } from '.' import React from 'react' import styled from 'styled-components' -export type Props = OwnProps & SuccessStateType & LinkStatePropsType +export type Props = OwnProps & SuccessStateType const Top = styled(FlyoutWrapper)` padding-bottom: 0px; diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/ActionButton/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/ActionButton/index.tsx index 6f51101a93d..46cad17d431 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/ActionButton/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/ActionButton/index.tsx @@ -1,13 +1,13 @@ import { Button, HeartbeatLoader, Link, Text } from 'blockchain-info-components' import { FormattedMessage } from 'react-intl' -import { LinkDispatchPropsType, SuccessStateType } from '..' +import { Props as OwnProps, SuccessStateType } from '..' import React from 'react' type Props = { invalid: boolean submitting: boolean -} & SuccessStateType & - LinkDispatchPropsType +} & OwnProps & + SuccessStateType const ActionButton: React.FC = props => { switch (props.userData.kycState) { diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/index.tsx index 6b4320645d4..9eb9eeb794d 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/index.tsx @@ -1,22 +1,14 @@ import { actions, selectors } from 'data' import { bindActionCreators } from 'redux' -import { - CoinType, - FiatType, - InvitationsType, - RemoteDataType, - SBPaymentMethodType, - SBSuggestedAmountType, - SupportedCoinsType -} from 'core/types' -import { connect } from 'react-redux' +import { connect, ConnectedProps } from 'react-redux' import { OwnProps as EnterAmountOwnProps, SuccessStateType as EnterAmountSuccessStateType } from '../index' import { getData } from './selectors' -import { RatesType, SBCheckoutFormValuesType, UserDataType } from 'data/types' import { RootState } from 'data/rootReducer' +import { SBCheckoutFormValuesType, UserDataType } from 'data/types' +import { SBPaymentMethodType } from 'core/types' import Failure from '../template.failure' import Loading from './template.loading' import React, { PureComponent } from 'react' @@ -90,7 +82,7 @@ class Checkout extends PureComponent { } } -const mapStateToProps = (state: RootState): LinkStatePropsType => ({ +const mapStateToProps = (state: RootState) => ({ data: getData(state), fiatCurrency: selectors.components.simpleBuy.getFiatCurrency(state) }) @@ -106,29 +98,12 @@ const mapDispatchToProps = dispatch => ({ simpleBuyActions: bindActionCreators(actions.components.simpleBuy, dispatch) }) -const enhance = connect(mapStateToProps, mapDispatchToProps) +const connector = connect(mapStateToProps, mapDispatchToProps) type OwnProps = EnterAmountOwnProps & EnterAmountSuccessStateType -export type SuccessStateType = { +export type SuccessStateType = ReturnType['data'] & { formErrors: { amount?: 'ABOVE_MAX' | 'BELOW_MIN' | boolean } - formValues?: SBCheckoutFormValuesType - invitations: InvitationsType - rates: { [key in CoinType]: RatesType } - suggestedAmounts: SBSuggestedAmountType - supportedCoins: SupportedCoinsType - userData: UserDataType -} -type LinkStatePropsType = { - data: RemoteDataType - fiatCurrency: undefined | FiatType -} -export type LinkDispatchPropsType = { - analyticsActions: typeof actions.analytics - formActions: typeof actions.form - identityVerificationActions: typeof actions.components.identityVerification - profileActions: typeof actions.modules.profile - simpleBuyActions: typeof actions.components.simpleBuy } -export type Props = OwnProps & LinkDispatchPropsType & LinkStatePropsType +export type Props = OwnProps & ConnectedProps -export default enhance(Checkout) +export default connector(Checkout) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/selectors.ts index 246651e74ba..a073b8e95df 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/selectors.ts @@ -1,12 +1,16 @@ +import { ExtractSuccess, SupportedCoinsType } from 'core/types' import { lift } from 'ramda' import { RootState } from 'data/rootReducer' +import { SBCheckoutFormValuesType } from 'data/types' import { selectors } from 'data' export const getData = (state: RootState) => { const formErrors = selectors.form.getFormSyncErrors('simpleBuyCheckout')( state ) - const formValues = selectors.form.getFormValues('simpleBuyCheckout')(state) + const formValues = selectors.form.getFormValues('simpleBuyCheckout')( + state + ) as SBCheckoutFormValuesType const invitationsR = selectors.core.settings.getInvitations(state) const suggestedAmountsR = selectors.components.simpleBuy.getSBSuggestedAmounts( state @@ -14,51 +18,19 @@ export const getData = (state: RootState) => { const supportedCoinsR = selectors.core.walletOptions.getSupportedCoins(state) const userDataR = selectors.modules.profile.getUserData(state) - const bchRatesR = selectors.core.data.bch.getRates(state) - const btcRatesR = selectors.core.data.btc.getRates(state) - const ethRatesR = selectors.core.data.eth.getRates(state) - const paxRatesR = selectors.core.data.eth.getErc20Rates(state, 'pax') - const usdtRatesR = selectors.core.data.eth.getErc20Rates(state, 'usdt') - const xlmRatesR = selectors.core.data.xlm.getRates(state) - const algoRatesR = selectors.core.data.algo.getRates(state) - - const ratesR = lift( + return lift( ( - bchRates, - btcRates, - ethRates, - paxRates, - xlmRates, - usdtRates, - algoRates + invitations: ExtractSuccess, + suggestedAmounts: ExtractSuccess, + supportedCoins: SupportedCoinsType, + userData: ExtractSuccess ) => ({ - BCH: bchRates, - BTC: btcRates, - ETH: ethRates, - PAX: paxRates, - XLM: xlmRates, - USDT: usdtRates, - ALGO: algoRates - }) - )( - bchRatesR, - btcRatesR, - ethRatesR, - paxRatesR, - xlmRatesR, - usdtRatesR, - algoRatesR - ) - - return lift( - (invitations, rates, suggestedAmounts, supportedCoins, userData) => ({ formErrors, formValues, invitations, - rates, suggestedAmounts, supportedCoins, userData }) - )(invitationsR, ratesR, suggestedAmountsR, supportedCoinsR, userDataR) + )(invitationsR, suggestedAmountsR, supportedCoinsR, userDataR) } diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/index.tsx b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/index.tsx index f1a1cef8879..93e31cb7d7a 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/index.tsx @@ -2,14 +2,7 @@ import { actions } from 'data' import { bindActionCreators, Dispatch } from 'redux' import { connect, ConnectedProps } from 'react-redux' import { getData } from './selectors' -import { - LoanType, - NabuApiErrorType, - OfferType, - RemoteDataType, - SupportedCoinsType -} from 'core/types' -import { RatesType, UserDataType } from 'data/types' +import { LoanType, OfferType } from 'core/types' import React, { Component } from 'react' import styled from 'styled-components' import Success from './template.success' @@ -45,7 +38,7 @@ class BorrowHistory extends Component { } } -const mapStateToProps = (state): LinkStatePropsType => ({ +const mapStateToProps = state => ({ data: getData(state) }) @@ -56,17 +49,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({ const connector = connect(mapStateToProps, mapDispatchToProps) -export type SuccessStateType = { - borrowHistory: Array - offers: Array - rates: RatesType - showLoanDetails: (loan: LoanType, offer: OfferType) => void - supportedCoins: SupportedCoinsType - userData: UserDataType -} -type LinkStatePropsType = { - data: RemoteDataType -} +export type SuccessStateType = ReturnType['data'] type Props = ConnectedProps export default connector(BorrowHistory) diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/selectors.ts index 0dce506f034..a3416fc3429 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/selectors.ts @@ -1,3 +1,4 @@ +import { ExtractSuccess, SupportedCoinsType } from 'core/types' import { lift } from 'ramda' import { selectors } from 'data' @@ -9,11 +10,11 @@ export const getData = state => { const userDataR = selectors.modules.profile.getUserData(state) const transform = ( - borrowHistory, - offers, - rates, - supportedCoins, - userData + borrowHistory: ExtractSuccess, + offers: ExtractSuccess, + rates: ExtractSuccess, + supportedCoins: SupportedCoinsType, + userData: ExtractSuccess ) => ({ borrowHistory, offers, diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/template.success.tsx b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/template.success.tsx index 25a2fe1da3f..d45d79aa4ca 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/template.success.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/BorrowHistory/template.success.tsx @@ -8,6 +8,7 @@ import { TableRow, Text } from 'blockchain-info-components' +import { LoanType, OfferType } from 'core/types' import { SuccessStateType } from '.' import CoinDisplay from 'components/Display/CoinDisplay' import CollateralizationBar from 'blockchain-wallet-v4-frontend/src/modals/Borrow/BorrowDetails/CollateralizationBar' @@ -30,7 +31,11 @@ const ViewDetailsCell = styled(TableCell)` justify-content: flex-end; ` -function Success (props: SuccessStateType): ReactElement { +function Success ( + props: SuccessStateType & { + showLoanDetails: (loan: LoanType, offer: OfferType) => void + } +): ReactElement { return (
diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/InitBorrowForm/Amount/index.tsx b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/InitBorrowForm/Amount/index.tsx index 7f9743af633..c6c69ae2a97 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/InitBorrowForm/Amount/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/InitBorrowForm/Amount/index.tsx @@ -1,10 +1,9 @@ -import { CoinType, OfferType, RemoteDataType } from 'core/types' +import { CoinType } from 'core/types' import { connect, ConnectedProps } from 'react-redux' import { convertBaseToStandard } from 'data/components/exchange/services' import { Exchange } from 'blockchain-wallet-v4/src' import { fiatToString } from 'blockchain-wallet-v4/src/exchange/currency' import { getBalance } from './selectors' -import { RatesType } from 'data/types' import { RootState } from 'data/rootReducer' import { Text } from 'blockchain-info-components' import React, { Component } from 'react' @@ -71,7 +70,7 @@ export class Amount extends Component { } } -const mapStateToProps = (state: RootState): LinkStatePropsType => ({ +const mapStateToProps = (state: RootState) => ({ data: getBalance(state) }) @@ -80,19 +79,6 @@ const connector = connect(mapStateToProps) type OwnProps = { coin: CoinType } -type LinkStatePropsType = { - data: RemoteDataType< - Error | string, - { - balance: number - max: number - offer: OfferType - offers: Array - rates: RatesType - values: { coin: CoinType } - } - > -} type Props = OwnProps & ConnectedProps export default connector(Amount) diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/InitBorrowForm/Amount/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/InitBorrowForm/Amount/selectors.ts index 46d312e4b81..99ba6e2e4e1 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/InitBorrowForm/Amount/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Borrow/InitBorrowForm/Amount/selectors.ts @@ -1,4 +1,4 @@ -import { CoinType, OfferType } from 'core/types' +import { CoinType, ExtractSuccess } from 'core/types' import { getBalanceSelector } from 'components/Balances/nonCustodial/selectors' import { lift } from 'ramda' import { selectors } from 'data' @@ -13,7 +13,11 @@ export const getBalance = state => { const ratesR = selectors.core.data.misc.getRatesSelector(values.coin, state) - const transform = (offers: Array, balance, rates) => { + const transform = ( + offers: ExtractSuccess, + balance: number, + rates: ExtractSuccess + ) => { const offer = offers.find( offer => offer.terms.collateralCcy === values.coin ) diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/SummaryCard/index.tsx b/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/SummaryCard/index.tsx index 40f603f83dd..e0e0ae51078 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/SummaryCard/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/SummaryCard/index.tsx @@ -3,15 +3,7 @@ import { connect, ConnectedProps } from 'react-redux' import React, { PureComponent } from 'react' import { actions } from 'data' -import { - CoinType, - FiatType, - InterestAccountBalanceType, - InterestEligibleType, - InterestRateType, - RemoteDataType, - SupportedCoinsType -} from 'core/types' +import { CoinType, InterestRateType, RemoteDataType } from 'core/types' import { SkeletonRectangle, Text } from 'blockchain-info-components' import { getData } from './selectors' @@ -48,20 +40,14 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({ const connector = connect(mapStateToProps, mapDispatchToProps) -export type SuccessStateType = { - interestAccountBalance: InterestAccountBalanceType - interestEligible: InterestEligibleType - showInterestInfoBox: boolean - supportedCoins: SupportedCoinsType - walletCurrency: FiatType -} - export type OwnPropsType = { coin: CoinType interestRate: InterestRateType isGoldTier: boolean } +export type SuccessStateType = ReturnType['data'] + export type LinkStatePropsType = { data: RemoteDataType } diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/SummaryCard/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/SummaryCard/selectors.ts index 143672ac4e3..f3aa5be9109 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/SummaryCard/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/SummaryCard/selectors.ts @@ -1,5 +1,6 @@ import { lift } from 'ramda' +import { ExtractSuccess, FiatType, SupportedCoinsType } from 'core/types' import { selectors } from 'data' export const getData = state => { @@ -11,15 +12,15 @@ export const getData = state => { ) const showInterestInfoBox = selectors.preferences.getShowInterestInfoBox( state - ) + ) as boolean const supportedCoinsR = selectors.core.walletOptions.getSupportedCoins(state) const walletCurrencyR = selectors.core.settings.getCurrency(state) const transform = ( - interestAccountBalance, - interestEligible, - supportedCoins, - walletCurrency + interestAccountBalance: ExtractSuccess, + interestEligible: ExtractSuccess, + supportedCoins: SupportedCoinsType, + walletCurrency: FiatType ) => ({ interestAccountBalance, interestEligible, diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/TransactionList/index.tsx b/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/TransactionList/index.tsx index 877cce1808a..2fb01990c29 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/TransactionList/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/TransactionList/index.tsx @@ -4,16 +4,7 @@ import { connect, ConnectedProps } from 'react-redux' import React, { Component } from 'react' import styled from 'styled-components' -import { - FiatType, - InterestTransactionType, - NabuApiErrorType, - RemoteDataType, - SupportedCoinsType -} from 'core/types' - import { getData } from './selectors' -import { RatesType } from 'data/components/borrow/types' import TransactionList from './template.success' const History = styled.div` @@ -39,7 +30,7 @@ class TransactionListContainer extends Component { } } -const mapStateToProps = (state): LinkStatePropsType => ({ +const mapStateToProps = state => ({ data: getData(state) }) @@ -48,16 +39,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({ }) const connector = connect(mapStateToProps, mapDispatchToProps) -export type SuccessStateType = { - rates: RatesType - supportedCoins: SupportedCoinsType - txPages: Array> - walletCurrency: FiatType -} - -type LinkStatePropsType = { - data: RemoteDataType -} +export type SuccessStateType = ReturnType['data'] export type Props = ConnectedProps diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/TransactionList/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/TransactionList/selectors.ts index 7c8f8dbf30d..d69f59cd242 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/TransactionList/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Interest/TransactionList/selectors.ts @@ -1,5 +1,6 @@ import { lift } from 'ramda' +import { ExtractSuccess, FiatType, SupportedCoinsType } from 'core/types' import { selectors } from 'data' export const getData = state => { @@ -8,7 +9,11 @@ export const getData = state => { const supportedCoinsR = selectors.core.walletOptions.getSupportedCoins(state) const walletCurrencyR = selectors.core.settings.getCurrency(state) - const transform = (rates, supportedCoins, walletCurrency) => ({ + const transform = ( + rates: ExtractSuccess, + supportedCoins: SupportedCoinsType, + walletCurrency: FiatType + ) => ({ rates, supportedCoins, txPages, diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/TheExchange/index.tsx b/packages/blockchain-wallet-v4-frontend/src/scenes/TheExchange/index.tsx index 24560d926d6..bfa2673d399 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/TheExchange/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/TheExchange/index.tsx @@ -47,7 +47,7 @@ const connector = connect(mapStateToProps, mapDispatchToProps) type LinkStatePropsType = { domains: { exchange: string } isExchangeAccountLinked: boolean - isExchangeRelinkRequired: boolean + isExchangeRelinkRequired: boolean | number } export type Props = ConnectedProps diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/CoinIntroduction/index.tsx b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/CoinIntroduction/index.tsx index 2acd22f4bac..1b483fc7638 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/CoinIntroduction/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/CoinIntroduction/index.tsx @@ -5,8 +5,7 @@ import React from 'react' import { actions, selectors } from 'data' import { CoinType, SupportedCoinsType } from 'core/types' -import { currentUserTier, getCurrentKYCState, getTags } from './selectors' -import { ModalNamesType, TagsType, UserDataType } from 'data/types' +import { ModalNamesType } from 'data/types' import Welcome from './template' class CoinIntroductionContainer extends React.PureComponent { @@ -31,9 +30,6 @@ class CoinIntroductionContainer extends React.PureComponent { } const mapStateToProps = (state): LinkStatePropsType => ({ - currentUserTier: currentUserTier(state), - currentTags: getTags(state), - currentKYCState: getCurrentKYCState(state), supportedCoins: selectors.core.walletOptions .getSupportedCoins(state) .getOrFail() @@ -54,9 +50,6 @@ type OwnProps = { coin: CoinType } type LinkStatePropsType = { - currentKYCState: UserDataType['kycState'] - currentTags: TagsType - currentUserTier: 0 | 1 | 2 supportedCoins: SupportedCoinsType | Error } type Props = OwnProps & ConnectedProps diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/CoinIntroduction/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/CoinIntroduction/selectors.ts index 8061681175a..b262346aa42 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/CoinIntroduction/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/CoinIntroduction/selectors.ts @@ -7,7 +7,6 @@ export const getTags = state => { .getOrElse({ BLOCKSTACK: false }) } export const getCurrentKYCState = state => { - // @ts-ignore return selectors.modules.profile.getUserKYCState(state).getOrElse('NONE') } export const currentUserTier = state => { diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/WalletBalanceDropdown/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/WalletBalanceDropdown/selectors.ts index a5a68e0809d..db463cc1c4e 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/WalletBalanceDropdown/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/WalletBalanceDropdown/selectors.ts @@ -144,6 +144,7 @@ export const getData = ( } } + // @ts-ignore return lift(transform)( addressDataR, balanceDataR, diff --git a/packages/blockchain-wallet-v4/src/exchange/index.ts b/packages/blockchain-wallet-v4/src/exchange/index.ts index 13616b19a9f..7581f1786a0 100755 --- a/packages/blockchain-wallet-v4/src/exchange/index.ts +++ b/packages/blockchain-wallet-v4/src/exchange/index.ts @@ -2,8 +2,7 @@ import * as Currency from './currency' import * as Pairs from './pairs' import { assoc, assocPath, path, prop } from 'ramda' import { BigNumber } from 'bignumber.js' -import { CoinType } from 'core/types' -import { RatesType } from 'data/types' +import { CoinType, RatesType } from 'core/types' import Currencies, { CurrenciesType } from './currencies' type KeysOfUnion = T extends any ? keyof T : never diff --git a/packages/blockchain-wallet-v4/src/redux/data/algo/types.ts b/packages/blockchain-wallet-v4/src/redux/data/algo/types.ts index da8cb00b669..c19c7c6683a 100644 --- a/packages/blockchain-wallet-v4/src/redux/data/algo/types.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/algo/types.ts @@ -1,5 +1,4 @@ -import { RatesType } from 'data/types' -import { RemoteDataType } from 'core/types' +import { RatesType, RemoteDataType } from 'core/types' import * as AT from './actionTypes' diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts index c7d7fbd1ff9..6b6d267eb7a 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts @@ -1,9 +1,8 @@ import * as selectors from '../../selectors' -import { CoinType, RemoteDataType } from 'core/types' +import { CoinType, RatesType, RemoteDataType } from 'core/types' import { dataPath } from '../../paths' import { INVALID_COIN_TYPE } from 'blockchain-wallet-v4/src/model' import { path } from 'ramda' -import { RatesType } from 'data/types' import { Remote } from 'blockchain-wallet-v4/src' export const getCaptcha = path([dataPath, 'misc', 'captcha']) diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts new file mode 100644 index 00000000000..00ba482fbcc --- /dev/null +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts @@ -0,0 +1,13 @@ +import { FiatType } from 'core/types' + +export type RateType = { + '15m': number + buy: number + last: number + sell: number + symbol: string +} + +export type RatesType = { + [key in FiatType]: RateType +} diff --git a/packages/blockchain-wallet-v4/src/types/index.ts b/packages/blockchain-wallet-v4/src/types/index.ts index 816375f106b..ce84950aa78 100755 --- a/packages/blockchain-wallet-v4/src/types/index.ts +++ b/packages/blockchain-wallet-v4/src/types/index.ts @@ -94,6 +94,7 @@ export type AccountTypes = BtcAccountType export * from '../redux/payment/types' export * from '../redux/settings/' +export * from '../redux/data/misc/types' export * from '../redux/walletOptions/types' export * from '../network/api/borrow/types' export * from '../network/api/simpleBuy/types' diff --git a/typings/ramda.d.ts b/typings/ramda.d.ts new file mode 100644 index 00000000000..be5f32e418d --- /dev/null +++ b/typings/ramda.d.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +import * as ramda from 'ramda' +import { RemoteDataType } from 'core/types' + +declare module 'ramda' { + export function lift( + f: (...args: any[]) => T + ): (...Fx) => RemoteDataType> { + return Fx => Fx.map(f) + } +} From 57266c7d243766b0b142fdd0eb27bcfe201a253d Mon Sep 17 00:00:00 2001 From: Philip London Date: Tue, 14 Jul 2020 18:32:30 +0200 Subject: [PATCH 2/5] feat(sb): create price_24h actions --- .../src/data/components/activityList/sagas.js | 5 - .../src/network/api/misc/index.ts | 15 ++ .../src/network/api/misc/types.ts | 5 + .../blockchain-wallet-v4/src/network/types.ts | 5 - .../misc/{actionTypes.js => actionTypes.ts} | 6 + .../data/misc/{actions.js => actions.ts} | 46 ++++-- .../data/misc/{reducers.js => reducers.ts} | 60 +++---- .../misc/{sagaRegister.js => sagaRegister.ts} | 1 - .../redux/data/misc/{sagas.js => sagas.ts} | 37 +++-- .../src/redux/data/misc/selectors.ts | 4 + .../src/redux/data/misc/types.ts | 147 +++++++++++++++++- .../src/redux/data/reducers.ts | 8 +- .../blockchain-wallet-v4/src/types/index.ts | 3 + 13 files changed, 272 insertions(+), 70 deletions(-) create mode 100644 packages/blockchain-wallet-v4/src/network/api/misc/types.ts rename packages/blockchain-wallet-v4/src/redux/data/misc/{actionTypes.js => actionTypes.ts} (87%) rename packages/blockchain-wallet-v4/src/redux/data/misc/{actions.js => actions.ts} (77%) rename packages/blockchain-wallet-v4/src/redux/data/misc/{reducers.js => reducers.ts} (53%) rename packages/blockchain-wallet-v4/src/redux/data/misc/{sagaRegister.js => sagaRegister.ts} (91%) rename packages/blockchain-wallet-v4/src/redux/data/misc/{sagas.js => sagas.ts} (83%) diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/activityList/sagas.js b/packages/blockchain-wallet-v4-frontend/src/data/components/activityList/sagas.js index 73aa6f709a4..483fa9b4a21 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/activityList/sagas.js +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/activityList/sagas.js @@ -1,12 +1,10 @@ import { actions, selectors } from 'data' import { isEmpty } from 'ramda' import { put, select } from 'redux-saga/effects' -import { Remote } from 'blockchain-wallet-v4/src' export default () => { const initialized = function * () { try { - const logsR = yield select(selectors.core.data.misc.getLogs) const btcTransactions = yield select( selectors.core.data.btc.getTransactions ) @@ -19,9 +17,6 @@ export default () => { const xlmTransactions = yield select( selectors.core.data.xlm.getTransactions ) - if (!Remote.Success.is(logsR)) { - yield put(actions.core.data.misc.fetchLogs()) - } if (isEmpty(btcTransactions)) { yield put(actions.core.data.btc.fetchTransactions('', true)) } diff --git a/packages/blockchain-wallet-v4/src/network/api/misc/index.ts b/packages/blockchain-wallet-v4/src/network/api/misc/index.ts index 726734772ee..9583321f44b 100755 --- a/packages/blockchain-wallet-v4/src/network/api/misc/index.ts +++ b/packages/blockchain-wallet-v4/src/network/api/misc/index.ts @@ -1,4 +1,7 @@ +import { CoinType, FiatType } from 'core/types' import { equals, toUpper } from 'ramda' +import { Moment } from 'moment' +import { PriceIndexResponseType } from './types' export default ({ rootUrl, apiUrl, get, post }) => { const getCaptchaImage = (timestamp, sessionToken) => @@ -27,6 +30,17 @@ export default ({ rootUrl, apiUrl, get, post }) => { data: { guid, sharedKey, method: 'list-logs', format: 'json' } }) + const getPriceIndex = ( + base: CoinType, + quote: FiatType, + time: Moment + ): PriceIndexResponseType => + get({ + url: apiUrl, + endPoint: '/price/index', + data: { base, quote, time: time.milliseconds } + }) + const getPriceIndexSeries = (coin, currency, start, scale) => get({ url: apiUrl, @@ -61,6 +75,7 @@ export default ({ rootUrl, apiUrl, get, post }) => { getCaptchaImage, getTransactionHistory, getLogs, + getPriceIndex, getPriceIndexSeries, getPriceTimestampSeries, getRandomBytes, diff --git a/packages/blockchain-wallet-v4/src/network/api/misc/types.ts b/packages/blockchain-wallet-v4/src/network/api/misc/types.ts new file mode 100644 index 00000000000..b68ae18cd26 --- /dev/null +++ b/packages/blockchain-wallet-v4/src/network/api/misc/types.ts @@ -0,0 +1,5 @@ +export type PriceIndexResponseType = { + price: number + timestamp: number + volume24h: number +} diff --git a/packages/blockchain-wallet-v4/src/network/types.ts b/packages/blockchain-wallet-v4/src/network/types.ts index 2274d1f373e..fd87f3da2a6 100644 --- a/packages/blockchain-wallet-v4/src/network/types.ts +++ b/packages/blockchain-wallet-v4/src/network/types.ts @@ -2,8 +2,3 @@ export type NabuApiErrorType = { description: string type: string } - -export * from './api/borrow/types' -export * from './api/eth/types' -export * from './api/interest/types' -export * from './api/simpleBuy/types' diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/actionTypes.js b/packages/blockchain-wallet-v4/src/redux/data/misc/actionTypes.ts similarity index 87% rename from packages/blockchain-wallet-v4/src/redux/data/misc/actionTypes.js rename to packages/blockchain-wallet-v4/src/redux/data/misc/actionTypes.ts index 9d1065bbfed..12763a30ca3 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/actionTypes.js +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/actionTypes.ts @@ -10,6 +10,12 @@ export const FETCH_LOGS_LOADING = '@CORE.FETCH_LOGS_LOADING' export const FETCH_LOGS_SUCCESS = '@CORE.FETCH_LOGS_SUCCESS' export const FETCH_LOGS_FAILURE = '@CORE.FETCH_LOGS_FAILURE' +// FETCH_PRICE_24H +export const FETCH_PRICE_24H = '@CORE.FETCH_PRICE_24H' +export const FETCH_PRICE_24H_LOADING = '@CORE.FETCH_PRICE_24H_LOADING' +export const FETCH_PRICE_24H_SUCCESS = '@CORE.FETCH_PRICE_24H_SUCCESS' +export const FETCH_PRICE_24H_FAILURE = '@CORE.FETCH_PRICE_24H_FAILURE' + // FETCH_PRICE_INDEX_SERIES export const FETCH_PRICE_INDEX_SERIES = '@CORE.FETCH_PRICE_INDEX_SERIES' export const FETCH_PRICE_INDEX_SERIES_LOADING = diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/actions.js b/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts similarity index 77% rename from packages/blockchain-wallet-v4/src/redux/data/misc/actions.js rename to packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts index 9d21854b5dd..ff4ea879fb9 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/actions.js +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts @@ -1,4 +1,11 @@ import * as AT from './actionTypes' +import { + CoinType, + FiatType, + MiscActionTypes, + PriceIndexResponseType +} from 'core/types' +import { Moment } from 'moment' // FETCH_CAPTCHA export const fetchCaptcha = () => ({ type: AT.FETCH_CAPTCHA }) @@ -12,16 +19,35 @@ export const fetchCaptchaFailure = error => ({ payload: error }) -// FETCH_LOGS -export const fetchLogs = () => ({ type: AT.FETCH_LOGS }) -export const fetchLogsLoading = () => ({ type: AT.FETCH_LOGS_LOADING }) -export const fetchLogsSuccess = data => ({ - type: AT.FETCH_LOGS_SUCCESS, - payload: data -}) -export const fetchLogsFailure = error => ({ - type: AT.FETCH_LOGS_FAILURE, - payload: error +// FETCH_PRICE_24H +export const fetchPrice24H = ( + base: CoinType, + quote: FiatType, + time: Moment +) => ({ + type: AT.FETCH_PRICE_24H, + payload: { base, quote, time } +}) +export const fetchPrice24HLoading = (base: CoinType): MiscActionTypes => ({ + type: AT.FETCH_PRICE_24H_LOADING, + payload: { base } +}) +export const fetchPrice24HSuccess = ( + base: CoinType, + data: PriceIndexResponseType +): MiscActionTypes => ({ + type: AT.FETCH_PRICE_24H_SUCCESS, + payload: { + base, + data + } +}) +export const fetchPrice24HFailure = (base, error): MiscActionTypes => ({ + type: AT.FETCH_PRICE_24H_FAILURE, + payload: { + error, + base + } }) // FETCH_PRICE_INDEX_SERIES diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/reducers.js b/packages/blockchain-wallet-v4/src/redux/data/misc/reducers.ts similarity index 53% rename from packages/blockchain-wallet-v4/src/redux/data/misc/reducers.js rename to packages/blockchain-wallet-v4/src/redux/data/misc/reducers.ts index 27630b61b9e..732f4277431 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/reducers.js +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/reducers.ts @@ -1,83 +1,85 @@ -import * as AT from './actionTypes.js' +import * as AT from './actionTypes' import { assoc } from 'ramda' +import { MiscActionTypes, MiscStateType } from './types' import Remote from '../../../remote' -const INITIAL_STATE = { +const INITIAL_STATE: MiscStateType = { logs: Remote.NotAsked, captcha: Remote.NotAsked, pairing_code: Remote.NotAsked, + price_24h: { + BTC: Remote.NotAsked, + ETH: Remote.NotAsked, + BCH: Remote.NotAsked, + XLM: Remote.NotAsked, + ALGO: Remote.NotAsked, + PAX: Remote.NotAsked, + USDT: Remote.NotAsked + }, price_index_series: Remote.NotAsked, verify_email_token: Remote.NotAsked, handle_2fa_reset: Remote.NotAsked, authorize_login: Remote.NotAsked } -const miscReducer = (state = INITIAL_STATE, action) => { - const { type, payload } = action - - switch (type) { +export const miscReducer = ( + state = INITIAL_STATE, + action: MiscActionTypes +): MiscStateType => { + switch (action.type) { + case AT.FETCH_CAPTCHA_FAILURE: { + return assoc('captcha', Remote.Failure(action.payload), state) + } case AT.FETCH_CAPTCHA_LOADING: { return assoc('captcha', Remote.Loading, state) } case AT.FETCH_CAPTCHA_SUCCESS: { - return assoc('captcha', Remote.Success(payload), state) - } - case AT.FETCH_CAPTCHA_FAILURE: { - return assoc('captcha', Remote.Failure(payload), state) - } - case AT.FETCH_LOGS_LOADING: { - return assoc('logs', Remote.Loading, state) - } - case AT.FETCH_LOGS_SUCCESS: { - return assoc('logs', Remote.Success(payload), state) - } - case AT.FETCH_LOGS_FAILURE: { - return assoc('logs', Remote.Failure(payload), state) + return assoc('captcha', Remote.Success(action.payload), state) } case AT.FETCH_PRICE_INDEX_SERIES_LOADING: { return assoc('price_index_series', Remote.Loading, state) } case AT.FETCH_PRICE_INDEX_SERIES_SUCCESS: { - return assoc('price_index_series', Remote.Success(payload), state) + return assoc('price_index_series', Remote.Success(action.payload), state) } case AT.FETCH_PRICE_INDEX_SERIES_FAILURE: { - return assoc('price_index_series', Remote.Failure(payload), state) + return assoc('price_index_series', Remote.Failure(action.payload), state) } case AT.ENCODE_PAIRING_CODE_LOADING: { return assoc('pairing_code', Remote.Loading, state) } case AT.ENCODE_PAIRING_CODE_SUCCESS: { - return assoc('pairing_code', Remote.Success(payload), state) + return assoc('pairing_code', Remote.Success(action.payload), state) } case AT.ENCODE_PAIRING_CODE_FAILURE: { - return assoc('pairing_code', Remote.Failure(payload), state) + return assoc('pairing_code', Remote.Failure(action.payload), state) } case AT.AUTHORIZE_LOGIN_LOADING: { return assoc('authorize_login', Remote.Loading, state) } case AT.AUTHORIZE_LOGIN_SUCCESS: { - return assoc('authorize_login', Remote.Success(payload), state) + return assoc('authorize_login', Remote.Success(action.payload), state) } case AT.AUTHORIZE_LOGIN_FAILURE: { - return assoc('authorize_login', Remote.Failure(payload), state) + return assoc('authorize_login', Remote.Failure(action.payload), state) } case AT.HANDLE_2FA_RESET_LOADING: { return assoc('handle_2fa_reset', Remote.Loading, state) } case AT.HANDLE_2FA_RESET_SUCCESS: { - return assoc('handle_2fa_reset', Remote.Success(payload), state) + return assoc('handle_2fa_reset', Remote.Success(action.payload), state) } case AT.HANDLE_2FA_RESET_FAILURE: { - return assoc('handle_2fa_reset', Remote.Failure(payload), state) + return assoc('handle_2fa_reset', Remote.Failure(action.payload), state) } case AT.VERIFY_EMAIL_TOKEN_LOADING: { return assoc('verify_email_token', Remote.Loading, state) } case AT.VERIFY_EMAIL_TOKEN_SUCCESS: { - return assoc('verify_email_token', Remote.Success(payload), state) + return assoc('verify_email_token', Remote.Success(action.payload), state) } case AT.VERIFY_EMAIL_TOKEN_FAILURE: { - return assoc('verify_email_token', Remote.Failure(payload), state) + return assoc('verify_email_token', Remote.Failure(action.payload), state) } default: return state diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.js b/packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.ts similarity index 91% rename from packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.js rename to packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.ts index b5f84d933af..34e532617eb 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.js +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.ts @@ -8,7 +8,6 @@ export default ({ api }) => { return function * coreDataMiscSaga () { yield takeLatest(AT.AUTHORIZE_LOGIN, dataMiscSagas.authorizeLogin) yield takeLatest(AT.FETCH_CAPTCHA, dataMiscSagas.fetchCaptcha) - yield takeLatest(AT.FETCH_LOGS, dataMiscSagas.fetchLogs) yield takeLatest( AT.FETCH_PRICE_INDEX_SERIES, dataMiscSagas.fetchPriceIndexSeries diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/sagas.js b/packages/blockchain-wallet-v4/src/redux/data/misc/sagas.ts similarity index 83% rename from packages/blockchain-wallet-v4/src/redux/data/misc/sagas.js rename to packages/blockchain-wallet-v4/src/redux/data/misc/sagas.ts index 81ecc98ffbf..6982693fe78 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/sagas.js +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/sagas.ts @@ -1,14 +1,16 @@ import * as A from './actions' import * as pairing from '../../../pairing' -import * as selectors from '../../selectors' import * as wS from '../../wallet/selectors' +import { APIType } from 'core/network/api' import { call, put, select } from 'redux-saga/effects' +import { errorHandler } from 'blockchain-wallet-v4/src/utils' +import moment from 'moment' import readBlob from 'read-blob' const taskToPromise = t => new Promise((resolve, reject) => t.fork(reject, resolve)) -export default ({ api }) => { +export default ({ api }: { api: APIType }) => { const fetchCaptcha = function * () { try { const timestamp = new Date().getTime() @@ -22,6 +24,23 @@ export default ({ api }) => { } } + const fetchPrice24H = function * (action: ReturnType) { + const { base, quote } = action.payload + try { + yield put(A.fetchPrice24HLoading(base)) + const response: ReturnType = yield call( + api.getPriceIndex, + base, + quote, + moment().subtract(1, 'day') + ) + yield put(A.fetchPrice24HSuccess(base, response)) + } catch (e) { + const error = errorHandler(e) + yield put(A.fetchPrice24HFailure(base, error)) + } + } + const fetchPriceIndexSeries = function * (action) { try { const { coin, currency, start, scale } = action.payload @@ -39,18 +58,6 @@ export default ({ api }) => { } } - const fetchLogs = function * ({ address }) { - try { - const guid = yield select(selectors.wallet.getGuid) - const sharedKey = yield select(selectors.wallet.getSharedKey) - yield put(A.fetchLogsLoading()) - const data = yield call(api.getLogs, guid, sharedKey) - yield put(A.fetchLogsSuccess(data.results)) - } catch (e) { - yield put(A.fetchLogsFailure(e.message)) - } - } - const encodePairingCode = function * () { try { yield put(A.encodePairingCodeLoading()) @@ -117,7 +124,7 @@ export default ({ api }) => { return { authorizeLogin, fetchCaptcha, - fetchLogs, + fetchPrice24H, fetchPriceIndexSeries, encodePairingCode, verifyEmailToken, diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts index 6b6d267eb7a..0ec1e78668c 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts @@ -4,6 +4,7 @@ import { dataPath } from '../../paths' import { INVALID_COIN_TYPE } from 'blockchain-wallet-v4/src/model' import { path } from 'ramda' import { Remote } from 'blockchain-wallet-v4/src' +import { RootState } from 'data/rootReducer' export const getCaptcha = path([dataPath, 'misc', 'captcha']) @@ -23,6 +24,9 @@ export const handle2FAReset = path([dataPath, 'misc', 'handle_2fa_reset']) export const verifyEmailToken = path([dataPath, 'misc', 'verify_email_token']) +export const getPrice24H = (state: RootState, coin: CoinType) => + state.dataPath.misc.price_24h[coin] + export const getRatesSelector = ( coin: CoinType, state diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts index 00ba482fbcc..847b63d42c0 100644 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts @@ -1,5 +1,12 @@ -import { FiatType } from 'core/types' +import * as AT from './actionTypes' +import { + CoinType, + FiatType, + PriceIndexResponseType, + RemoteDataType +} from 'core/types' +// types export type RateType = { '15m': number buy: number @@ -11,3 +18,141 @@ export type RateType = { export type RatesType = { [key in FiatType]: RateType } + +// state +export type MiscStateType = { + authorize_login: RemoteDataType + captcha: RemoteDataType + handle_2fa_reset: RemoteDataType + logs: RemoteDataType + pairing_code: RemoteDataType + price_24h: { + [key in CoinType]: RemoteDataType + } + price_index_series: RemoteDataType + verify_email_token: RemoteDataType +} + +// actions + +interface AuthorizeLoginFailureActionType { + payload: { + error: string + } + type: typeof AT.AUTHORIZE_LOGIN_FAILURE +} +interface AuthorizeLoginLoadingActionType { + type: typeof AT.AUTHORIZE_LOGIN_LOADING +} +interface AuthorizeLoginSuccessActionType { + payload: any + type: typeof AT.AUTHORIZE_LOGIN_SUCCESS +} +interface EncodePairingCodeFailureActionType { + payload: { + error: string + } + type: typeof AT.ENCODE_PAIRING_CODE_FAILURE +} +interface EncodePairingCodeLoadingActionType { + type: typeof AT.ENCODE_PAIRING_CODE_LOADING +} +interface EncodePairingCodeSuccessActionType { + payload: any + type: typeof AT.ENCODE_PAIRING_CODE_SUCCESS +} +interface FetchCaptchaFailureActionType { + payload: { + error: string + } + type: typeof AT.FETCH_CAPTCHA_FAILURE +} +interface FetchCaptchaLoadingActionType { + type: typeof AT.FETCH_CAPTCHA_LOADING +} +interface FetchCaptchaSuccessActionType { + payload: any + type: typeof AT.FETCH_CAPTCHA_SUCCESS +} +interface FetchPrice24HFailureActionType { + payload: { + base: CoinType + error: string + } + type: typeof AT.FETCH_PRICE_24H_FAILURE +} +interface FetchPrice24HLoadingActionType { + payload: { + base: CoinType + } + type: typeof AT.FETCH_PRICE_24H_LOADING +} +interface FetchPrice24HSuccessActionType { + payload: { + base: CoinType + data: PriceIndexResponseType + } + type: typeof AT.FETCH_PRICE_24H_SUCCESS +} +interface FetchPriceIndexSeriesFailureActionType { + payload: { + error: string + } + type: typeof AT.FETCH_PRICE_INDEX_SERIES_FAILURE +} +interface FetchPriceIndexSeriesLoadingActionType { + type: typeof AT.FETCH_PRICE_INDEX_SERIES_LOADING +} +interface FetchPriceIndexSeriesSuccessActionType { + payload: any + type: typeof AT.FETCH_PRICE_INDEX_SERIES_SUCCESS +} +interface Handle2FAResetFailureActionType { + payload: { + error: string + } + type: typeof AT.HANDLE_2FA_RESET_FAILURE +} +interface Handle2FAResetLoadingActionType { + type: typeof AT.HANDLE_2FA_RESET_LOADING +} +interface Handle2FAResetSuccessActionType { + payload: any + type: typeof AT.HANDLE_2FA_RESET_SUCCESS +} +interface VerifyEmailTokenFailureActionType { + payload: { + error: string + } + type: typeof AT.VERIFY_EMAIL_TOKEN_FAILURE +} +interface VerifyEmailTokenLoadingActionType { + type: typeof AT.VERIFY_EMAIL_TOKEN_LOADING +} +interface VerifyEmailTokenSuccessActionType { + payload: any + type: typeof AT.VERIFY_EMAIL_TOKEN_SUCCESS +} + +export type MiscActionTypes = + | AuthorizeLoginFailureActionType + | AuthorizeLoginLoadingActionType + | AuthorizeLoginSuccessActionType + | EncodePairingCodeFailureActionType + | EncodePairingCodeLoadingActionType + | EncodePairingCodeSuccessActionType + | FetchCaptchaFailureActionType + | FetchCaptchaLoadingActionType + | FetchCaptchaSuccessActionType + | FetchPrice24HFailureActionType + | FetchPrice24HLoadingActionType + | FetchPrice24HSuccessActionType + | FetchPriceIndexSeriesFailureActionType + | FetchPriceIndexSeriesLoadingActionType + | FetchPriceIndexSeriesSuccessActionType + | Handle2FAResetFailureActionType + | Handle2FAResetLoadingActionType + | Handle2FAResetSuccessActionType + | VerifyEmailTokenFailureActionType + | VerifyEmailTokenLoadingActionType + | VerifyEmailTokenSuccessActionType diff --git a/packages/blockchain-wallet-v4/src/redux/data/reducers.ts b/packages/blockchain-wallet-v4/src/redux/data/reducers.ts index 6a6db89bbda..8dad7b16c30 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/reducers.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/reducers.ts @@ -1,17 +1,17 @@ +import { algoReducer } from './algo/reducers' import { combineReducers } from 'redux' -import algo from './algo/reducers' +import { miscReducer } from './misc/reducers' import bch from './bch/reducers' import btc from './btc/reducers' import eth from './eth/reducers' -import misc from './misc/reducers' import xlm from './xlm/reducers' const dataReducer = combineReducers({ - algo, + algo: algoReducer, bch, btc, eth, - misc, + misc: miscReducer, xlm }) diff --git a/packages/blockchain-wallet-v4/src/types/index.ts b/packages/blockchain-wallet-v4/src/types/index.ts index ce84950aa78..2c9057aaa63 100755 --- a/packages/blockchain-wallet-v4/src/types/index.ts +++ b/packages/blockchain-wallet-v4/src/types/index.ts @@ -96,7 +96,10 @@ export * from '../redux/payment/types' export * from '../redux/settings/' export * from '../redux/data/misc/types' export * from '../redux/walletOptions/types' +export * from '../network/api/eth/types' export * from '../network/api/borrow/types' +export * from '../network/api/interest/types' +export * from '../network/api/misc/types' export * from '../network/api/simpleBuy/types' export * from '../exchange/currencies' export * from '../network/types' From 71f20960948f7daf439f4c1b750f446ad5b5cf69 Mon Sep 17 00:00:00 2001 From: Philip London Date: Wed, 15 Jul 2020 12:25:49 +0200 Subject: [PATCH 3/5] feat(sb): display price movement --- .../CryptoSelector/CryptoItem/index.tsx | 10 ++- .../CryptoSelector/CryptoItem/selectors.ts | 10 ++- .../CryptoItem/template.success.tsx | 13 ++- .../CryptoSelector/PriceMovement/index.tsx | 86 +++++++++++++++++++ .../CryptoSelector/PriceMovement/selectors.ts | 16 ++++ .../src/network/api/misc/index.ts | 2 +- .../src/redux/data/misc/actions.ts | 22 ++--- .../src/redux/data/misc/reducers.ts | 27 ++++++ .../src/redux/data/misc/sagaRegister.ts | 3 +- .../src/redux/data/misc/sagas.ts | 20 ++++- .../src/redux/data/misc/selectors.ts | 2 +- .../src/redux/data/misc/types.ts | 15 ++-- yarn.lock | 7 +- 13 files changed, 195 insertions(+), 38 deletions(-) create mode 100644 packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/index.tsx create mode 100644 packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/selectors.ts diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/index.tsx index e1a7f848da3..13c3aa03335 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/index.tsx @@ -1,3 +1,5 @@ +import { actions } from 'data' +import { bindActionCreators, Dispatch } from 'redux' import { connect, ConnectedProps } from 'react-redux' import { getData } from './selectors' import { RootState } from 'data/rootReducer' @@ -6,8 +8,6 @@ import React, { PureComponent } from 'react' import Success from './template.success' class CryptoItem extends PureComponent { - state = {} - render () { return this.props.data.cata({ Success: val => , @@ -22,7 +22,11 @@ const mapStateToProps = (state: RootState, ownProps: OwnProps) => ({ data: getData(state, ownProps) }) -const connector = connect(mapStateToProps) +const mapDispatchToProps = (dispatch: Dispatch) => ({ + miscActions: bindActionCreators(actions.core.data.misc, dispatch) +}) + +const connector = connect(mapStateToProps, mapDispatchToProps) export type OwnProps = { onClick: (string) => void diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/selectors.ts index 337d4e5d868..bab404c5870 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/selectors.ts +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/selectors.ts @@ -1,14 +1,18 @@ import { ExtractSuccess } from 'core/types' import { getCoinFromPair } from 'data/components/simpleBuy/model' -import { getRatesSelector } from 'core/redux/data/misc/selectors' import { lift } from 'ramda' import { RootState } from 'data/rootReducer' import { OwnProps } from '.' +import { selectors } from 'data' export const getData = (state: RootState, ownProps: OwnProps) => { const coin = getCoinFromPair(ownProps.value.pair) - const ratesR = getRatesSelector(coin, state) + const ratesR = selectors.core.data.misc.getRatesSelector(coin, state) + const fiatCurrency = selectors.components.simpleBuy.getFiatCurrency(state) - return lift((rates: ExtractSuccess) => ({ rates }))(ratesR) + return lift((rates: ExtractSuccess) => ({ + fiatCurrency, + rates + }))(ratesR) } diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/template.success.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/template.success.tsx index 4059a33d142..a468d300d52 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/template.success.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/CryptoItem/template.success.tsx @@ -15,6 +15,7 @@ import { OwnProps as ParentOwnProps, SuccessStateType } from '.' +import PriceMovement from '../PriceMovement' const DisplayContainer = styled.div<{ coinType: SupportedCoinType @@ -40,6 +41,11 @@ const Display = styled.div` font-weight: 500; color: ${props => props.theme.grey800}; ` +const DisplayTitle = styled(Title)` + margin-top: 4px; + display: flex; + align-items: center; +` type Props = OwnProps & ParentOwnProps & SuccessStateType @@ -60,13 +66,14 @@ const Success: React.FC = props => { > - {displayName} - + <Value style={{ marginTop: '0px' }}>{displayName}</Value> + <DisplayTitle> {fiatToString({ value: props.rates[fiat].last, unit: fiat })} - + + diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/index.tsx new file mode 100644 index 00000000000..0be91a6e4e7 --- /dev/null +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/index.tsx @@ -0,0 +1,86 @@ +import { actions } from 'data' +import { bindActionCreators, Dispatch } from 'redux' +import { connect, ConnectedProps } from 'react-redux' +import { FiatType, SBPairType } from 'core/types' +import { getCoinFromPair } from 'data/components/simpleBuy/model' +import { RootState } from 'data/rootReducer' +import React, { PureComponent } from 'react' +import styled, { DefaultTheme } from 'styled-components' + +import { getData } from './selectors' +import { SkeletonRectangle } from 'blockchain-info-components' + +const Container = styled.span` + margin-left: 8px; +` +const Change = styled.span<{ color: keyof DefaultTheme }>` + font-weight: 500; + color: ${props => props.theme[props.color]}; +` + +const getSignFromMovement = (movement: 'none' | 'up' | 'down') => { + switch (movement) { + case 'down': + return '-' + case 'up': + return '+' + default: + return '' + } +} + +const getColorFromMovement = (movement: 'none' | 'up' | 'down') => { + switch (movement) { + case 'down': + return 'red600' + case 'up': + return 'green600' + default: + return 'grey600' + } +} + +class PriceMovement extends PureComponent { + componentDidMount () { + const coin = getCoinFromPair(this.props.value.pair) + this.props.miscActions.fetchPrice24H(coin, this.props.fiatCurrency || 'EUR') + } + + render () { + return ( + + {this.props.data.cata({ + Success: val => ( + + {getSignFromMovement(val.price24Hr.movement)} + {val.price24Hr.change}% + + ), + Loading: () => , + Failure: () => null, + NotAsked: () => null + })} + + ) + } +} + +const mapStateToProps = (state: RootState, ownProps: OwnProps) => ({ + data: getData(state, ownProps) +}) + +const mapDispatchToProps = (dispatch: Dispatch) => ({ + miscActions: bindActionCreators(actions.core.data.misc, dispatch) +}) + +const connector = connect(mapStateToProps, mapDispatchToProps) + +export type OwnProps = { + fiatCurrency?: FiatType + value: SBPairType +} +type SuccessStateType = ReturnType['data'] +type Props = OwnProps & ConnectedProps +type State = {} + +export default connector(PriceMovement) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/selectors.ts b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/selectors.ts new file mode 100644 index 00000000000..c2d443584b0 --- /dev/null +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/selectors.ts @@ -0,0 +1,16 @@ +import { ExtractSuccess } from 'core/types' +import { getCoinFromPair } from 'data/components/simpleBuy/model' +import { lift } from 'ramda' +import { RootState } from 'data/rootReducer' + +import { OwnProps } from '.' +import { selectors } from 'data' + +export const getData = (state: RootState, ownProps: OwnProps) => { + const coin = getCoinFromPair(ownProps.value.pair) + const price24HrR = selectors.core.data.misc.getPrice24H(coin, state) + + return lift((price24Hr: ExtractSuccess) => ({ + price24Hr + }))(price24HrR) +} diff --git a/packages/blockchain-wallet-v4/src/network/api/misc/index.ts b/packages/blockchain-wallet-v4/src/network/api/misc/index.ts index 9583321f44b..af4cbf731c4 100755 --- a/packages/blockchain-wallet-v4/src/network/api/misc/index.ts +++ b/packages/blockchain-wallet-v4/src/network/api/misc/index.ts @@ -38,7 +38,7 @@ export default ({ rootUrl, apiUrl, get, post }) => { get({ url: apiUrl, endPoint: '/price/index', - data: { base, quote, time: time.milliseconds } + data: { base, quote, time: time.unix() } }) const getPriceIndexSeries = (coin, currency, start, scale) => diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts index ff4ea879fb9..5cecc5de5c1 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts @@ -1,11 +1,5 @@ import * as AT from './actionTypes' -import { - CoinType, - FiatType, - MiscActionTypes, - PriceIndexResponseType -} from 'core/types' -import { Moment } from 'moment' +import { CoinType, FiatType, MiscActionTypes } from 'core/types' // FETCH_CAPTCHA export const fetchCaptcha = () => ({ type: AT.FETCH_CAPTCHA }) @@ -20,13 +14,9 @@ export const fetchCaptchaFailure = error => ({ }) // FETCH_PRICE_24H -export const fetchPrice24H = ( - base: CoinType, - quote: FiatType, - time: Moment -) => ({ +export const fetchPrice24H = (base: CoinType, quote: FiatType) => ({ type: AT.FETCH_PRICE_24H, - payload: { base, quote, time } + payload: { base, quote } }) export const fetchPrice24HLoading = (base: CoinType): MiscActionTypes => ({ type: AT.FETCH_PRICE_24H_LOADING, @@ -34,12 +24,14 @@ export const fetchPrice24HLoading = (base: CoinType): MiscActionTypes => ({ }) export const fetchPrice24HSuccess = ( base: CoinType, - data: PriceIndexResponseType + change: string, + movement: 'none' | 'up' | 'down' ): MiscActionTypes => ({ type: AT.FETCH_PRICE_24H_SUCCESS, payload: { base, - data + change, + movement } }) export const fetchPrice24HFailure = (base, error): MiscActionTypes => ({ diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/reducers.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/reducers.ts index 732f4277431..70b3372c40b 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/reducers.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/reducers.ts @@ -36,6 +36,33 @@ export const miscReducer = ( case AT.FETCH_CAPTCHA_SUCCESS: { return assoc('captcha', Remote.Success(action.payload), state) } + case AT.FETCH_PRICE_24H_LOADING: { + return { + ...state, + price_24h: { + ...state.price_24h, + [action.payload.base]: Remote.Loading + } + } + } + case AT.FETCH_PRICE_24H_SUCCESS: { + return { + ...state, + price_24h: { + ...state.price_24h, + [action.payload.base]: Remote.Success(action.payload) + } + } + } + case AT.FETCH_PRICE_24H_FAILURE: { + return { + ...state, + price_24h: { + ...state.price_24h, + [action.payload.base]: Remote.Failure(action.payload.error) + } + } + } case AT.FETCH_PRICE_INDEX_SERIES_LOADING: { return assoc('price_index_series', Remote.Loading, state) } diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.ts index 34e532617eb..b9cad65e3f6 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/sagaRegister.ts @@ -1,5 +1,5 @@ import * as AT from './actionTypes' -import { takeLatest } from 'redux-saga/effects' +import { takeEvery, takeLatest } from 'redux-saga/effects' import sagas from './sagas' export default ({ api }) => { @@ -8,6 +8,7 @@ export default ({ api }) => { return function * coreDataMiscSaga () { yield takeLatest(AT.AUTHORIZE_LOGIN, dataMiscSagas.authorizeLogin) yield takeLatest(AT.FETCH_CAPTCHA, dataMiscSagas.fetchCaptcha) + yield takeEvery(AT.FETCH_PRICE_24H, dataMiscSagas.fetchPrice24H) yield takeLatest( AT.FETCH_PRICE_INDEX_SERIES, dataMiscSagas.fetchPriceIndexSeries diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/sagas.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/sagas.ts index 6982693fe78..6852fd4db60 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/sagas.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/sagas.ts @@ -4,6 +4,7 @@ import * as wS from '../../wallet/selectors' import { APIType } from 'core/network/api' import { call, put, select } from 'redux-saga/effects' import { errorHandler } from 'blockchain-wallet-v4/src/utils' +import BigNumber from 'bignumber.js' import moment from 'moment' import readBlob from 'read-blob' @@ -28,13 +29,28 @@ export default ({ api }: { api: APIType }) => { const { base, quote } = action.payload try { yield put(A.fetchPrice24HLoading(base)) - const response: ReturnType = yield call( + const yesterday: ReturnType = yield call( api.getPriceIndex, base, quote, moment().subtract(1, 'day') ) - yield put(A.fetchPrice24HSuccess(base, response)) + const today: ReturnType = yield call( + api.getPriceIndex, + base, + quote, + moment() + ) + const diff = new BigNumber( + (today.price - yesterday.price) / yesterday.price + ).times(100) + const change = diff.abs().toFixed(2) + const movement = diff.isEqualTo(0) + ? 'none' + : diff.isGreaterThan(0) + ? 'up' + : 'down' + yield put(A.fetchPrice24HSuccess(base, change, movement)) } catch (e) { const error = errorHandler(e) yield put(A.fetchPrice24HFailure(base, error)) diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts index 0ec1e78668c..2216d279973 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/selectors.ts @@ -24,7 +24,7 @@ export const handle2FAReset = path([dataPath, 'misc', 'handle_2fa_reset']) export const verifyEmailToken = path([dataPath, 'misc', 'verify_email_token']) -export const getPrice24H = (state: RootState, coin: CoinType) => +export const getPrice24H = (coin: CoinType, state: RootState) => state.dataPath.misc.price_24h[coin] export const getRatesSelector = ( diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts index 847b63d42c0..a3cc816c609 100644 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts @@ -1,10 +1,5 @@ import * as AT from './actionTypes' -import { - CoinType, - FiatType, - PriceIndexResponseType, - RemoteDataType -} from 'core/types' +import { CoinType, FiatType, RemoteDataType } from 'core/types' // types export type RateType = { @@ -27,7 +22,10 @@ export type MiscStateType = { logs: RemoteDataType pairing_code: RemoteDataType price_24h: { - [key in CoinType]: RemoteDataType + [key in CoinType]: RemoteDataType< + string, + { change: string; movement: 'none' | 'up' | 'down' } + > } price_index_series: RemoteDataType verify_email_token: RemoteDataType @@ -90,7 +88,8 @@ interface FetchPrice24HLoadingActionType { interface FetchPrice24HSuccessActionType { payload: { base: CoinType - data: PriceIndexResponseType + change: string + movement: 'none' | 'up' | 'down' } type: typeof AT.FETCH_PRICE_24H_SUCCESS } diff --git a/yarn.lock b/yarn.lock index bc72a4757e8..12982339831 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13690,11 +13690,16 @@ mock-socket@8.0.5: dependencies: url-parse "^1.2.0" -moment@*, moment@2.24.0: +moment@*: version "2.24.0" resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b" integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg== +moment@2.27.0: + version "2.27.0" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.27.0.tgz#8bff4e3e26a236220dfe3e36de756b6ebaa0105d" + integrity sha512-al0MUK7cpIcglMv3YF13qSgdAIqxHTO7brRtaz3DlSULbqfazqkc5kEjNrLDOM7fsjshoFIihnU8snrP7zUvhQ== + moo@^0.5.0: version "0.5.1" resolved "https://registry.yarnpkg.com/moo/-/moo-0.5.1.tgz#7aae7f384b9b09f620b6abf6f74ebbcd1b65dbc4" From 805f6170030807da7c3a43722796c58e52fdf75d Mon Sep 17 00:00:00 2001 From: Philip London Date: Wed, 15 Jul 2020 12:41:31 +0200 Subject: [PATCH 4/5] Update index.tsx --- .../src/modals/SimpleBuy/EnterAmount/Checkout/index.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/index.tsx index 82c25d24b4b..6b4320645d4 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/EnterAmount/Checkout/index.tsx @@ -42,8 +42,6 @@ class Checkout extends PureComponent { } as SuccessStateType) if (userData.tiers.current < 2) { - // eslint-disable-next-line - console.log('inside first if') this.props.identityVerificationActions.verifyIdentity( 2, false, @@ -54,8 +52,6 @@ class Checkout extends PureComponent { formValues?.method?.type as SBPaymentMethodType['type'] ) } else if (formValues && formValues.method) { - // eslint-disable-next-line - console.log('here we gooo', formValues.method.type) switch (formValues.method.type) { case 'PAYMENT_CARD': this.props.simpleBuyActions.setStep({ From 96f8041db27ae0d738237662a9e1ddbd69cb98ce Mon Sep 17 00:00:00 2001 From: Philip London Date: Wed, 15 Jul 2020 13:01:16 +0200 Subject: [PATCH 5/5] refactor(sb): price movement type --- .../CryptoSelector/PriceMovement/index.tsx | 6 +++--- .../blockchain-wallet-v4/src/redux/data/misc/actions.ts | 9 +++++++-- .../blockchain-wallet-v4/src/redux/data/misc/types.ts | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/index.tsx b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/index.tsx index 0be91a6e4e7..22412ba3cd8 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/index.tsx +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SimpleBuy/CryptoSelection/CryptoSelector/PriceMovement/index.tsx @@ -1,7 +1,7 @@ import { actions } from 'data' import { bindActionCreators, Dispatch } from 'redux' import { connect, ConnectedProps } from 'react-redux' -import { FiatType, SBPairType } from 'core/types' +import { FiatType, PriceMovementDirType, SBPairType } from 'core/types' import { getCoinFromPair } from 'data/components/simpleBuy/model' import { RootState } from 'data/rootReducer' import React, { PureComponent } from 'react' @@ -18,7 +18,7 @@ const Change = styled.span<{ color: keyof DefaultTheme }>` color: ${props => props.theme[props.color]}; ` -const getSignFromMovement = (movement: 'none' | 'up' | 'down') => { +const getSignFromMovement = (movement: PriceMovementDirType) => { switch (movement) { case 'down': return '-' @@ -29,7 +29,7 @@ const getSignFromMovement = (movement: 'none' | 'up' | 'down') => { } } -const getColorFromMovement = (movement: 'none' | 'up' | 'down') => { +const getColorFromMovement = (movement: PriceMovementDirType) => { switch (movement) { case 'down': return 'red600' diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts index 5cecc5de5c1..2812c7bd4f4 100755 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/actions.ts @@ -1,5 +1,10 @@ import * as AT from './actionTypes' -import { CoinType, FiatType, MiscActionTypes } from 'core/types' +import { + CoinType, + FiatType, + MiscActionTypes, + PriceMovementDirType +} from 'core/types' // FETCH_CAPTCHA export const fetchCaptcha = () => ({ type: AT.FETCH_CAPTCHA }) @@ -25,7 +30,7 @@ export const fetchPrice24HLoading = (base: CoinType): MiscActionTypes => ({ export const fetchPrice24HSuccess = ( base: CoinType, change: string, - movement: 'none' | 'up' | 'down' + movement: PriceMovementDirType ): MiscActionTypes => ({ type: AT.FETCH_PRICE_24H_SUCCESS, payload: { diff --git a/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts b/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts index a3cc816c609..8bc406599d9 100644 --- a/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts +++ b/packages/blockchain-wallet-v4/src/redux/data/misc/types.ts @@ -14,6 +14,8 @@ export type RatesType = { [key in FiatType]: RateType } +export type PriceMovementDirType = 'none' | 'up' | 'down' + // state export type MiscStateType = { authorize_login: RemoteDataType @@ -24,7 +26,7 @@ export type MiscStateType = { price_24h: { [key in CoinType]: RemoteDataType< string, - { change: string; movement: 'none' | 'up' | 'down' } + { change: string; movement: PriceMovementDirType } > } price_index_series: RemoteDataType @@ -89,7 +91,7 @@ interface FetchPrice24HSuccessActionType { payload: { base: CoinType change: string - movement: 'none' | 'up' | 'down' + movement: PriceMovementDirType } type: typeof AT.FETCH_PRICE_24H_SUCCESS }