From 1c928e937c112c0825c531136346f327d24bfd21 Mon Sep 17 00:00:00 2001 From: William Swanson Date: Tue, 4 Jan 2022 15:27:19 -0800 Subject: [PATCH] wip --- src/swap-helpers.js | 16 ++++++++++++++++ src/swap/sideshift.js | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/swap-helpers.js b/src/swap-helpers.js index c6045202..cafa25db 100644 --- a/src/swap-helpers.js +++ b/src/swap-helpers.js @@ -161,3 +161,19 @@ export function safeCurrencyCodes( return out } + +/** + * Turn a max quote into a "from" quote. + */ +export function handleMax(request: EdgeSwapRequest): EdgeSwapRequest { + if (request.quoteFor !== 'max') return request + + const maxAmount = request.fromWallet.getMaxSpendable({ + /* ... */ + }) + return { + ...request, + nativeAmount: maxAmount, + quoteFor: 'from' + } +} diff --git a/src/swap/sideshift.js b/src/swap/sideshift.js index 779ff9ea..f9589235 100644 --- a/src/swap/sideshift.js +++ b/src/swap/sideshift.js @@ -27,6 +27,7 @@ import { type InvalidCurrencyCodes, checkInvalidCodes, ensureInFuture, + handleMax, makeSwapPluginQuote, safeCurrencyCodes } from '../swap-helpers.js' @@ -149,6 +150,7 @@ const createFetchSwapQuote = (api: SideshiftApi, affiliateId: string) => request: EdgeSwapRequest ): Promise { checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo) + request = handleMax(request) const [depositAddress, settleAddress] = await Promise.all([ getAddress(request.fromWallet, request.fromCurrencyCode),