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

Dev-default-currencies #1133

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
27 changes: 21 additions & 6 deletions components/Input/CurrencyFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFormikContext } from "formik";
import { FC, useCallback, useEffect, useMemo, useState } from "react";
import { Dispatch, FC, SetStateAction, useCallback, useEffect, useMemo, useState } from "react";
import { SwapDirection, SwapFormValues } from "../DTOs/SwapFormValues";
import { SelectMenuItem } from "../Select/Shared/Props/selectMenuItem";
import PopoverSelectWrapper from "../Select/Popover/PopoverSelectWrapper";
Expand Down Expand Up @@ -31,6 +31,8 @@ const CurrencyFormField: FC<{ direction: SwapDirection }> = ({ direction }) => {
setFieldValue,
} = useFormikContext<SwapFormValues>();

const [currencyIsSetManually, setCurrencyIsSetManually] = useState(false)

const { to, fromCurrency, toCurrency, from, currencyGroup, destination_address } = values
const name = direction === 'from' ? 'fromCurrency' : 'toCurrency';
const query = useQueryState()
Expand Down Expand Up @@ -94,7 +96,6 @@ const CurrencyFormField: FC<{ direction: SwapDirection }> = ({ direction }) => {
}
}, [to, query, routes])


useEffect(() => {
if (direction !== "from") return

Expand Down Expand Up @@ -127,8 +128,15 @@ const CurrencyFormField: FC<{ direction: SwapDirection }> = ({ direction }) => {
if (name === "toCurrency" && toCurrency && !isLoading && routes) {
const value = routes.data?.find(r => r.name === to?.name)?.tokens?.find(r => r.symbol === toCurrency?.symbol)
if (!value) return

setFieldValue(name, value)

if (!currencyIsSetManually && (value?.status !== "active" || error?.code === LSAPIKnownErrorCode.ROUTE_NOT_FOUND_ERROR)) {
const default_currency = currencyMenuItems?.find(c => c.baseObject?.status === "active")
if (default_currency) {
setFieldValue(name, default_currency.baseObject, true)
}
} else {
setFieldValue(name, value)
}
}
}, [fromCurrency, currencyGroup, name, to, routes, error, isLoading])

Expand All @@ -137,7 +145,14 @@ const CurrencyFormField: FC<{ direction: SwapDirection }> = ({ direction }) => {
const value = routes.data?.find(r => r.name === from?.name)?.tokens?.find(r => r.symbol === fromCurrency?.symbol)
if (!value) return

setFieldValue(name, value)
if (!currencyIsSetManually && (value?.status !== "active" || error?.code === LSAPIKnownErrorCode.ROUTE_NOT_FOUND_ERROR)) {
const default_currency = currencyMenuItems?.find(c => c.baseObject?.status === "active")
if (default_currency) {
setFieldValue(name, default_currency.baseObject, true)
}
} else {
setFieldValue(name, value)
}
}
}, [toCurrency, currencyGroup, name, from, routes, error, isLoading])

Expand All @@ -158,9 +173,9 @@ const CurrencyFormField: FC<{ direction: SwapDirection }> = ({ direction }) => {
}
}, [network, token])


const handleSelect = useCallback((item: SelectMenuItem<RouteToken>) => {
setFieldValue(name, item.baseObject, true)
setCurrencyIsSetManually(true)
}, [name, direction, toCurrency, fromCurrency, from, to])

const isLocked = direction === 'from' ? query?.lockFromAsset
Expand Down
2 changes: 1 addition & 1 deletion components/Select/Popover/PopoverSelectWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function PopoverSelectWrapper<T>({
const handleSelect = useCallback((item: SelectMenuItem<T>) => {
setValue(item)
setShowModal(false)
}, [])
}, [setValue])

if (!values) return <Placeholder placeholder={placeholder} />

Expand Down
2 changes: 1 addition & 1 deletion components/Swap/Withdraw/Wallet/SolanaWalletWithdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const SolanaWalletWithdrawStep: FC<WithdrawPageProps> = ({ network, callData, sw

if (!wallet) {
return <ConnectWalletButton />
}
}

return (
<div className="w-full space-y-5 flex flex-col justify-between h-full text-primary-text">
Expand Down
4 changes: 2 additions & 2 deletions context/validationErrorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ export const ValidationProvider: React.FC<{ children: ReactNode }> = ({ children
}
}
else if (currencyGroup?.status === 'not_found' || toCurrency?.status === 'not_found' || fromCurrency?.status === 'not_found') {

validationMessage = 'Please change one of the selected tokens';
validationDetails = { title: 'Route Unavailable', type: 'warning', icon: <RouteOff stroke='#f8974b' className='w-4 h-4 ' /> };
}

return (
<ValidationContext.Provider
value={{ validationMessage, validationDetails }}
value={{ validationMessage: '', validationDetails: {} }}
>
{children}
</ValidationContext.Provider>
Expand Down
Loading