Commit b44ae1a2 authored by Noah Zinsmeister's avatar Noah Zinsmeister

clean up parseCurrencyFromURLParameter

parent 418dcf0c
......@@ -25,8 +25,8 @@ describe('hooks', () => {
expect(
queryParametersToSwapState(parse('?outputCurrency=invalid', { parseArrays: false, ignoreQueryPrefix: true }))
).toEqual({
[Field.INPUT]: { currencyId: '' },
[Field.OUTPUT]: { currencyId: 'ETH' },
[Field.INPUT]: { currencyId: 'ETH' },
[Field.OUTPUT]: { currencyId: '' },
typedValue: '',
independentField: Field.INPUT,
recipient: null,
......
......@@ -217,9 +217,8 @@ function parseCurrencyFromURLParameter(urlParam: any): string {
const valid = isAddress(urlParam)
if (valid) return valid
if (urlParam.toUpperCase() === 'ETH') return 'ETH'
if (valid === false) return 'ETH'
}
return 'ETH' ?? ''
return ''
}
function parseTokenAmountURLParameter(urlParam: any): string {
......@@ -244,13 +243,13 @@ function validatedRecipient(recipient: any): string | null {
export function queryParametersToSwapState(parsedQs: ParsedQs): SwapState {
let inputCurrency = parseCurrencyFromURLParameter(parsedQs.inputCurrency)
let outputCurrency = parseCurrencyFromURLParameter(parsedQs.outputCurrency)
if (inputCurrency === outputCurrency) {
if (typeof parsedQs.outputCurrency === 'string') {
inputCurrency = ''
} else {
if (inputCurrency === '' && outputCurrency === '') {
// default to ETH input
inputCurrency = 'ETH'
} else if (inputCurrency === outputCurrency) {
// clear output if identical
outputCurrency = ''
}
}
const recipient = validatedRecipient(parsedQs.recipient)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment