Skip to content

Commit

Permalink
feat(swap-2.x): refresh swap accounts in init swap
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Oct 28, 2020
1 parent 159beab commit adbeb07
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,6 @@ export default ({
api.getSBBalances,
currency
)
// const locks: ReturnType<typeof api.getWithdrawalLocks> = yield call(
// api.getWithdrawalLocks
// )
// eslint-disable-next-line
// console.log(locks)
yield put(A.fetchSBBalancesSuccess(balances))
} catch (e) {
const error = errorHandler(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const FETCH_TRADES_SUCCESS = '@EVENT.FETCH_SWAP_TRADES_SUCCESS'

export const INIT_AMOUNT_FORM = '@EVENT.INIT_SWAP_AMOUNT_FORM'

export const REFRESH_ACCOUNTS = '@EVENT.REFRESH_SWAP_ACCOUNTS'

export const SET_STEP = '@EVENT.SET_SWAP_STEP'

export const SHOW_MODAL = '@EVENT.SHOW_SWAP_MODAL'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export const initAmountForm = () => ({
type: AT.INIT_AMOUNT_FORM
})

export const refreshAccounts = () => ({
type: AT.REFRESH_ACCOUNTS
})

export const setStep = ({ step, options }: SwapStepPayload) => ({
type: AT.SET_STEP,
payload: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default ({ api, coreSagas, networks }) => {
yield takeLatest(AT.FETCH_LIMITS, swapSagas.fetchLimits)
yield takeLatest(AT.FETCH_TRADES, swapSagas.fetchTrades)
yield takeLatest(AT.INIT_AMOUNT_FORM, swapSagas.initAmountForm)
yield takeLatest(AT.REFRESH_ACCOUNTS, swapSagas.refreshAccounts)
yield takeLatest(AT.SHOW_MODAL, swapSagas.showModal)
yield takeLatest(AT.TOGGLE_BASE_COUNTER, swapSagas.toggleBaseAndCounter)
yield takeEvery(actionTypes.CHANGE, swapSagas.formChanged)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,31 @@ export default ({
}
}

const refreshAccounts = function * () {
const initSwapFormValues = selectors.form.getFormValues('initSwap')(
yield select()
) as InitSwapFormValuesType

if (
!initSwapFormValues ||
!initSwapFormValues.BASE ||
!initSwapFormValues.COUNTER
) {
return
}

const accounts = S.getActiveAccounts(yield select())
const baseAccount = accounts[initSwapFormValues.BASE.coin].find(
val => val.label === initSwapFormValues.BASE?.label
)
const counterAccount = accounts[initSwapFormValues.COUNTER.coin].find(
val => val.label === initSwapFormValues.COUNTER?.label
)

yield put(actions.form.change('initSwap', 'BASE', baseAccount))
yield put(actions.form.change('initSwap', 'COUNTER', counterAccount))
}

const showModal = function * ({ payload }: ReturnType<typeof A.showModal>) {
const invitations = selectors.core.settings
.getInvitations(yield select())
Expand Down Expand Up @@ -398,6 +423,7 @@ export default ({
fetchTrades,
formChanged,
initAmountForm,
refreshAccounts,
showModal,
toggleBaseAndCounter
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import VerifyIdentity from './VerifyIdentity'
class InitSwapForm extends PureComponent<InjectedFormProps<{}, Props> & Props> {
state = {}

componentDidMount () {
this.props.swapActions.refreshAccounts()
}

handleSubmit = e => {
e.preventDefault()
this.props.swapActions.setStep({ step: 'ENTER_AMOUNT' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class PreviewSwap extends PureComponent<InjectedFormProps<{}, Props> & Props> {
!this.props.initSwapFormValues?.BASE ||
!this.props.initSwapFormValues?.COUNTER
) {
return this.props.swapActions.setStep({ step: 'INIT_SWAP' })
this.props.swapActions.setStep({ step: 'INIT_SWAP' })
return null
}

const { BASE, COUNTER } = this.props.initSwapFormValues
Expand Down

0 comments on commit adbeb07

Please sign in to comment.