Skip to content

Commit

Permalink
refactor(borrow): always have loan and offer after checkout step
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Feb 14, 2020
1 parent c3e7f2b commit 5b0ce56
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import * as AT from './actionTypes'
import { BorrowActionTypes, BorrowMinMaxType, BorrowStepsType } from './types'
import { CoinType, LoanType, OfferType } from 'blockchain-wallet-v4/src/types'

export const addCollateral = (loan: LoanType) => ({
type: AT.ADD_COLLATERAL,
payload: {
loan
}
export const addCollateral = () => ({
type: AT.ADD_COLLATERAL
})

export const createBorrow = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Exchange } from 'blockchain-wallet-v4/src'
export const INVALID_COIN_TYPE = 'Invalid coin type'

export const NO_OFFER_EXISTS = 'NO_OFFER_EXISTS'
export const NO_LOAN_EXISTS = 'NO_LOAN_EXISTS'

export const BORROW_STEPS = {
CHECKOUT: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
fiatDisplayName,
getAmount,
getCollateralAmtRequired,
NO_LOAN_EXISTS,
NO_OFFER_EXISTS
} from './model'
import { FormAction, initialize } from 'redux-form'
Expand All @@ -31,12 +32,9 @@ export default ({
const waitForUserData = profileSagas({ api, coreSagas, networks })
.waitForUserData

const addCollateral = function * ({
payload
}: ReturnType<typeof A.addCollateral>) {
const addCollateral = function * () {
try {
yield put(actions.form.startSubmit('borrowForm'))
const { loan } = payload
const paymentR = S.getPayment(yield select())
let payment: PaymentType = coreSagas.payment.btc.create({
payment: paymentR.getOrElse(<PaymentType>{}),
Expand All @@ -46,14 +44,17 @@ export default ({
selectors.form.getFormValues('borrowForm')
)

const loan = S.getLoan(yield select())
const offer = S.getOffer(yield select())
const coin = S.getCoinType(yield select())

if (!offer) throw new Error(NO_OFFER_EXISTS)
if (!loan) throw new Error(NO_LOAN_EXISTS)

const ratesR = S.getRates(yield select())
const rates = ratesR.getOrElse({})
// TODO: Borrow use offer for displayName
const rate = rates[fiatDisplayName('PAX')].last
const rate = rates[fiatDisplayName(offer.terms.principalCcy)].last

const cryptoAmt = Number(values.additionalCollateral) / rate
const amount: string = getAmount(cryptoAmt || 0, coin)

Expand All @@ -65,7 +66,6 @@ export default ({

payment = yield payment.build()
// ask for second password

const password = yield call(promptForSecondPassword)
payment = yield payment.sign(password)
payment = yield payment.publish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BorrowForm extends Component<Props> {
}

handleSubmit = () => {
this.props.borrowActions.addCollateral(this.props.loan)
this.props.borrowActions.addCollateral()
}

render () {
Expand Down

0 comments on commit 5b0ce56

Please sign in to comment.