Skip to content

Commit

Permalink
Merge pull request #2147 from blockchain/feat/ts-payments
Browse files Browse the repository at this point in the history
Feat/ts payments
  • Loading branch information
schnogz committed Mar 8, 2020
2 parents 2425079 + f829b98 commit 7af20ea
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as AT from './actionTypes'
import { BorrowActionTypes, BorrowMinMaxType, PaymentValue } from './types'
import { BorrowActionTypes, BorrowMinMaxType } from './types'
import {
CoinType,
LoanFinancialsType,
LoanTransactionsType,
LoanType,
OfferType
} from 'blockchain-wallet-v4/src/types'
OfferType,
PaymentValue
} from 'core/types'

export const addCollateral = () => ({
type: AT.ADD_COLLATERAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +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,
PaymentType,
PaymentValue,
RepayLoanFormType
} from './types'
import { BorrowFormValuesType, RepayLoanFormType } from './types'
import {
convertBaseToStandard,
convertStandardToBase
Expand All @@ -21,7 +16,12 @@ import {
} from './model'
import { FormAction, initialize, touch } from 'redux-form'
import { head, nth } from 'ramda'
import { LoanFinancialsType, LoanType } from 'core/types'
import {
LoanFinancialsType,
LoanType,
PaymentType,
PaymentValue
} from 'core/types'
import BigNumber from 'bignumber.js'
import exchangeSagaUtils from '../exchange/sagas.utils'
import profileSagas from '../../../data/modules/profile/sagas'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import * as S from './selectors'
import { ADDRESS_TYPES } from 'blockchain-wallet-v4/src/redux/payment/btc/utils'
import { APIType } from 'core/network/api'
import { call, CallEffect, put, select } from 'redux-saga/effects'
import { CoinType, RemoteDataType } from 'core/types'
import { CoinType, PaymentType, PaymentValue, RemoteDataType } from 'core/types'
import { convertStandardToBase } from '../exchange/services'
import { Exchange } from 'blockchain-wallet-v4/src'
import { NO_OFFER_EXISTS } from './model'
import { PaymentType, PaymentValue } from './types'
import { promptForSecondPassword } from 'services/SagaService'
import BigNumber from 'bignumber.js'

Expand All @@ -28,9 +27,18 @@ export default ({
): Generator<PaymentType | CallEffect, boolean, any> {
let paymentError
try {
payment = yield payment.amount(
parseInt(convertStandardToBase(coin, amount))
)
switch (payment.coin) {
case 'PAX':
case 'ETH':
payment = yield payment.amount(
parseInt(convertStandardToBase(coin, amount)).toString()
)
break
default:
payment = yield payment.amount(
parseInt(convertStandardToBase(coin, amount))
)
}
payment = yield payment.to(destination, ADDRESS_TYPES.ADDRESS)
payment = yield payment.build()
// ask for second password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LoanType,
NabuApiErrorType,
OfferType,
PaymentValue,
RemoteDataType
} from 'core/types'

Expand Down Expand Up @@ -52,63 +53,6 @@ export type RepayLoanFormType = {
'repay-type': 'full' | 'partial'
}

// TODO: move to payments
export type UTXOType = {
address: string
change: boolean
index: number
path: string
script: string
txHash: string
value: number
xpub: {
m: string
path: string
}
}

export type FromType =
| 'ACCOUNT'
| 'LEGACY'
| 'WATCH_ONLY'
| 'EXTERNAL'
| 'LOCKBOX'
| 'ADDRESS'

export type PaymentValue = {
amount?: Array<number>
change: string
coins: Array<UTXOType>
effectiveBalance: number
fee: number
fees: {
limits: {
max: number
min: number
}
priority: number
regular: number
}
from: Array<string>
fromAccountIdx: number
fromType: FromType
selection?: {
fee: number
inputs: Array<UTXOType>
outputs: Array<UTXOType>
}
to?: Array<any>
}

export type PaymentType = {
amount: (n: number | string) => PaymentType
build: () => PaymentType
publish: () => PaymentType
sign: (pw: string) => PaymentType
to: (address: string, addressType?: FromType) => PaymentType
value: () => PaymentValue
}

// State
export interface BorrowState {
borrowHistory: RemoteDataType<NabuApiErrorType, Array<LoanType>>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { actions } from 'data'
import { bindActionCreators, compose, Dispatch } from 'redux'
import { BorrowMinMaxType, PaymentType, RatesType } from 'data/types'
import { BorrowMinMaxType, RatesType } from 'data/types'
import {
CoinType,
LoanTransactionsType,
LoanType,
OfferType,
PaymentType,
RemoteDataType,
SupportedCoinsType
} from 'core/types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { actions } from 'data'
import { bindActionCreators, compose, Dispatch } from 'redux'
import { BorrowMinMaxType, PaymentType, RatesType } from 'data/types'
import { BorrowMinMaxType, RatesType } from 'data/types'
import {
CoinType,
OfferType,
PaymentType,
RemoteDataType,
SupportedCoinsType
} from 'core/types'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { actions } from 'data'
import { bindActionCreators, compose, Dispatch } from 'redux'
import { connect } from 'react-redux'
import { getData } from './selectors'
import { OfferType, RemoteDataType } from 'core/types'
import { PaymentValue, RatesType } from 'data/types'
import { OfferType, PaymentValue, RemoteDataType } from 'core/types'
import { RatesType } from 'data/types'
import { RootState } from 'data/rootReducer'
import DataError from 'components/DataError'
import Loading from './template.loading'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { actions } from 'data'
import { bindActionCreators, Dispatch } from 'redux'
import { BorrowMinMaxType, PaymentType, RatesType } from 'data/types'
import { BorrowMinMaxType, RatesType } from 'data/types'
import { connect } from 'react-redux'
import { getData } from './selectors'
import {
LoanTransactionsType,
LoanType,
OfferType,
PaymentType,
RemoteDataType,
SupportedCoinsType
} from 'core/types'
Expand Down
2 changes: 2 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/payment/bch/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ export default ({ api }) => {
// ///////////////////////////////////////////////////////////////////////////
function create ({ network, payment } = { network: undefined, payment: {} }) {
const makePayment = p => ({
coin: 'BCH',

value () {
return p
},
Expand Down
2 changes: 2 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/payment/btc/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ export default ({ api }) => {

function create ({ network, payment } = { network: undefined, payment: {} }) {
const makePayment = p => ({
coin: 'BTC',

value () {
return p
},
Expand Down
2 changes: 2 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/payment/eth/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export default ({ api }) => {

function create ({ network, payment } = { network: undefined, payment: {} }) {
const makePayment = p => ({
coin: 'ETH',

value () {
return p
},
Expand Down
82 changes: 82 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/payment/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { CoinType } from 'core/types'

export type UTXOType = {
address: string
change: boolean
index: number
path: string
script: string
txHash: string
value: number
xpub: {
m: string
path: string
}
}

export type FromType =
| 'ACCOUNT'
| 'LEGACY'
| 'WATCH_ONLY'
| 'EXTERNAL'
| 'LOCKBOX'
| 'ADDRESS'

export type PaymentValue = {
amount?: Array<number>
change: string
coins: Array<UTXOType>
effectiveBalance: number
fee: number
fees: {
limits: {
max: number
min: number
}
priority: number
regular: number
}
from: Array<string>
fromAccountIdx: number
fromType: FromType
selection?: {
fee: number
inputs: Array<UTXOType>
outputs: Array<UTXOType>
}
to?: Array<any>
}

type IPaymentType = {
build: () => PaymentType
publish: () => PaymentType
sign: (pw: string) => PaymentType
to: (address: string, addressType?: FromType) => PaymentType
value: () => PaymentValue
}

type BchPaymentType = IPaymentType & {
amount: (n: number) => BchPaymentType
coin: 'BCH'
}

type BtcPaymentType = IPaymentType & {
amount: (n: number) => BtcPaymentType
coin: 'BTC'
}

type EthPaymentType = IPaymentType & {
amount: (n: string) => EthPaymentType
coin: 'ETH' | 'PAX'
}

type XlmPaymentType = IPaymentType & {
amount: (n: number) => XlmPaymentType
coin: 'XLM'
}

export type PaymentType =
| BchPaymentType
| BtcPaymentType
| EthPaymentType
| XlmPaymentType
2 changes: 2 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/payment/xlm/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export default ({ api }) => {

function create ({ payment } = { payment: {} }) {
const makePayment = p => ({
coin: 'XLM',

value () {
return p
},
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-wallet-v4/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type BtcAccountType = {

export type AccountTypes = BtcAccountType

export * from '../redux/payment/types'
export * from '../redux/walletOptions/types'
export * from '../network/api/borrow/types'
export * from '../network/types'
Expand Down

0 comments on commit 7af20ea

Please sign in to comment.