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

Fix/solana UI updates #278

Merged
merged 3 commits into from
Sep 19, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/gentle-chefs-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reservoir0x/relay-kit-ui': patch
---

Fix solana custom address prompt
6 changes: 2 additions & 4 deletions packages/ui/src/components/common/CustomAddressModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { truncateAddress } from '../../utils/truncate.js'
type Props = {
open: boolean
toToken?: Token
isSvmSwap: boolean
toAddress?: string
toChain?: RelayChain
isConnected?: boolean
Expand All @@ -36,7 +35,6 @@ type Props = {

export const CustomAddressModal: FC<Props> = ({
open,
isSvmSwap,
toAddress,
toChain,
linkedWallets,
Expand All @@ -54,7 +52,7 @@ export const CustomAddressModal: FC<Props> = ({

const isValidAddress = (input: string) => {
const ethereumRegex = /^(0x)?[0-9a-fA-F]{40}$/
if (isSvmSwap) {
if (toChain?.vmType === 'svm') {
return solanaAddressRegex.test(input)
} else {
return ethereumRegex.test(input)
Expand Down Expand Up @@ -137,7 +135,7 @@ export const CustomAddressModal: FC<Props> = ({
height: 48
}}
placeholder={
isSvmSwap
toChain?.vmType === 'svm'
? `Enter ${toChain?.displayName} address`
: 'Address or ENS'
}
Expand Down
6 changes: 2 additions & 4 deletions packages/ui/src/components/widgets/ChainWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ const ChainWidget: FC<ChainWidgetProps> = ({
supportsExternalLiquidity,
timeEstimate,
fetchingSolverConfig,
isSvmSwap,
isValidFromAddress,
isValidToAddress,
invalidateBalanceQueries,
Expand Down Expand Up @@ -195,7 +194,6 @@ const ChainWidget: FC<ChainWidgetProps> = ({
setTransactionModalOpen={setTransactionModalOpen}
addressModalOpen={addressModalOpen}
setAddressModalOpen={setAddressModalOpen}
isSvmSwap={isSvmSwap}
fromToken={fromToken}
fromChain={fromChain}
toToken={toToken}
Expand Down Expand Up @@ -436,7 +434,7 @@ const ChainWidget: FC<ChainWidgetProps> = ({
style="subtitle3"
css={{ color: 'inherit' }}
>
{isSvmSwap && !isValidToAddress
{toChain?.vmType === 'svm' && !isValidToAddress
? `Enter ${toChain?.displayName} Address`
: toDisplayName}
</Text>
Expand Down Expand Up @@ -630,7 +628,7 @@ const ChainWidget: FC<ChainWidgetProps> = ({
isSameCurrencySameRecipientSwap
}
onClick={() => {
if (isSvmSwap && !isValidToAddress) {
if (toChain?.vmType === 'svm' && !isValidToAddress) {
setAddressModalOpen(true)
} else {
setTransactionModalOpen(true)
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/src/components/widgets/SwapWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ const SwapWidget: FC<SwapWidgetProps> = ({
setTransactionModalOpen={setTransactionModalOpen}
addressModalOpen={addressModalOpen}
setAddressModalOpen={setAddressModalOpen}
isSvmSwap={isSvmSwap}
fromToken={fromToken}
fromChain={fromChain}
toToken={toToken}
Expand Down Expand Up @@ -555,7 +554,7 @@ const SwapWidget: FC<SwapWidgetProps> = ({
}}
>
<Text style="subtitle2" css={{ color: 'inherit' }}>
{isSvmSwap && !isValidToAddress
{toChain?.vmType === 'svm' && !isValidToAddress
? `Enter ${toChain?.displayName} Address`
: toDisplayName}
</Text>
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/components/widgets/SwapWidgetRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,16 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({

const invalidateBalanceQueries = useCallback(() => {
const invalidatePeriodically = (invalidateFn: () => void) => {
let maxRefreshes = 5
let maxRefreshes = 4
let refreshCount = 0
const timer = setInterval(() => {
refreshCount++
if (maxRefreshes === refreshCount) {
clearInterval(timer)
return
}
refreshCount++
invalidateFn()
}, 1000)
}, 3000)
}

queryClient.invalidateQueries({ queryKey: ['useDuneBalances'] })
Expand Down Expand Up @@ -511,7 +511,7 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
ctaCopy = `Select ${fromChain?.displayName} wallet`
} else if (multiWalletSupportEnabled && !isValidToAddress) {
ctaCopy = `Select ${toChain?.displayName} wallet`
} else if (isSvmSwap && !isValidToAddress) {
} else if (toChain?.vmType === 'svm' && !isValidToAddress) {
ctaCopy = `Enter ${toChain?.displayName} Address`
} else if (isSameCurrencySameRecipientSwap) {
ctaCopy = 'Invalid recipient'
Expand Down
3 changes: 0 additions & 3 deletions packages/ui/src/components/widgets/WidgetContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { LinkedWallet } from '../../types/index.js'
export type WidgetContainerProps = {
transactionModalOpen: boolean
addressModalOpen: boolean
isSvmSwap: boolean
toChain?: RelayChain
fromChain?: RelayChain
wallet?: AdaptedWallet
Expand Down Expand Up @@ -63,7 +62,6 @@ const WidgetContainer: FC<WidgetContainerProps> = ({
useExternalLiquidity,
timeEstimate,
recipient,
isSvmSwap,
toChain,
wallet,
linkedWallets,
Expand Down Expand Up @@ -110,7 +108,6 @@ const WidgetContainer: FC<WidgetContainerProps> = ({
<CustomAddressModal
open={addressModalOpen}
toAddress={customToAddress ?? address}
isSvmSwap={isSvmSwap}
toChain={toChain}
isConnected={wallet !== undefined || isConnected ? true : false}
linkedWallets={linkedWallets ?? []}
Expand Down