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),