Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sell): add FF to fallback to payment address for nc sell #5926

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/mocks/wallet-options-v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"themeEnabled": true,
"unifiedAccountLogin": true,
"useAgentHotWalletAddress": true,
"useAgentHotWalletAddressForSell": false,
"useLoqateService": true,
"useNewPaymentProviders": true,
"useVgsProvider": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
selectors.form.getFormValues(FORM_BS_CHECKOUT)
)
try {
const useAgentHotWalletAddressForSell = selectors.core.walletOptions
.getUseAgentHotWalletAddressForSell(yield select())
.getOrElse(true)

const pair = S.getBSPair(yield select())

if (!pair) throw new Error(BS_ERROR.NO_PAIR_SELECTED)
Expand Down Expand Up @@ -367,6 +371,7 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
direction === 'FROM_USERKEY'
? yield call(selectReceiveAddress, from, networks, api, coreSagas)
: undefined

const sellOrder: SwapOrderType = yield call(
api.createSwapOrder,
direction,
Expand All @@ -376,13 +381,23 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
undefined,
refundAddr
)
const paymentAccount: ReturnType<typeof api.getPaymentAccount> = yield call(
api.getPaymentAccount,
coin
)
// Should generally use sellOrder deposit address, have this just in case
// we need to fall back to paymentAccount address
const sellOrderDepositAddress: string = useAgentHotWalletAddressForSell
? paymentAccount.agent.address || paymentAccount.address
: sellOrder.kind.depositAddress

// on chain
if (direction === 'FROM_USERKEY') {
const paymentR = S.getPayment(yield select())
// @ts-ignore
const payment = paymentGetOrElse(from.coin, paymentR)
try {
yield call(buildAndPublishPayment, payment.coin, payment, sellOrder.kind.depositAddress)
yield call(buildAndPublishPayment, payment.coin, payment, sellOrderDepositAddress)
yield call(api.updateSwapOrder, sellOrder.id, 'DEPOSIT_SENT')
} catch (e) {
yield call(api.updateSwapOrder, sellOrder.id, 'CANCEL')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,7 @@ export const getShowProveFlow = (state: RootState) =>
// which deposit address to use for swap
export const getUseAgentHotWalletAddress = (state: RootState) =>
getWebOptions(state).map(path(['featureFlags', 'useAgentHotWalletAddress']))

// which deposit address to use for non custodial sell
export const getUseAgentHotWalletAddressForSell = (state: RootState) =>
getWebOptions(state).map(path(['featureFlags', 'useAgentHotWalletAddressForSell']))