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

Implement multiwallet #1151

Open
wants to merge 188 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
a3a1821
refactoring usewallet for multiwallets
babkenmes Jul 2, 2024
8e603d5
Merge branch 'dev' into dev-mutiwallet
arentant Jul 15, 2024
8ce15ce
multiwallet alpha state
arentant Jul 15, 2024
d569d25
some refactorings
arentant Jul 19, 2024
0fdd1a6
Merge branch 'dev' into dev-mutiwallet
arentant Jul 19, 2024
fa3246c
fix major issues
arentant Aug 6, 2024
3412865
Merge branch 'dev' into dev-mutiwallet
arentant Aug 8, 2024
711a6a9
Get rid of rainbow kit
arentant Aug 9, 2024
197c9d7
Custom qr uri
arentant Aug 12, 2024
86f4471
providers fixes
arentant Aug 12, 2024
aed020d
Merge branch 'dev' into dev-mutiwallet
arentant Aug 12, 2024
ced9182
Merge branch 'dev-mutiwallet' into dev-multiwallet-removeRainbowkit
arentant Aug 12, 2024
ae10427
global multiwallet ui and functionality improvements
arentant Aug 13, 2024
a583724
refactor
arentant Aug 20, 2024
fc25ec2
Merge remote-tracking branch 'origin/dev-multiwallet-removeRainbowkit…
babkenmes Aug 20, 2024
e1fa349
Merge branch 'dev' into dev-multiwallet-removeRainbowkit
arentant Aug 27, 2024
4efa9cf
update yarn lock
arentant Aug 27, 2024
1e6b382
fix dumb issue
arentant Aug 27, 2024
fad0538
changes
arentant Aug 30, 2024
0de6b03
add wallet icon to qr
arentant Aug 30, 2024
623d0ee
sesr
babkenmes Sep 2, 2024
b3667f2
changes
arentant Sep 4, 2024
98bb502
some fixes
arentant Sep 4, 2024
62efdb7
Merge branch 'dev' into dev-multiwallet-removeRainbowkit
arentant Sep 5, 2024
ca91cfb
little fixes
arentant Sep 5, 2024
d8a0319
Merge branch 'dev' into dev-mutiwallet
arentant Sep 6, 2024
4261e41
some fixes
arentant Sep 6, 2024
31b66f6
Refactor Swap/Form component and remove unused code
arentant Sep 6, 2024
e91b366
Refactor Swap/Form component and remove unused code
arentant Sep 6, 2024
2ac7e95
Refactor Bitget icon component and fix clipPath attribute
arentant Sep 6, 2024
901fdd5
Merge branch 'dev' into dev-multiwallet-form
babkenmes Sep 10, 2024
71145dc
merge
babkenmes Sep 10, 2024
5d2c2cd
Merge branch 'dev-multiwallet-removeRainbowkit' into dev-multiwallet-…
babkenmes Sep 10, 2024
6414dbf
Merged dev
babkenmes Sep 13, 2024
a854275
asd
babkenmes Sep 13, 2024
8e64201
Merge branch 'dev' into dev-multiwallet-form
babkenmes Sep 16, 2024
d2f5c46
asdasd
babkenmes Sep 16, 2024
9474b44
Merge branch 'dev' into dev-multiwallet-form
babkenmes Sep 19, 2024
ac43039
Refactor ConnectButton component to use new wallet modal state
arentant Sep 19, 2024
78f70ba
Fixed buil errors
babkenmes Sep 19, 2024
b0ef77c
Merge branch 'dev' into dev-multiwallet-form
arentant Sep 19, 2024
81e62e8
Basic implementation
babkenmes Sep 23, 2024
e26faa2
Fixed initial deposit method value
babkenmes Sep 23, 2024
fef507d
Fixed balance & swapper
babkenmes Sep 23, 2024
31d1bd6
position
babkenmes Sep 23, 2024
adb4f1c
Fixed source addres for create swap
babkenmes Sep 23, 2024
e963fc6
Added wallet accounts to source and destination pickers
babkenmes Sep 24, 2024
06cb764
Fixed walle data issues
babkenmes Sep 24, 2024
90d9c75
Filter right metamask connector and add rkDetails
babkenmes Sep 30, 2024
c0cb099
Fixed some connectors
babkenmes Sep 30, 2024
56a92f4
Implemented final muktiwallet
babkenmes Oct 9, 2024
44b94e1
Merge branch 'dev' into dev-multiwallet-form
babkenmes Oct 9, 2024
fa49356
Diconnect before connect
babkenmes Oct 9, 2024
3fe69d2
reset conenctor on error
babkenmes Oct 9, 2024
bfcef1a
Merge branch 'dev' into dev-multiwallet-form
babkenmes Oct 10, 2024
a1c7a3f
clear connector on modal close
babkenmes Oct 16, 2024
ea0eefb
Merge branch 'dev' into dev-multiwallet-form
babkenmes Oct 21, 2024
ab99409
Autofil fixes
babkenmes Oct 22, 2024
892279f
Merge branch 'dev' into dev-multiwallet-form
babkenmes Oct 22, 2024
666ef76
Withdraw by selected account
babkenmes Oct 24, 2024
2a27786
Fixed build errors
babkenmes Oct 24, 2024
8bc5979
Merge
babkenmes Oct 28, 2024
eb73576
Fixed default sourceaccount effect
babkenmes Oct 28, 2024
b858305
Implement latest design for address autofill by wallet connect
arentant Oct 28, 2024
2c8809f
Merge branch 'dev-multiwallet-form' into dev-multiwallet-form-autofil…
arentant Oct 28, 2024
4dfa2ef
Bound balance to selectedSourceAddres in currency picker
arentant Oct 28, 2024
9e58fb2
Merge pull request #1129 from layerswap/dev-multiwallet-form-autofill…
babkenmes Oct 28, 2024
89b84d6
Added balance to source wallets
babkenmes Oct 30, 2024
af0c2e6
merge new modal
arentant Oct 31, 2024
136c02a
change to new modal
arentant Oct 31, 2024
4a37169
refactor: adjust padding in SwapDetails and update WalletsList layout
arentant Oct 31, 2024
6f9106f
Merge branch 'dev-multiwallet-form' into dev-multiwallet-form-newModal
arentant Oct 31, 2024
f6e3a52
refactor: replace Modal with VaulDrawer in AddressPicker component
arentant Oct 31, 2024
729ee33
refactor: replace img with Image component in WalletsList for better …
arentant Oct 31, 2024
0551aee
refactor: replace Modal with VaulDrawer in LayerswapMenu and adjust s…
arentant Nov 4, 2024
8bb4f03
refactor: replace Modal with VaulDrawer in CommandSelect component
arentant Nov 5, 2024
f09257f
some fixes
arentant Nov 5, 2024
b750eef
Implement modal withdrawal account picker
arentant Nov 6, 2024
430f594
merge dev
arentant Nov 6, 2024
a90626d
Fixed fuel provider
babkenmes Nov 6, 2024
21a29b9
Merge pull request #1140 from layerswap/dev-multiwallet-form-devMerge
babkenmes Nov 7, 2024
df7bfc8
Merge branch 'dev-multiwallet-form' into dev-multiwallet-form-withdra…
arentant Nov 7, 2024
498db90
Merge branch 'dev-multiwallet-form' into dev-multiwallet-form-newModal
arentant Nov 7, 2024
6c74e08
fix build
arentant Nov 7, 2024
c9f9a3e
Merge branch 'dev-multiwallet-form' into dev-multiwallet-form-newModal
arentant Nov 7, 2024
0b0b42c
Merge branch 'dev-multiwallet-form' into dev-multiwallet-form-withdra…
arentant Nov 7, 2024
96a9697
Merge branch 'dev-multiwallet-form-newModal' into dev-multiwallet-for…
arentant Nov 7, 2024
07b38be
refactor: replace Modal with VaulDrawer in WalletTransferContent comp…
arentant Nov 7, 2024
62eda78
Merge pull request #1138 from layerswap/dev-multiwallet-form-withdraw…
arentant Nov 7, 2024
1c6b40f
some optimizations
arentant Nov 7, 2024
15c2d3c
Merge pull request #1131 from layerswap/dev-multiwallet-form-newModal
babkenmes Nov 8, 2024
946826c
vaul bug fix
arentant Nov 8, 2024
391a223
refactor: improve VaulDrawer usage and clean up unused code in variou…
arentant Nov 8, 2024
de1dde6
little fixes
arentant Nov 11, 2024
d0645b1
Changed wallet accounts appearance
babkenmes Nov 11, 2024
40fe735
fixed shoouldConnectWallet
babkenmes Nov 11, 2024
50f48bf
some modal fixes
arentant Nov 11, 2024
c8f2577
Updated layout of connect wallets list
babkenmes Nov 12, 2024
a91b38b
Refactor layout and styling in SwapHistory, Vaul modal, and ThemeWrap…
arentant Nov 12, 2024
eb1bbaf
Enhance Vaul modal behavior for mobile; adjust overlay rendering and …
arentant Nov 12, 2024
397afd5
Refactor Vaul modal component; simplify overlay rendering and remove …
arentant Nov 12, 2024
1f58772
Remove vaul from packages, add source code of vaul
arentant Nov 12, 2024
80140b5
Add @radix-ui/react-dialog package to dependencies
arentant Nov 12, 2024
3542752
build fix
arentant Nov 12, 2024
3b9415c
trying to fix build
arentant Nov 13, 2024
ce4b650
another try to fix build
arentant Nov 13, 2024
4fd0bf6
test
arentant Nov 13, 2024
831df3b
fix mobile modal
arentant Nov 13, 2024
a335fe7
little fixes
arentant Nov 13, 2024
12e3ea3
Revert some vaul modal replacements
arentant Nov 14, 2024
7884610
Refactor ConnectWalletLIst
arentant Nov 14, 2024
e7b1e58
Merge branch 'dev' into dev-multiwallet-form
babkenmes Nov 15, 2024
4a49a57
fixed vaulModal issue
paur94 Nov 15, 2024
7183393
removed vaul package
paur94 Nov 15, 2024
9e0ecf1
refactor: update AddressWithIcon layout and replace ChevronDown with …
arentant Nov 15, 2024
43e01ee
fix starknet connect hook
arentant Nov 18, 2024
1ce6d94
Merge branch 'dev-multiwallet-form' into dev-multiwallet-form-refacto…
arentant Nov 18, 2024
f8d5682
yarn lock update
arentant Nov 18, 2024
a95bbe6
feat: enhance wallet connection by updating icon handling and improvi…
arentant Nov 18, 2024
6e00432
refactored useIsWindowVisible hook
paur94 Nov 18, 2024
97444fc
Merge branch 'dev-multiwallet-form' into dev-multiwallet-fix-balances…
paur94 Nov 18, 2024
fe8436c
Fixed default address values
babkenmes Nov 18, 2024
780f847
Merge pull request #1149 from layerswap/dev-multiwallet-fix-balances-…
babkenmes Nov 18, 2024
4ccf553
Update WalletsList.tsx
babkenmes Nov 18, 2024
10c5b7a
refactor: update wallet icon handling and improve connector properties
arentant Nov 19, 2024
1d2f57c
Added isNotAvailable in wallets
babkenmes Nov 19, 2024
cfb1df2
Merge branch 'dev-multiwallet-form' into dev-multiwallet-form-refacto…
babkenmes Nov 19, 2024
00c76ae
Merge pull request #1148 from layerswap/dev-multiwallet-form-refactor…
babkenmes Nov 19, 2024
be09ce7
Added addresses to values swapper
babkenmes Nov 19, 2024
c17ee64
Fixing runtime error
babkenmes Nov 19, 2024
4d20285
feat: implement SVG to Base64 conversion utility and update wallet ha…
arentant Nov 19, 2024
c982aa1
fix: update wallet handling logic to conditionally display "Continue …
arentant Nov 20, 2024
036c9fa
Merge branch 'dev' into dev-multiwallet-form
arentant Nov 20, 2024
3fb9a6f
Fixed circular dependancy
babkenmes Nov 20, 2024
3e7a4f8
Final fix for circular dependancy
babkenmes Nov 20, 2024
6d9e5ba
Fixed build error
babkenmes Nov 20, 2024
8003d17
final fixes for imports
babkenmes Nov 20, 2024
ae62136
Implement solana connection layerswap ui and fix build error
arentant Nov 20, 2024
692ca3d
Implement fuel connection layerswap ui
arentant Nov 21, 2024
f1399af
wagmi
babkenmes Nov 21, 2024
70fd9f7
Fix formik submit on non swap create button click
arentant Nov 21, 2024
56989f3
little fixes
arentant Nov 21, 2024
f8277e4
initial commit
arentant Nov 25, 2024
fe20ae5
fix EVM
arentant Nov 25, 2024
ea67c3c
Merge pull request #1157 from layerswap/dev-multiwallet-form-connectC…
babkenmes Nov 25, 2024
cbcddc3
Implement async connect modal
arentant Nov 25, 2024
a3be7c1
little fixes
arentant Nov 25, 2024
2ff71be
Fxied source&destintion address compatability
babkenmes Nov 25, 2024
0f9bca2
autopick connected wallet in address component and sourceWalletPicker
arentant Nov 26, 2024
aac3cc9
revert Ton connect to open sdk modal for connect
arentant Nov 26, 2024
c2a2fbd
refactor wallet connection UI and improve Solana wallet icon handling
arentant Nov 26, 2024
e44860f
Fixed source destibnation wallets availability and interchangability
babkenmes Nov 26, 2024
f5388a2
Merge branch 'dev-multiwallet-form' into dev-multiwallet-form-asyncCo…
babkenmes Nov 26, 2024
69dda61
mini fixes
arentant Nov 26, 2024
0a0854d
Replace Connect button with SubmitButton component for improved UI co…
arentant Nov 26, 2024
4e03eb7
Merge pull request #1159 from layerswap/dev-multiwallet-form-asyncCon…
babkenmes Nov 26, 2024
dd9a7af
Fixed button types
babkenmes Nov 27, 2024
44bc4d8
Aded initial implementation of refactored balance fetching
babkenmes Nov 8, 2024
7f065a0
some improvements and fixes
arentant Nov 29, 2024
e510efa
added new xhr balances and gases
paur94 Nov 25, 2024
3254872
fixed hook call
paur94 Nov 25, 2024
baa368d
removed unnecessary isSweepless
paur94 Nov 25, 2024
d9d5b4d
minor fixes
paur94 Nov 25, 2024
ddc4136
test
paur94 Nov 29, 2024
13f553c
fix build
arentant Nov 29, 2024
120aadc
Fixed wallet modal portal state
babkenmes Nov 29, 2024
7f586e6
Enhance wallet modal functionality by adding cancel option and improv…
arentant Nov 29, 2024
31c4d58
Fixed source address
babkenmes Dec 2, 2024
dc0c564
Merge pull request #1163 from layerswap/dev-multiwallet-form-someFixes
babkenmes Dec 2, 2024
a0fb37b
Merge branch 'dev-multiwallet-form' into dev-balances-swr-rebase
babkenmes Dec 2, 2024
3f6c1be
Fixed gas wallet address
babkenmes Dec 2, 2024
c4435d0
minor changes in connected wallets
paur94 Dec 2, 2024
9e5ce14
added key for wallet mapping
paur94 Dec 2, 2024
06370a0
little fixes
arentant Dec 2, 2024
f1c7937
Fixed balance&gas calculation
babkenmes Dec 2, 2024
c5385e9
fixed build errors
babkenmes Dec 2, 2024
a2b3e78
Merge branch 'dev-multiwallet-form' into dev-balances-swr-rebase
babkenmes Dec 2, 2024
77dfd2a
Merge pull request #1167 from layerswap/dev-balances-swr-rebase
babkenmes Dec 2, 2024
d084679
Merge pull request #1168 from layerswap/dev-multiwallet-form-compatib…
babkenmes Dec 3, 2024
2b06c5d
Implement groupping in address picker
arentant Dec 3, 2024
7fd2073
Refactor wallet icon handling and update Argent wallet ID
arentant Dec 3, 2024
04a1cfb
removed overflow from ResizablePanel
paur94 Dec 3, 2024
533aaa7
added space for notCompatibleWallets
paur94 Dec 3, 2024
a0141d1
global bug fixes
arentant Dec 3, 2024
6abbda4
fix Fuel hook issue
arentant Dec 3, 2024
a5f7483
fixed solana gas issue
paur94 Dec 4, 2024
bf44cb2
Merge branch 'dev-multiwallet-form' of https://github.com/layerswap/l…
paur94 Dec 4, 2024
e2d22a0
add disconnect functionality to address picker and wallet list
arentant Dec 4, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# next.js
/.next/
/out/
next-env.d.ts

# production
/build
Expand All @@ -37,3 +38,4 @@ storybook-static/*
# Sentry Config File
.sentryclirc
.env*.local

3 changes: 1 addition & 2 deletions Models/Balance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Wallet } from "../stores/walletStore"
import { Network, Token } from "./Network"
import { Wallet } from "./WalletProvider"

export type BalanceProps = {
networkName: string,
Expand All @@ -17,7 +17,6 @@ export type GasProps = {
token: Token,
address?: `0x${string}`,
recipientAddress?: string,
isSweeplessTx?: boolean,
wallet?: Wallet
}

Expand Down
52 changes: 52 additions & 0 deletions Models/WalletProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { AccountInterface } from 'starknet';
import { StarknetWindowObject } from 'starknetkit';
import { RouteNetwork } from './Network';


export type InternalConnector = {
name: string,
id: string,
icon?: string | undefined,
order?: number,
type?: 'injected' | 'other'
}

export type Wallet = {
// TODO: might be unused and unnecessary check
isActive: boolean;
address: string | `0x${string}`;
addresses: string[];
providerName: string
icon: (props: any) => React.JSX.Element;
//TODO: this is name of the connector, should be changed to connectorId
connector?: string;
metadata?: {
starknetAccount?: AccountInterface,
wallet?: StarknetWindowObject
}
chainId?: string | number,
isLoading?: boolean,
disconnect: () => Promise<void> | undefined | void;
connect: () => Promise<Wallet | undefined>;
isNotAvailable?: boolean;
//TODO: refactor
withdrawalSupportedNetworks?: string[],
asSourceSupportedNetworks?: string[],
autofillSupportedNetworks?: string[],
}


export type WalletProvider = {
connectWallet: (props?: { chain?: string | number | undefined | null, destination?: RouteNetwork }) => Promise<Wallet | undefined>,
connectConnector?: (props?: { connector: InternalConnector }) => Promise<Wallet | undefined> | undefined
disconnectWallets: () => Promise<void> | undefined | void,
switchAccount?: (connector: Wallet, address: string) => Promise<void>
availableWalletsForConnect?: InternalConnector[],
connectedWallets: Wallet[] | undefined,
activeWallet: Wallet | undefined,
autofillSupportedNetworks?: string[],
withdrawalSupportedNetworks?: string[],
asSourceSupportedNetworks?: string[],
name: string,
id: string,
}
6 changes: 3 additions & 3 deletions components/AddressIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ type Props = {
className?: string;
}

const AddressIcon: FC<Props> = ({ address, size, className}) => {
const AddressIcon: FC<Props> = ({ address, size, className }) => {
const ref = useRef<HTMLDivElement>(null)
useEffect(() => {
if (address && ref.current) {
ref.current.innerHTML = "";
const iconElement = Jazzicon(size, parseInt(address.slice(2, 10), 16))
if(iconElement){
if (iconElement) {
iconElement.style.display = 'block'
iconElement.style.width = "100%"
iconElement.style.height = "100%"
Expand All @@ -22,6 +22,6 @@ const AddressIcon: FC<Props> = ({ address, size, className}) => {
}
}, [address, size]);

return <div className={className} ref={ref as any} />
return <div className={className} ref={ref as any} />
}
export default AddressIcon
9 changes: 3 additions & 6 deletions components/Campaigns/Details/Rewards.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { FC, useMemo } from "react"
import { FC } from "react"
import Image from 'next/image'
import BackgroundField from "../../backgroundField";
import { Clock } from "lucide-react"
Expand All @@ -19,11 +19,8 @@ type Props = {
const Rewards: FC<Props> = ({ campaign }) => {
const network = campaign?.network

const { getAutofillProvider: getProvider } = useWallet()
const provider = useMemo(() => {
return network && getProvider(network)
}, [network, getProvider])
const wallet = provider?.getConnectedWallet()
const { provider } = useWallet(network, 'autofil')
const wallet = provider?.activeWallet

const address = wallet?.address

Expand Down
10 changes: 3 additions & 7 deletions components/Campaigns/Details/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useRouter } from "next/router"
import { FC, useCallback, useMemo } from "react"
import { FC, useCallback } from "react"
import Image from 'next/image'
import { Gift } from "lucide-react"
import LayerSwapApiClient, { Campaign } from "../../../lib/layerSwapApiClient"
import useSWR from "swr"
import { ApiResponse } from "../../../Models/ApiResponse"
import { useAccount } from "wagmi"
import SubmitButton from "../../buttons/submitButton";
import WalletIcon from "../../icons/WalletIcon";
import LinkWrapper from "../../LinkWraapper";
Expand All @@ -24,16 +23,13 @@ function CampaignDetails() {
const campaign = campaignsData?.data?.find(c => c.name === camapaignName)
const network = campaign?.network

const { getAutofillProvider: getProvider } = useWallet()
const provider = useMemo(() => {
return network && getProvider(network)
}, [network, getProvider])
const { provider } = useWallet(network, 'autofil')

const handleConnect = useCallback(async () => {
await provider?.connectWallet({ chain: network?.chain_id })
}, [provider, network])

const wallet = provider?.getConnectedWallet()
const wallet = provider?.activeWallet
const isConnected = !!wallet?.address

if (isLoading) {
Expand Down
142 changes: 0 additions & 142 deletions components/ConnectedWallets.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions components/DTOs/SwapFormValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Exchange, ExchangeToken } from "../../Models/Exchange";
export type SwapFormValues = {
amount?: string;
destination_address?: string;
// source_address?: string;
fromCurrency?: RouteToken;
toCurrency?: RouteToken;
refuel?: boolean;
Expand All @@ -13,7 +12,7 @@ export type SwapFormValues = {
fromExchange?: Exchange,
toExchange?: Exchange,
currencyGroup?: ExchangeToken
depositMethod?: string,
depositMethod?: 'wallet' | 'deposit_address',
}


Expand Down
6 changes: 3 additions & 3 deletions components/FeeDetails/DepositMethod/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const DepositMethodComponent: FC = () => {
setFieldValue(name, defaultMethod?.id, true)
return
}
else {
else if (!(menuItems?.find(i => i.id === depositMethod))) {
setFieldValue(name, first, true)
return
}
Expand All @@ -74,9 +74,9 @@ const DepositMethodComponent: FC = () => {
return null

return (
<div className="relative w-full mb-1.5">
<div className="relative w-full mb-1">
<Popover open={showModal} onOpenChange={setShowModal}>
<PopoverTrigger className="font-semibold text-secondary-text text-xs flex items-center space-x-1">
<PopoverTrigger className="font-semibold text-secondary-text text-xs flex items-center space-x-1 p-2">
<span> Transfer via </span> <span>{selectedMethod?.toLowerCase()}</span> <motion.div
animate={showModal ? "open" : "closed"}
variants={variants}
Expand Down
15 changes: 3 additions & 12 deletions components/FeeDetails/Refuel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { useFormikContext } from "formik";
import { SwapFormValues } from "../DTOs/SwapFormValues";
import { FC, useEffect, useRef } from "react";
import { Info } from "lucide-react";
import useBalance from "../../hooks/useBalance";
import { isValidAddress } from "../../lib/address/validator";
import { useBalancesState } from "../../context/balances";
import ResizablePanel from "../ResizablePanel";
import useSWRBalance from "../../lib/newbalances/useSWRBalance";

type RefuelProps = {
onButtonClick: () => void
Expand All @@ -20,21 +19,13 @@ const RefuelToggle: FC<RefuelProps> = ({ onButtonClick }) => {
} = useFormikContext<SwapFormValues>();
const { toCurrency, to, destination_address, refuel } = values

const { fetchBalance } = useBalance()
const { balances } = useBalancesState()
const { balance } = useSWRBalance(destination_address, to)

const destinationNativeBalance = destination_address && balances[destination_address]?.find(b => (b.token === to?.token?.symbol) && (b.network === to.name))
const destinationNativeBalance = destination_address && balance?.find(b => (b.token === to?.token?.symbol) && (b.network === to.name))
const needRefuel = toCurrency && toCurrency.refuel && to && to.token && isValidAddress(destination_address, to) && destinationNativeBalance && destinationNativeBalance?.amount == 0 && !refuel
const precviouslySelectedDestination = useRef(to)

useEffect(() => {

if (toCurrency && toCurrency.refuel && to && to.token && isValidAddress(destination_address, to)) {
(async () => {
to.token && await fetchBalance(to, to.token, destination_address)
})()
}

if (to && precviouslySelectedDestination.current !== to && !!refuel) {
setFieldValue('refuel', false)
}
Expand Down
Loading
Loading