@@ -254,12 +226,18 @@ export default function Transfer() {
setTargetChain(_targetChain);
setSourceToken(_sourceToken);
setTargetToken(_targetToken);
- handleUrlParams({ _category, _sourceChain, _targetChain, _sourceToken, _targetToken });
+ updateUrlParams(router, searchParams, {
+ _category,
+ _sourceChain,
+ _targetChain,
+ _sourceToken,
+ _targetToken,
+ });
}}
/>
@@ -300,7 +278,7 @@ export default function Transfer() {
setBridgeCategory(_category);
setSourceToken(_sourceToken);
setTargetToken(_targetToken);
- handleUrlParams({ _category, _sourceToken, _targetToken });
+ updateUrlParams(router, searchParams, { _category, _sourceToken, _targetToken });
}}
/>
@@ -312,7 +290,7 @@ export default function Transfer() {
value={bridgeCategory}
onChange={(_category) => {
setBridgeCategory(_category);
- handleUrlParams({ _category });
+ updateUrlParams(router, searchParams, { _category });
}}
/>
diff --git a/src/components/user.tsx b/src/components/user.tsx
new file mode 100644
index 000000000..ba4746d4b
--- /dev/null
+++ b/src/components/user.tsx
@@ -0,0 +1,150 @@
+import { useApp, useTransfer } from "@/hooks";
+import { UrlSearchParamKey } from "@/types";
+import Dropdown from "@/ui/dropdown";
+import {
+ formatBalance,
+ getAvailableBridges,
+ getAvailableTargetChains,
+ getAvailableTargetTokens,
+ getChainLogoSrc,
+ getTokenLogoSrc,
+ toShortAdrress,
+} from "@/utils";
+import { useConnectModal } from "@rainbow-me/rainbowkit";
+import Image from "next/image";
+import Link from "next/link";
+import { PropsWithChildren } from "react";
+import { useAccount, useDisconnect } from "wagmi";
+import PrettyAddress from "./pretty-address";
+import AddressIdenticon from "./address-identicon";
+import { Placement } from "@floating-ui/react";
+import { useRouter, useSearchParams } from "next/navigation";
+
+interface Props {
+ placement: Placement;
+ prefixLength?: number;
+ suffixLength?: number;
+ onComplete?: () => void;
+}
+
+export default function User({ placement, prefixLength = 10, suffixLength = 8, onComplete = () => undefined }: Props) {
+ const { setBridgeCategory, setSourceChain, setTargetChain, setSourceToken, setTargetToken, updateUrlParams } =
+ useTransfer();
+ const { balances, setRecordsSearch } = useApp();
+
+ const { address } = useAccount();
+ const { disconnect } = useDisconnect();
+ const { openConnectModal } = useConnectModal();
+
+ const searchParams = useSearchParams();
+ const router = useRouter();
+
+ return address ? (
+
{toShortAdrress(address)}}
+ >
+
+
+
+ {
+ setRecordsSearch(address);
+ onComplete();
+ }}
+ className="user-dropdown-item"
+ >
+
+ History
+
+
+
+
+
+
+
+ {balances
+ .filter(({ balance }) => 0 < balance)
+ .map((balance) => (
+
+ ))}
+
+
+ ) : (
+
+ );
+}
+
+function LabelSpan({ children }: PropsWithChildren
) {
+ return {children};
+}
+
+function ChildSpan({ children }: PropsWithChildren) {
+ return {children};
+}
diff --git a/packages/apps/src/config/chains/arbitrum-goerli.ts b/src/config/chains/arbitrum-goerli.ts
similarity index 81%
rename from packages/apps/src/config/chains/arbitrum-goerli.ts
rename to src/config/chains/arbitrum-goerli.ts
index a4f76dff5..77531eeb5 100644
--- a/packages/apps/src/config/chains/arbitrum-goerli.ts
+++ b/src/config/chains/arbitrum-goerli.ts
@@ -1,32 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { arbitrumGoerli } from "viem/chains";
export const arbitrumGoerliChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.ARBITRUM_GOERLI,
+ ...arbitrumGoerli,
network: "arbitrum-goerli",
name: "Arbitrum Goerli",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://goerli-rollup.arbitrum.io/rpc"],
- },
- public: {
- http: ["https://goerli-rollup.arbitrum.io/rpc"],
- },
- },
- blockExplorers: {
- default: {
- name: "Arbiscan",
- url: "https://goerli.arbiscan.io/",
- },
- },
- testnet: true,
/**
* Custom
diff --git a/packages/apps/src/config/chains/arbitrum.ts b/src/config/chains/arbitrum.ts
similarity index 82%
rename from packages/apps/src/config/chains/arbitrum.ts
rename to src/config/chains/arbitrum.ts
index faea54a19..fa29b1aa4 100644
--- a/packages/apps/src/config/chains/arbitrum.ts
+++ b/src/config/chains/arbitrum.ts
@@ -1,31 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { arbitrum } from "viem/chains";
export const arbitrumChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.ARBITRUM,
+ ...arbitrum,
network: "arbitrum",
name: "Arbitrum One",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://arb1.arbitrum.io/rpc"],
- },
- public: {
- http: ["https://arb1.arbitrum.io/rpc"],
- },
- },
- blockExplorers: {
- default: {
- name: "Arbiscan",
- url: "https://arbiscan.io/",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/base-goerli.ts b/src/config/chains/base-goerli.ts
similarity index 55%
rename from packages/apps/src/config/chains/base-goerli.ts
rename to src/config/chains/base-goerli.ts
index 253c07644..5b95b4953 100644
--- a/packages/apps/src/config/chains/base-goerli.ts
+++ b/src/config/chains/base-goerli.ts
@@ -1,34 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { baseGoerli } from "viem/chains";
export const baseGoerliChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.BASE_GOERLI,
+ ...baseGoerli,
network: "base-goerli",
name: "Base Goerli",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://goerli.base.org"],
- webSocket: ["wss://base-goerli.publicnode.com"],
- },
- public: {
- http: ["https://goerli.base.org"],
- webSocket: ["wss://base-goerli.publicnode.com"],
- },
- },
- blockExplorers: {
- default: {
- name: "Basescan",
- url: "https://goerli.basescan.org",
- },
- },
- testnet: true,
/**
* Custom
diff --git a/packages/apps/src/config/chains/base.ts b/src/config/chains/base.ts
similarity index 56%
rename from packages/apps/src/config/chains/base.ts
rename to src/config/chains/base.ts
index 69410071b..3476d5189 100644
--- a/packages/apps/src/config/chains/base.ts
+++ b/src/config/chains/base.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { base } from "viem/chains";
export const baseChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.BASE,
+ ...base,
network: "base",
name: "Base",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://mainnet.base.org"],
- webSocket: ["wss://base.publicnode.com"],
- },
- public: {
- http: ["https://mainnet.base.org"],
- webSocket: ["wss://base.publicnode.com"],
- },
- },
- blockExplorers: {
- default: {
- name: "Basescan",
- url: "https://basescan.org",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/bsc.ts b/src/config/chains/bsc.ts
similarity index 71%
rename from packages/apps/src/config/chains/bsc.ts
rename to src/config/chains/bsc.ts
index c7f26a68a..598884fb3 100644
--- a/packages/apps/src/config/chains/bsc.ts
+++ b/src/config/chains/bsc.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { bsc } from "viem/chains";
export const bscChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.BSC,
+ ...bsc,
network: "bsc",
name: "BSC",
- nativeCurrency: {
- name: "BNB",
- symbol: "BNB",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://bsc-dataseed1.binance.org"],
- webSocket: ["wss://bsc.publicnode.com"],
- },
- public: {
- http: ["https://bsc-dataseed1.binance.org"],
- webSocket: ["wss://bsc.publicnode.com"],
- },
- },
- blockExplorers: {
- default: {
- name: "BscScan",
- url: "https://bscscan.com/",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/crab.ts b/src/config/chains/crab.ts
similarity index 92%
rename from packages/apps/src/config/chains/crab.ts
rename to src/config/chains/crab.ts
index 99f7c195d..d69ff0a55 100644
--- a/packages/apps/src/config/chains/crab.ts
+++ b/src/config/chains/crab.ts
@@ -28,6 +28,12 @@ export const crabChain: ChainConfig = {
url: "https://crab.subscan.io/",
},
},
+ contracts: {
+ multicall3: {
+ address: "0xcA11bde05977b3631167028862bE2a173976CA11",
+ blockCreated: 599936,
+ },
+ },
/**
* Custom
diff --git a/packages/apps/src/config/chains/darwinia.ts b/src/config/chains/darwinia.ts
similarity index 89%
rename from packages/apps/src/config/chains/darwinia.ts
rename to src/config/chains/darwinia.ts
index 43952a2bc..d13f8d81d 100644
--- a/packages/apps/src/config/chains/darwinia.ts
+++ b/src/config/chains/darwinia.ts
@@ -29,6 +29,12 @@ export const darwiniaChain: ChainConfig = {
url: "https://darwinia.subscan.io/",
},
},
+ contracts: {
+ multicall3: {
+ address: "0xcA11bde05977b3631167028862bE2a173976CA11",
+ blockCreated: 251739,
+ },
+ },
/**
* Custom
@@ -65,15 +71,15 @@ export const darwiniaChain: ChainConfig = {
},
],
},
- {
- decimals: 18,
- symbol: "WRING",
- name: "WRING",
- type: "erc20",
- address: "0x",
- logo: "ring.svg",
- cross: [],
- },
+ // {
+ // decimals: 18,
+ // symbol: "WRING",
+ // name: "WRING",
+ // type: "erc20",
+ // address: "0x",
+ // logo: "ring.svg",
+ // cross: [],
+ // },
{
decimals: 18,
symbol: "KTON",
diff --git a/packages/apps/src/config/chains/ethereum.ts b/src/config/chains/ethereum.ts
similarity index 69%
rename from packages/apps/src/config/chains/ethereum.ts
rename to src/config/chains/ethereum.ts
index c4cc150d0..208f1a59b 100644
--- a/packages/apps/src/config/chains/ethereum.ts
+++ b/src/config/chains/ethereum.ts
@@ -1,34 +1,14 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
import { parseUnits } from "viem";
+import { mainnet } from "viem/chains";
export const ethereumChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.ETHEREUM,
+ ...mainnet,
network: "ethereum",
name: "Ethereum",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://mainnet.infura.io/v3/5350449ccd2349afa007061e62ee1409"],
- webSocket: ["wss://mainnet.infura.io/ws/v3/5350449ccd2349afa007061e62ee1409"],
- },
- public: {
- http: ["https://mainnet.infura.io/v3/5350449ccd2349afa007061e62ee1409"],
- webSocket: ["wss://mainnet.infura.io/ws/v3/5350449ccd2349afa007061e62ee1409"],
- },
- },
- blockExplorers: {
- default: {
- name: "Etherscan",
- url: "https://etherscan.io/",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/gnosis.ts b/src/config/chains/gnosis.ts
similarity index 59%
rename from packages/apps/src/config/chains/gnosis.ts
rename to src/config/chains/gnosis.ts
index 8dd2b466e..ba7685072 100644
--- a/packages/apps/src/config/chains/gnosis.ts
+++ b/src/config/chains/gnosis.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types";
+import { ChainConfig } from "@/types";
+import { gnosis } from "viem/chains";
export const gnosisChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.GNOSIS,
+ ...gnosis,
network: "gnosis",
name: "Gnosis Chain",
- nativeCurrency: {
- name: "xDai",
- symbol: "xDai",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://rpc.gnosischain.com/"],
- webSocket: [],
- },
- public: {
- http: ["https://rpc.gnosischain.com/"],
- webSocket: [],
- },
- },
- blockExplorers: {
- default: {
- name: "GnosisScan",
- url: "https://gnosisscan.io/",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/goerli.ts b/src/config/chains/goerli.ts
similarity index 79%
rename from packages/apps/src/config/chains/goerli.ts
rename to src/config/chains/goerli.ts
index 4a3a479cd..c328f80af 100644
--- a/packages/apps/src/config/chains/goerli.ts
+++ b/src/config/chains/goerli.ts
@@ -1,34 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { goerli } from "viem/chains";
export const goerliChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.GOERLI,
+ ...goerli,
network: "goerli",
name: "Goerli",
- nativeCurrency: {
- name: "goerliETH",
- symbol: "goerliETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://goerli.infura.io/v3/5350449ccd2349afa007061e62ee1409"],
- webSocket: ["wss://goerli.infura.io/ws/v3/5350449ccd2349afa007061e62ee1409"],
- },
- public: {
- http: ["https://goerli.infura.io/v3/5350449ccd2349afa007061e62ee1409"],
- webSocket: ["wss://goerli.infura.io/ws/v3/5350449ccd2349afa007061e62ee1409"],
- },
- },
- blockExplorers: {
- default: {
- name: "Etherscan",
- url: "https://goerli.etherscan.io/",
- },
- },
- testnet: true,
/**
* Custom
diff --git a/packages/apps/src/config/chains/index.ts b/src/config/chains/index.ts
similarity index 100%
rename from packages/apps/src/config/chains/index.ts
rename to src/config/chains/index.ts
diff --git a/packages/apps/src/config/chains/linea-goerli.ts b/src/config/chains/linea-goerli.ts
similarity index 78%
rename from packages/apps/src/config/chains/linea-goerli.ts
rename to src/config/chains/linea-goerli.ts
index 03551abf0..377d485b1 100644
--- a/packages/apps/src/config/chains/linea-goerli.ts
+++ b/src/config/chains/linea-goerli.ts
@@ -1,34 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { lineaTestnet } from "viem/chains";
export const lineaGoerliChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.LINEA_GOERLI,
+ ...lineaTestnet,
network: "linea-goerli",
name: "Linea Goerli",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://rpc.goerli.linea.build"],
- webSocket: ["wss://rpc.goerli.linea.build"],
- },
- public: {
- http: ["https://rpc.goerli.linea.build"],
- webSocket: ["wss://rpc.goerli.linea.build"],
- },
- },
- blockExplorers: {
- default: {
- name: "BlockScout",
- url: "https://explorer.goerli.linea.build/",
- },
- },
- testnet: true,
/**
* Custom
diff --git a/packages/apps/src/config/chains/linea.ts b/src/config/chains/linea.ts
similarity index 60%
rename from packages/apps/src/config/chains/linea.ts
rename to src/config/chains/linea.ts
index d6e28e5b8..7a761cf3f 100644
--- a/packages/apps/src/config/chains/linea.ts
+++ b/src/config/chains/linea.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { linea } from "viem/chains";
export const lineaChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.LINEA,
+ ...linea,
network: "linea",
name: "Linea",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://rpc.linea.build"],
- webSocket: ["wss://rpc.linea.build"],
- },
- public: {
- http: ["https://rpc.linea.build"],
- webSocket: ["wss://rpc.linea.build"],
- },
- },
- blockExplorers: {
- default: {
- name: "BlockScout",
- url: "https://explorer.linea.build/",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/mantle-goerli.ts b/src/config/chains/mantle-goerli.ts
similarity index 76%
rename from packages/apps/src/config/chains/mantle-goerli.ts
rename to src/config/chains/mantle-goerli.ts
index d96a67dbc..692e21237 100644
--- a/packages/apps/src/config/chains/mantle-goerli.ts
+++ b/src/config/chains/mantle-goerli.ts
@@ -1,34 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { mantleTestnet } from "viem/chains";
export const mantleGoerliChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.MANTLE_GOERLI,
+ ...mantleTestnet,
network: "mantle-goerli",
name: "Mantle Testnet",
- nativeCurrency: {
- name: "MNT",
- symbol: "MNT",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://rpc.testnet.mantle.xyz"],
- webSocket: ["wss://rpc.testnet.mantle.xyz"],
- },
- public: {
- http: ["https://rpc.testnet.mantle.xyz"],
- webSocket: ["wss://rpc.testnet.mantle.xyz"],
- },
- },
- blockExplorers: {
- default: {
- name: "Mantle",
- url: "https://explorer.testnet.mantle.xyz/",
- },
- },
- testnet: true,
/**
* Custom
diff --git a/packages/apps/src/config/chains/mantle.ts b/src/config/chains/mantle.ts
similarity index 72%
rename from packages/apps/src/config/chains/mantle.ts
rename to src/config/chains/mantle.ts
index 70afe9ca6..267f84f14 100644
--- a/packages/apps/src/config/chains/mantle.ts
+++ b/src/config/chains/mantle.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { mantle } from "viem/chains";
export const mantleChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.MANTLE,
+ ...mantle,
network: "mantle",
name: "Mantle",
- nativeCurrency: {
- name: "MNT",
- symbol: "MNT",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://rpc.mantle.xyz"],
- webSocket: ["wss://rpc.mantle.xyz"],
- },
- public: {
- http: ["https://rpc.mantle.xyz"],
- webSocket: ["wss://rpc.mantle.xyz"],
- },
- },
- blockExplorers: {
- default: {
- name: "Mantle",
- url: "https://explorer.mantle.xyz/",
- },
- },
/**
* Custom
diff --git a/src/config/chains/mumbai.ts b/src/config/chains/mumbai.ts
new file mode 100644
index 000000000..005a063f9
--- /dev/null
+++ b/src/config/chains/mumbai.ts
@@ -0,0 +1,17 @@
+import { ChainConfig } from "@/types/chain";
+import { polygonMumbai } from "viem/chains";
+
+export const mumbaiChain: ChainConfig = {
+ /**
+ * Chain
+ */
+ ...polygonMumbai,
+ network: "mumbai",
+ name: "Mumbai",
+
+ /**
+ * Custom
+ */
+ logo: "polygon.png",
+ tokens: [],
+};
diff --git a/packages/apps/src/config/chains/optimism.ts b/src/config/chains/optimism.ts
similarity index 55%
rename from packages/apps/src/config/chains/optimism.ts
rename to src/config/chains/optimism.ts
index eccf63426..4115b474b 100644
--- a/packages/apps/src/config/chains/optimism.ts
+++ b/src/config/chains/optimism.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { optimism } from "viem/chains";
export const optimismChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.OPTIMISM,
+ ...optimism,
network: "op",
name: "OP Mainnet",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://mainnet.optimism.io"],
- webSocket: ["wss://optimism.publicnode.com"],
- },
- public: {
- http: ["https://mainnet.optimism.io"],
- webSocket: ["wss://optimism.publicnode.com"],
- },
- },
- blockExplorers: {
- default: {
- name: "Etherscan",
- url: "https://optimistic.etherscan.io/",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/pangolin.ts b/src/config/chains/pangolin.ts
similarity index 100%
rename from packages/apps/src/config/chains/pangolin.ts
rename to src/config/chains/pangolin.ts
diff --git a/packages/apps/src/config/chains/pangoro.ts b/src/config/chains/pangoro.ts
similarity index 100%
rename from packages/apps/src/config/chains/pangoro.ts
rename to src/config/chains/pangoro.ts
diff --git a/packages/apps/src/config/chains/polygon-zkevm.ts b/src/config/chains/polygon-zkevm.ts
similarity index 63%
rename from packages/apps/src/config/chains/polygon-zkevm.ts
rename to src/config/chains/polygon-zkevm.ts
index 87c79f4df..6a4e89b9a 100644
--- a/packages/apps/src/config/chains/polygon-zkevm.ts
+++ b/src/config/chains/polygon-zkevm.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types";
+import { ChainConfig } from "@/types";
+import { polygonZkEvm } from "viem/chains";
export const polygonZkEvmChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.POLYGON_ZKEVM,
+ ...polygonZkEvm,
network: "polygon-zkEvm",
name: "Polygon zkEVM",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://zkevm-rpc.com"],
- webSocket: [],
- },
- public: {
- http: ["https://zkevm-rpc.com"],
- webSocket: [],
- },
- },
- blockExplorers: {
- default: {
- name: "Polygonscan",
- url: "https://zkevm.polygonscan.com/",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/polygon.ts b/src/config/chains/polygon.ts
similarity index 64%
rename from packages/apps/src/config/chains/polygon.ts
rename to src/config/chains/polygon.ts
index cd8f1f22b..c5ebbeeb2 100644
--- a/packages/apps/src/config/chains/polygon.ts
+++ b/src/config/chains/polygon.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { polygon } from "viem/chains";
export const polygonChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.POLYGON,
+ ...polygon,
network: "polygon",
name: "Polygon PoS",
- nativeCurrency: {
- name: "MATIC",
- symbol: "MATIC",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://polygon-rpc.com/"],
- webSocket: ["wss://polygon-bor.publicnode.com"],
- },
- public: {
- http: ["https://polygon-rpc.com/"],
- webSocket: ["wss://polygon-bor.publicnode.com"],
- },
- },
- blockExplorers: {
- default: {
- name: "Polygonscan",
- url: "https://polygonscan.com/",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/scroll.ts b/src/config/chains/scroll.ts
similarity index 72%
rename from packages/apps/src/config/chains/scroll.ts
rename to src/config/chains/scroll.ts
index 5a55e6981..020f02d4e 100644
--- a/packages/apps/src/config/chains/scroll.ts
+++ b/src/config/chains/scroll.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { scroll } from "viem/chains";
export const scrollChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.SCROLL,
+ ...scroll,
network: "scroll",
name: "Scroll",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://rpc.scroll.io"],
- webSocket: [],
- },
- public: {
- http: ["https://rpc.scroll.io"],
- webSocket: [],
- },
- },
- blockExplorers: {
- default: {
- name: "Scrollscan",
- url: "https://scrollscan.com",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/chains/zksync-goerli.ts b/src/config/chains/zksync-goerli.ts
similarity index 78%
rename from packages/apps/src/config/chains/zksync-goerli.ts
rename to src/config/chains/zksync-goerli.ts
index 142d75657..ffc2f0328 100644
--- a/packages/apps/src/config/chains/zksync-goerli.ts
+++ b/src/config/chains/zksync-goerli.ts
@@ -1,34 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { zkSyncTestnet } from "viem/chains";
export const zksyncGoerliChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.ZKSYNC_GOERLI,
+ ...zkSyncTestnet,
network: "zksync-goerli",
name: "Zksync Era Testnet",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://testnet.era.zksync.dev"],
- webSocket: ["wss://testnet.era.zksync.dev/ws"],
- },
- public: {
- http: ["https://testnet.era.zksync.dev"],
- webSocket: ["wss://testnet.era.zksync.dev/ws"],
- },
- },
- blockExplorers: {
- default: {
- name: "Zksync",
- url: "https://goerli.explorer.zksync.io/",
- },
- },
- testnet: true,
/**
* Custom
diff --git a/packages/apps/src/config/chains/zksync.ts b/src/config/chains/zksync.ts
similarity index 67%
rename from packages/apps/src/config/chains/zksync.ts
rename to src/config/chains/zksync.ts
index 46a3b5537..f12dc3cf9 100644
--- a/packages/apps/src/config/chains/zksync.ts
+++ b/src/config/chains/zksync.ts
@@ -1,33 +1,13 @@
-import { ChainConfig, ChainID } from "@/types/chain";
+import { ChainConfig } from "@/types/chain";
+import { zkSync } from "viem/chains";
export const zksyncChain: ChainConfig = {
/**
* Chain
*/
- id: ChainID.ZKSYNC,
+ ...zkSync,
network: "zksync",
name: "zkSync era",
- nativeCurrency: {
- name: "ETH",
- symbol: "ETH",
- decimals: 18,
- },
- rpcUrls: {
- default: {
- http: ["https://mainnet.era.zksync.io"],
- webSocket: ["wss://mainnet.era.zksync.io/ws"],
- },
- public: {
- http: ["https://mainnet.era.zksync.io"],
- webSocket: ["wss://mainnet.era.zksync.io/ws"],
- },
- },
- blockExplorers: {
- default: {
- name: "Zksync",
- url: "https://explorer.zksync.io/",
- },
- },
/**
* Custom
diff --git a/packages/apps/src/config/constant.ts b/src/config/constant.ts
similarity index 100%
rename from packages/apps/src/config/constant.ts
rename to src/config/constant.ts
diff --git a/packages/apps/src/config/gql.ts b/src/config/gql.ts
similarity index 100%
rename from packages/apps/src/config/gql.ts
rename to src/config/gql.ts
diff --git a/packages/apps/src/config/index.ts b/src/config/index.ts
similarity index 100%
rename from packages/apps/src/config/index.ts
rename to src/config/index.ts
diff --git a/packages/apps/src/hooks/index.ts b/src/hooks/index.ts
similarity index 78%
rename from packages/apps/src/hooks/index.ts
rename to src/hooks/index.ts
index 2e3c3cdc5..e6258b077 100644
--- a/packages/apps/src/hooks/index.ts
+++ b/src/hooks/index.ts
@@ -2,3 +2,4 @@ export * from "./use-app";
export * from "./use-relayer";
export * from "./use-toggle";
export * from "./use-transfer";
+export * from "./use-balances";
diff --git a/packages/apps/src/hooks/use-app.ts b/src/hooks/use-app.ts
similarity index 100%
rename from packages/apps/src/hooks/use-app.ts
rename to src/hooks/use-app.ts
diff --git a/src/hooks/use-balances.ts b/src/hooks/use-balances.ts
new file mode 100644
index 000000000..0739055f3
--- /dev/null
+++ b/src/hooks/use-balances.ts
@@ -0,0 +1,78 @@
+"use client";
+
+import { getChainConfigs } from "@/utils";
+import { useCallback, useEffect, useState } from "react";
+import { Address, createPublicClient, getContract, http } from "viem";
+import { forkJoin, map, of, merge, mergeAll, EMPTY } from "rxjs";
+import abi from "@/abi/erc20";
+import { ChainConfig, Token } from "@/types";
+
+const chains = getChainConfigs();
+
+interface BalanceState {
+ chain: ChainConfig;
+ token: Token;
+ balance: bigint;
+}
+
+export function useBalances(address: Address | null | undefined) {
+ const [balances, setBalances] = useState([]);
+ const [loading, setLoading] = useState(false);
+
+ const updateBalances = useCallback(() => {
+ if (address) {
+ setBalances((prev) => (prev.length ? [] : prev));
+ setLoading(true);
+
+ const chainObs = chains.map((chain) => {
+ const publicClient = createPublicClient({ chain, batch: { multicall: true }, transport: http() });
+
+ const balancesObs = chain.tokens.map((token) => {
+ if (token.type === "native") {
+ return publicClient.getBalance({ address });
+ } else {
+ const contract = getContract({ address: token.address, abi, publicClient });
+ return contract.read.balanceOf([address]);
+ }
+ });
+ return balancesObs.length
+ ? forkJoin(balancesObs).pipe(
+ map((_balances) => _balances.map((balance, index) => ({ chain, token: chain.tokens[index], balance }))),
+ )
+ : of([]);
+ });
+
+ return merge(chainObs, 3)
+ .pipe(mergeAll())
+ .subscribe({
+ next: (res) => {
+ setBalances((prev) =>
+ res.reduce(
+ (acc, cur) => acc.concat(cur).sort((a, b) => a.token.symbol.localeCompare(b.token.symbol)),
+ prev,
+ ),
+ );
+ },
+ error: (err) => {
+ console.error(err);
+ setLoading(false);
+ setBalances((prev) => (prev.length ? [] : prev));
+ },
+ complete: () => {
+ setLoading(false);
+ },
+ });
+ } else {
+ setBalances((prev) => (prev.length ? [] : prev));
+ }
+
+ return EMPTY.subscribe();
+ }, [address]);
+
+ useEffect(() => {
+ const sub$$ = updateBalances();
+ return () => sub$$.unsubscribe();
+ }, [updateBalances]);
+
+ return { loading, balances, updateBalances };
+}
diff --git a/packages/apps/src/hooks/use-relayer.ts b/src/hooks/use-relayer.ts
similarity index 100%
rename from packages/apps/src/hooks/use-relayer.ts
rename to src/hooks/use-relayer.ts
diff --git a/packages/apps/src/hooks/use-toggle.ts b/src/hooks/use-toggle.ts
similarity index 100%
rename from packages/apps/src/hooks/use-toggle.ts
rename to src/hooks/use-toggle.ts
diff --git a/packages/apps/src/hooks/use-transfer.ts b/src/hooks/use-transfer.ts
similarity index 100%
rename from packages/apps/src/hooks/use-transfer.ts
rename to src/hooks/use-transfer.ts
diff --git a/src/providers/app-provider.tsx b/src/providers/app-provider.tsx
new file mode 100644
index 000000000..1a448fc53
--- /dev/null
+++ b/src/providers/app-provider.tsx
@@ -0,0 +1,41 @@
+"use client";
+
+import { useBalances } from "@/hooks";
+import { ChainConfig, Token } from "@/types";
+import { Dispatch, PropsWithChildren, SetStateAction, createContext, useState } from "react";
+import { useAccount } from "wagmi";
+
+interface AppCtx {
+ balances: { chain: ChainConfig; token: Token; balance: bigint }[];
+ recordsSearch: string;
+ setRecordsSearch: Dispatch>;
+ updateBalances: () => void;
+}
+
+const defaultValue: AppCtx = {
+ balances: [],
+ recordsSearch: "",
+ setRecordsSearch: () => undefined,
+ updateBalances: () => undefined,
+};
+
+export const AppContext = createContext(defaultValue);
+
+export default function AppProvider({ children }: PropsWithChildren) {
+ const { address } = useAccount();
+ const { balances, updateBalances } = useBalances(address);
+ const [recordsSearch, setRecordsSearch] = useState(defaultValue.recordsSearch);
+
+ return (
+
+ {children}
+
+ );
+}
diff --git a/packages/apps/src/providers/graphql-provider.tsx b/src/providers/graphql-provider.tsx
similarity index 100%
rename from packages/apps/src/providers/graphql-provider.tsx
rename to src/providers/graphql-provider.tsx
diff --git a/packages/apps/src/providers/rainbow-provider.tsx b/src/providers/rainbow-provider.tsx
similarity index 100%
rename from packages/apps/src/providers/rainbow-provider.tsx
rename to src/providers/rainbow-provider.tsx
diff --git a/packages/apps/src/providers/relayer-provider.tsx b/src/providers/relayer-provider.tsx
similarity index 100%
rename from packages/apps/src/providers/relayer-provider.tsx
rename to src/providers/relayer-provider.tsx
diff --git a/packages/apps/src/providers/transfer-provider.tsx b/src/providers/transfer-provider.tsx
similarity index 85%
rename from packages/apps/src/providers/transfer-provider.tsx
rename to src/providers/transfer-provider.tsx
index 4437aab2e..604199a63 100644
--- a/packages/apps/src/providers/transfer-provider.tsx
+++ b/src/providers/transfer-provider.tsx
@@ -25,6 +25,16 @@ import {
import { Address, TransactionReceipt } from "viem";
import { useAccount, usePublicClient, useWalletClient } from "wagmi";
import { Subscription, forkJoin } from "rxjs";
+import { ReadonlyURLSearchParams } from "next/navigation";
+import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
+
+interface UpdateUrlParamsOptions {
+ _category?: BridgeCategory | undefined;
+ _sourceChain?: ChainConfig | undefined;
+ _targetChain?: ChainConfig | undefined;
+ _sourceToken?: Token | undefined;
+ _targetToken?: Token | undefined;
+}
interface TransferCtx {
bridgeInstance: BaseBridge | undefined;
@@ -65,6 +75,11 @@ interface TransferCtx {
chain: ChainConfig,
) => Promise;
updateSourceBalance: (sender: Address, bridge: BaseBridge) => Promise;
+ updateUrlParams: (
+ router: AppRouterInstance,
+ searchParams: ReadonlyURLSearchParams,
+ options: UpdateUrlParamsOptions,
+ ) => void;
}
const { defaultBridgeCategory, defaultSourceChain, defaultTargetChain, defaultSourceToken, defaultTargetToken } =
@@ -97,6 +112,7 @@ const defaultValue: TransferCtx = {
transfer: async () => undefined,
sourceApprove: async () => undefined,
updateSourceBalance: async () => undefined,
+ updateUrlParams: () => undefined,
};
export const TransferContext = createContext(defaultValue);
@@ -180,6 +196,29 @@ export default function TransferProvider({ children }: PropsWithChildren {
+ const params = new URLSearchParams(searchParams.toString());
+ const c = _category || bridgeCategory;
+ const sc = _sourceChain || sourceChain;
+ const tc = _targetChain || targetChain;
+ const st = _sourceToken || sourceToken;
+ const tt = _targetToken || targetToken;
+
+ c && params.set(UrlSearchParamKey.BRIDGE, c);
+ sc && params.set(UrlSearchParamKey.SOURCE_CHAIN, sc.network);
+ tc && params.set(UrlSearchParamKey.TARGET_CHAIN, tc.network);
+ st && params.set(UrlSearchParamKey.SOURCE_TOKEN, st.symbol);
+ tt && params.set(UrlSearchParamKey.TARGET_TOKEN, tt.symbol);
+ router.push(`?${params.toString()}`);
+ },
+ [bridgeCategory, sourceChain, targetChain, sourceToken, targetToken],
+ );
+
useEffect(() => {
let sub$$: Subscription | undefined;
@@ -276,6 +315,7 @@ export default function TransferProvider({ children }: PropsWithChildren
{children}
diff --git a/packages/apps/src/types/bridge.ts b/src/types/bridge.ts
similarity index 100%
rename from packages/apps/src/types/bridge.ts
rename to src/types/bridge.ts
diff --git a/packages/apps/src/types/chain.ts b/src/types/chain.ts
similarity index 100%
rename from packages/apps/src/types/chain.ts
rename to src/types/chain.ts
diff --git a/packages/apps/src/types/cross-chain.ts b/src/types/cross-chain.ts
similarity index 100%
rename from packages/apps/src/types/cross-chain.ts
rename to src/types/cross-chain.ts
diff --git a/packages/apps/src/types/graphql.ts b/src/types/graphql.ts
similarity index 100%
rename from packages/apps/src/types/graphql.ts
rename to src/types/graphql.ts
diff --git a/packages/apps/src/types/index.ts b/src/types/index.ts
similarity index 100%
rename from packages/apps/src/types/index.ts
rename to src/types/index.ts
diff --git a/packages/apps/src/types/misc.ts b/src/types/misc.ts
similarity index 100%
rename from packages/apps/src/types/misc.ts
rename to src/types/misc.ts
diff --git a/packages/apps/src/types/token.ts b/src/types/token.ts
similarity index 100%
rename from packages/apps/src/types/token.ts
rename to src/types/token.ts
diff --git a/packages/apps/src/types/url.ts b/src/types/url.ts
similarity index 100%
rename from packages/apps/src/types/url.ts
rename to src/types/url.ts
diff --git a/packages/apps/src/ui/button.tsx b/src/ui/button.tsx
similarity index 85%
rename from packages/apps/src/ui/button.tsx
rename to src/ui/button.tsx
index 24e905c74..98142254e 100644
--- a/packages/apps/src/ui/button.tsx
+++ b/src/ui/button.tsx
@@ -12,8 +12,8 @@ export default forwardRef
diff --git a/packages/apps/src/ui/countdown-refresh.tsx b/src/ui/countdown-refresh.tsx
similarity index 100%
rename from packages/apps/src/ui/countdown-refresh.tsx
rename to src/ui/countdown-refresh.tsx
diff --git a/packages/apps/src/ui/drawer.tsx b/src/ui/drawer.tsx
similarity index 86%
rename from packages/apps/src/ui/drawer.tsx
rename to src/ui/drawer.tsx
index e7b2f2ed5..8b10bc3c0 100644
--- a/packages/apps/src/ui/drawer.tsx
+++ b/src/ui/drawer.tsx
@@ -40,14 +40,14 @@ export default function Drawer({
maskClosable && onClose()}
- className="bg-app-bg/80 fixed left-0 top-0 z-20 h-screen w-screen"
+ className="fixed left-0 top-0 z-20 h-screen w-screen bg-app-bg/80"
>
e.stopPropagation()}
>
-
-
+
+
diff --git a/packages/apps/src/ui/dropdown.tsx b/src/ui/dropdown.tsx
similarity index 97%
rename from packages/apps/src/ui/dropdown.tsx
rename to src/ui/dropdown.tsx
index 5c25761e7..9ff4cbc56 100644
--- a/packages/apps/src/ui/dropdown.tsx
+++ b/src/ui/dropdown.tsx
@@ -1,6 +1,7 @@
import { useToggle } from "@/hooks/use-toggle";
import {
FloatingPortal,
+ Placement,
offset,
size,
useClick,
@@ -15,6 +16,7 @@ import { PropsWithChildren, ReactElement } from "react";
interface Props {
label: ReactElement;
+ placement?: Placement;
hoverable?: boolean;
sameWidth?: boolean;
labelClassName?: string;
@@ -24,6 +26,7 @@ interface Props {
export default function Dropdown({
label,
children,
+ placement,
hoverable,
sameWidth,
labelClassName,
@@ -44,6 +47,7 @@ export default function Dropdown({
})
: undefined,
],
+ placement,
});
const { styles, isMounted } = useTransitionStyles(context, {
diff --git a/packages/apps/src/ui/input-alert.tsx b/src/ui/input-alert.tsx
similarity index 73%
rename from packages/apps/src/ui/input-alert.tsx
rename to src/ui/input-alert.tsx
index 060a364ed..0d03404bc 100644
--- a/packages/apps/src/ui/input-alert.tsx
+++ b/src/ui/input-alert.tsx
@@ -1,7 +1,7 @@
export default function InputAlert({ text }: { text: string }) {
return (
- {text}
+ {text}
);
}
diff --git a/packages/apps/src/ui/input.tsx b/src/ui/input.tsx
similarity index 100%
rename from packages/apps/src/ui/input.tsx
rename to src/ui/input.tsx
diff --git a/packages/apps/src/ui/label.tsx b/src/ui/label.tsx
similarity index 84%
rename from packages/apps/src/ui/label.tsx
rename to src/ui/label.tsx
index 78601d287..b7018ad13 100644
--- a/packages/apps/src/ui/label.tsx
+++ b/src/ui/label.tsx
@@ -12,9 +12,9 @@ interface Props {
export default function Label({ text, tips, extra, children, className, needAbsolute }: PropsWithChildren
) {
return (
-
+
-
+
{text}
{tips ? (
diff --git a/packages/apps/src/ui/modal.tsx b/src/ui/modal.tsx
similarity index 87%
rename from packages/apps/src/ui/modal.tsx
rename to src/ui/modal.tsx
index d7f67f508..54029692f 100644
--- a/packages/apps/src/ui/modal.tsx
+++ b/src/ui/modal.tsx
@@ -64,11 +64,11 @@ export default function Modal({
maskClosable && onClose()}
- className="p-middle bg-app-bg/80 fixed left-0 top-0 z-20 flex h-screen w-screen items-center justify-center"
+ className="fixed left-0 top-0 z-20 flex h-screen w-screen items-center justify-center bg-app-bg/80 p-middle"
>
{/* modal */}
e.stopPropagation()}
>
{/* close icon */}
@@ -80,7 +80,7 @@ export default function Modal({
{/* header */}
-
+
{title}
{subTitle ? (
typeof subTitle === "string" ? (
@@ -99,7 +99,7 @@ export default function Modal({
{/* footer */}
{forceFooterHidden ? null : onCancel || onOk ? (
<>
-
+
@@ -110,7 +110,7 @@ export default function Modal({
kind="default"
onClick={onCancel}
disabled={disabledCancel}
- className="rounded-middle h-9 flex-1 text-base font-normal"
+ className="h-9 flex-1 rounded-middle text-base font-normal"
>
{cancelText || "Cancel"}
@@ -121,7 +121,7 @@ export default function Modal({
onClick={onOk}
disabled={disabledOk}
busy={busy}
- className="rounded-middle h-9 flex-1 text-base font-normal"
+ className="h-9 flex-1 rounded-middle text-base font-normal"
>
{okText || "Ok"}
diff --git a/packages/apps/src/ui/notification.tsx b/src/ui/notification.tsx
similarity index 98%
rename from packages/apps/src/ui/notification.tsx
rename to src/ui/notification.tsx
index 00e03926e..5755d0eab 100644
--- a/packages/apps/src/ui/notification.tsx
+++ b/src/ui/notification.tsx
@@ -41,7 +41,7 @@ const createItem = (config: Config, status: Status, onClose: () => void) => {
src={`/images/notification/${status}.svg`}
className="hidden shrink-0 self-start lg:inline"
/>
-
+
{config.title &&
{config.title}
}
{config.description &&
{config.description}
}
diff --git a/packages/apps/src/ui/page-wrap.tsx b/src/ui/page-wrap.tsx
similarity index 100%
rename from packages/apps/src/ui/page-wrap.tsx
rename to src/ui/page-wrap.tsx
diff --git a/packages/apps/src/ui/pagination.tsx b/src/ui/pagination.tsx
similarity index 91%
rename from packages/apps/src/ui/pagination.tsx
rename to src/ui/pagination.tsx
index 4bef6f957..04c46bbfe 100644
--- a/packages/apps/src/ui/pagination.tsx
+++ b/src/ui/pagination.tsx
@@ -12,7 +12,7 @@ export default function Pagination({ total, currentPage, pageSize = 10, onChange
return (
totalPages > 1 && (
-
+
onChange(currentPage - 1)} />
{createPageOptions(totalPages, currentPage, onChange)}
onChange(currentPage + 1)} />
@@ -34,9 +34,9 @@ function PageButton({
}) {
return (