Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed Jan 4, 2022
1 parent f89d965 commit 1c928e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/swap-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
2 changes: 2 additions & 0 deletions src/swap/sideshift.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
type InvalidCurrencyCodes,
checkInvalidCodes,
ensureInFuture,
handleMax,
makeSwapPluginQuote,
safeCurrencyCodes
} from '../swap-helpers.js'
Expand Down Expand Up @@ -149,6 +150,7 @@ const createFetchSwapQuote = (api: SideshiftApi, affiliateId: string) =>
request: EdgeSwapRequest
): Promise<EdgeSwapQuote> {
checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
request = handleMax(request)

const [depositAddress, settleAddress] = await Promise.all([
getAddress(request.fromWallet, request.fromCurrencyCode),
Expand Down

0 comments on commit 1c928e9

Please sign in to comment.