@aurora-is-near/intents-swap-widget 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -5,7 +5,7 @@ export type WipgetConfig = {
5
5
  appName: string;
6
6
  appIcon: string;
7
7
  topScreenOffset: string;
8
- intentsAccountType: 'evm' | 'near';
8
+ intentsAccountType: 'evm' | 'near' | 'sol';
9
9
  walletSupportedChains: ReadonlyArray<Chains>;
10
10
  walletAddress: string | undefined | null;
11
11
  defaultMaxSlippage: number;
@@ -28,7 +28,7 @@ export declare const useConfig: () => {
28
28
  readonly appName: string;
29
29
  readonly appIcon: string;
30
30
  readonly topScreenOffset: string;
31
- readonly intentsAccountType: "evm" | "near";
31
+ readonly intentsAccountType: "evm" | "near" | "sol";
32
32
  readonly walletSupportedChains: ReadonlyArray<Chains>;
33
33
  readonly walletAddress: string | undefined | null;
34
34
  readonly defaultMaxSlippage: number;
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../src/config.tsx"],"sourcesContent":["import { deepClone } from 'valtio/utils';\nimport { proxy, useSnapshot } from 'valtio';\nimport { createContext, useContext, useEffect } from 'react';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport type { PropsWithChildren } from 'react';\n\nimport { EVM_CHAINS } from '@/constants/chains';\nimport { useAddClassToPortal } from '@/hooks/useAddClassToPortal';\nimport type { Chain, Chains, DefaultChainsFilter } from '@/types/chain';\nimport type { Token } from '@/types/token';\n\nexport type WipgetConfig = {\n // Application metadata\n appName: string;\n appIcon: string;\n\n // Layout and UI\n topScreenOffset: string;\n\n // Connected wallet\n intentsAccountType: 'evm' | 'near';\n walletSupportedChains: ReadonlyArray<Chains>;\n walletAddress: string | undefined | null;\n\n // Quotes & Transfers\n defaultMaxSlippage: number;\n\n // Chains & Tokens filtering\n showIntentTokens: boolean;\n filterTokens: (token: Token) => boolean;\n filterChains: (chain: Chain) => boolean;\n\n chainsFilter: {\n source: DefaultChainsFilter;\n target: DefaultChainsFilter;\n };\n};\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 2000 * 60,\n },\n },\n});\n\nexport const defaultConfig: WipgetConfig = {\n appName: 'Unknown',\n appIcon:\n 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/unknown.svg',\n\n // 74px - height of the header\n // 10vh - desired offset from the top of the screen\n topScreenOffset: '10vh + 74px',\n defaultMaxSlippage: 0.01,\n\n intentsAccountType: 'evm',\n walletSupportedChains: EVM_CHAINS,\n walletAddress: undefined,\n\n filterChains: () => true,\n filterTokens: () => true,\n showIntentTokens: true,\n chainsFilter: {\n source: { external: 'wallet-supported', intents: 'with-balance' },\n target: { external: 'all', intents: 'all' },\n },\n};\n\ntype WipgetConfigContextType = WipgetConfig;\n\nconst WipgetConfigContext =\n createContext<WipgetConfigContextType>(defaultConfig);\n\ntype Props = PropsWithChildren<{ config?: WipgetConfig }>;\n\nexport const configStore = proxy<{ config: WipgetConfig }>({\n config: defaultConfig,\n});\n\nexport const useConfig = () => {\n const configState = useContext(WipgetConfigContext);\n const config = useSnapshot(configState);\n\n return config;\n};\n\nexport const WipgetConfigProvider = ({\n children,\n config: userConfig = defaultConfig,\n}: Props) => {\n useEffect(() => {\n configStore.config = deepClone(userConfig);\n }, [userConfig]);\n\n // add tailwind parent class to portal root\n useAddClassToPortal('headlessui-portal-root', 'sw');\n\n return (\n <QueryClientProvider client={queryClient}>\n <WipgetConfigContext.Provider value={configStore.config}>\n <div className=\"sw\">{children}</div>\n </WipgetConfigContext.Provider>\n </QueryClientProvider>\n );\n};\n"],"names":["queryClient","QueryClient","defaultConfig","EVM_CHAINS","WipgetConfigContext","createContext","configStore","proxy","useConfig","configState","useContext","useSnapshot","WipgetConfigProvider","children","userConfig","useEffect","deepClone","useAddClassToPortal","QueryClientProvider","jsx"],"mappings":";;;;;;;AAsCA,MAAMA,IAAc,IAAIC,EAAY;AAAA,EAClC,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,WAAW,MAAO;AAAA,IAAA;AAAA,EACpB;AAEJ,CAAC,GAEYC,IAA8B;AAAA,EACzC,SAAS;AAAA,EACT,SACE;AAAA;AAAA;AAAA,EAIF,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EAEpB,oBAAoB;AAAA,EACpB,uBAAuBC;AAAA,EACvB,eAAe;AAAA,EAEf,cAAc,MAAM;AAAA,EACpB,cAAc,MAAM;AAAA,EACpB,kBAAkB;AAAA,EAClB,cAAc;AAAA,IACZ,QAAQ,EAAE,UAAU,oBAAoB,SAAS,eAAA;AAAA,IACjD,QAAQ,EAAE,UAAU,OAAO,SAAS,MAAA;AAAA,EAAM;AAE9C,GAIMC,IACJC,EAAuCH,CAAa,GAIzCI,IAAcC,EAAgC;AAAA,EACzD,QAAQL;AACV,CAAC,GAEYM,IAAY,MAAM;AAC7B,QAAMC,IAAcC,EAAWN,CAAmB;AAGlD,SAFeO,EAAYF,CAAW;AAGxC,GAEaG,IAAuB,CAAC;AAAA,EACnC,UAAAC;AAAA,EACA,QAAQC,IAAaZ;AACvB,OACEa,EAAU,MAAM;AACd,EAAAT,EAAY,SAASU,EAAUF,CAAU;AAC3C,GAAG,CAACA,CAAU,CAAC,GAGfG,EAAoB,0BAA0B,IAAI,qBAG/CC,GAAA,EAAoB,QAAQlB,GAC3B,UAAA,gBAAAmB,EAACf,EAAoB,UAApB,EAA6B,OAAOE,EAAY,QAC/C,UAAA,gBAAAa,EAAC,OAAA,EAAI,WAAU,MAAM,UAAAN,EAAA,CAAS,GAChC,GACF;"}
1
+ {"version":3,"file":"config.js","sources":["../src/config.tsx"],"sourcesContent":["import { deepClone } from 'valtio/utils';\nimport { proxy, useSnapshot } from 'valtio';\nimport { createContext, useContext, useEffect } from 'react';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport type { PropsWithChildren } from 'react';\n\nimport { EVM_CHAINS } from '@/constants/chains';\nimport { useAddClassToPortal } from '@/hooks/useAddClassToPortal';\nimport type { Chain, Chains, DefaultChainsFilter } from '@/types/chain';\nimport type { Token } from '@/types/token';\n\nexport type WipgetConfig = {\n // Application metadata\n appName: string;\n appIcon: string;\n\n // Layout and UI\n topScreenOffset: string;\n\n // Connected wallet\n intentsAccountType: 'evm' | 'near' | 'sol';\n walletSupportedChains: ReadonlyArray<Chains>;\n walletAddress: string | undefined | null;\n\n // Quotes & Transfers\n defaultMaxSlippage: number;\n\n // Chains & Tokens filtering\n showIntentTokens: boolean;\n filterTokens: (token: Token) => boolean;\n filterChains: (chain: Chain) => boolean;\n\n chainsFilter: {\n source: DefaultChainsFilter;\n target: DefaultChainsFilter;\n };\n};\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 2000 * 60,\n },\n },\n});\n\nexport const defaultConfig: WipgetConfig = {\n appName: 'Unknown',\n appIcon:\n 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/unknown.svg',\n\n // 74px - height of the header\n // 10vh - desired offset from the top of the screen\n topScreenOffset: '10vh + 74px',\n defaultMaxSlippage: 0.01,\n\n intentsAccountType: 'evm',\n walletSupportedChains: EVM_CHAINS,\n walletAddress: undefined,\n\n filterChains: () => true,\n filterTokens: () => true,\n showIntentTokens: true,\n chainsFilter: {\n source: { external: 'wallet-supported', intents: 'with-balance' },\n target: { external: 'all', intents: 'all' },\n },\n};\n\ntype WipgetConfigContextType = WipgetConfig;\n\nconst WipgetConfigContext =\n createContext<WipgetConfigContextType>(defaultConfig);\n\ntype Props = PropsWithChildren<{ config?: WipgetConfig }>;\n\nexport const configStore = proxy<{ config: WipgetConfig }>({\n config: defaultConfig,\n});\n\nexport const useConfig = () => {\n const configState = useContext(WipgetConfigContext);\n const config = useSnapshot(configState);\n\n return config;\n};\n\nexport const WipgetConfigProvider = ({\n children,\n config: userConfig = defaultConfig,\n}: Props) => {\n useEffect(() => {\n configStore.config = deepClone(userConfig);\n }, [userConfig]);\n\n // add tailwind parent class to portal root\n useAddClassToPortal('headlessui-portal-root', 'sw');\n\n return (\n <QueryClientProvider client={queryClient}>\n <WipgetConfigContext.Provider value={configStore.config}>\n <div className=\"sw\">{children}</div>\n </WipgetConfigContext.Provider>\n </QueryClientProvider>\n );\n};\n"],"names":["queryClient","QueryClient","defaultConfig","EVM_CHAINS","WipgetConfigContext","createContext","configStore","proxy","useConfig","configState","useContext","useSnapshot","WipgetConfigProvider","children","userConfig","useEffect","deepClone","useAddClassToPortal","QueryClientProvider","jsx"],"mappings":";;;;;;;AAsCA,MAAMA,IAAc,IAAIC,EAAY;AAAA,EAClC,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,WAAW,MAAO;AAAA,IAAA;AAAA,EACpB;AAEJ,CAAC,GAEYC,IAA8B;AAAA,EACzC,SAAS;AAAA,EACT,SACE;AAAA;AAAA;AAAA,EAIF,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EAEpB,oBAAoB;AAAA,EACpB,uBAAuBC;AAAA,EACvB,eAAe;AAAA,EAEf,cAAc,MAAM;AAAA,EACpB,cAAc,MAAM;AAAA,EACpB,kBAAkB;AAAA,EAClB,cAAc;AAAA,IACZ,QAAQ,EAAE,UAAU,oBAAoB,SAAS,eAAA;AAAA,IACjD,QAAQ,EAAE,UAAU,OAAO,SAAS,MAAA;AAAA,EAAM;AAE9C,GAIMC,IACJC,EAAuCH,CAAa,GAIzCI,IAAcC,EAAgC;AAAA,EACzD,QAAQL;AACV,CAAC,GAEYM,IAAY,MAAM;AAC7B,QAAMC,IAAcC,EAAWN,CAAmB;AAGlD,SAFeO,EAAYF,CAAW;AAGxC,GAEaG,IAAuB,CAAC;AAAA,EACnC,UAAAC;AAAA,EACA,QAAQC,IAAaZ;AACvB,OACEa,EAAU,MAAM;AACd,EAAAT,EAAY,SAASU,EAAUF,CAAU;AAC3C,GAAG,CAACA,CAAU,CAAC,GAGfG,EAAoB,0BAA0B,IAAI,qBAG/CC,GAAA,EAAoB,QAAQlB,GAC3B,UAAA,gBAAAmB,EAACf,EAAoB,UAApB,EAA6B,OAAOE,EAAY,QAC/C,UAAA,gBAAAa,EAAC,OAAA,EAAI,WAAU,MAAM,UAAAN,EAAA,CAAS,GAChC,GACF;"}
@@ -8,6 +8,7 @@ export declare const CHAINS: readonly ["eth", "bera", "base", "gnosis", "arb", "
8
8
  export declare const DEFAULT_CHAIN_ICON = "https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/unknown.svg";
9
9
  export declare const DRY_QUOTE_ADDRESSES: {
10
10
  readonly evm: "0x0000000000000000000000000000000000000000";
11
+ readonly sol: "11111111111111111111111111111111";
11
12
  readonly near: "system.near";
12
13
  };
13
14
  export declare const EVM_CHAIN_BASE_TOKENS: Record<EvmChains, string>;
@@ -36,6 +36,7 @@ const o = [
36
36
  "cardano"
37
37
  ], i = [...o, ...e], r = "https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/unknown.svg", n = {
38
38
  evm: "0x0000000000000000000000000000000000000000",
39
+ sol: "11111111111111111111111111111111",
39
40
  near: "system.near"
40
41
  }, b = {
41
42
  eth: "ETH",
@@ -1 +1 @@
1
- {"version":3,"file":"chains.js","sources":["../../src/constants/chains.ts"],"sourcesContent":["import type { Chain, Chains, EvmChains } from '@/types/chain';\n\nexport const EVM_CHAINS = [\n 'eth',\n 'bera',\n 'base',\n 'gnosis',\n 'arb',\n 'bsc',\n 'avax',\n 'op',\n 'pol',\n] as const;\n\nexport const EVM_CHAIN_IDS_MAP: Record<EvmChains, number> = {\n eth: 1,\n bera: 80094,\n base: 8453,\n gnosis: 100,\n arb: 42161,\n avax: 43114,\n bsc: 56,\n op: 10,\n pol: 137,\n};\n\nexport const CHAIN_IDS_MAP: Partial<Record<Chains, number>> = {\n ...EVM_CHAIN_IDS_MAP,\n near: 397,\n};\n\nexport const EVM_CHAIN_IDS_MAP_REVERSED: Record<string, EvmChains> =\n Object.fromEntries(\n Object.entries(EVM_CHAIN_IDS_MAP).map(([chain, id]) => [`${id}`, chain]),\n ) as Record<string, EvmChains>;\n\nexport const NOT_EVM_CHAINS = [\n 'sui',\n 'xrp',\n 'btc',\n 'doge',\n 'tron',\n 'ton',\n 'near',\n 'sol',\n 'zec',\n 'cardano',\n] as const;\n\nexport const CHAINS = [...EVM_CHAINS, ...NOT_EVM_CHAINS] as const;\n\nexport const DEFAULT_CHAIN_ICON =\n 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/unknown.svg';\n\nexport const DRY_QUOTE_ADDRESSES = {\n evm: '0x0000000000000000000000000000000000000000',\n near: 'system.near',\n} as const;\n\nexport const EVM_CHAIN_BASE_TOKENS: Record<EvmChains, string> = {\n eth: 'ETH',\n bera: 'BERA',\n base: 'ETH',\n gnosis: 'XDAI',\n arb: 'ETH',\n avax: 'AVAX',\n bsc: 'BNB',\n op: 'ETH',\n pol: 'MATIC',\n};\n\nexport const CHAINS_LIST: Record<Chains, Chain> = {\n near: {\n id: 'near',\n label: 'NEAR',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/near.svg',\n },\n eth: {\n id: 'eth',\n label: 'Ethereum',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/eth.svg',\n },\n sol: {\n id: 'sol',\n label: 'Solana',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/sol.svg',\n },\n base: {\n id: 'base',\n label: 'Base',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/base.svg',\n },\n btc: {\n id: 'btc',\n label: 'Bitcoin',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/btc.svg',\n },\n gnosis: {\n id: 'gnosis',\n label: 'Gnosis',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/gnosis.svg',\n },\n xrp: {\n id: 'xrp',\n label: 'XRP',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/xrp.svg',\n },\n bera: {\n id: 'bera',\n label: 'Bera',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/bera.svg',\n },\n tron: {\n id: 'tron',\n label: 'Tron',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/tron.svg',\n },\n zec: {\n id: 'zec',\n label: 'Zcash',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/zec.svg',\n },\n doge: {\n id: 'doge',\n label: 'Dogecoin',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/doge.svg',\n },\n arb: {\n id: 'arb',\n label: 'Arbitrum',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/arb.svg',\n },\n ton: {\n id: 'ton',\n label: 'Toncoin',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/ton.svg',\n },\n op: {\n id: 'op',\n label: 'Optimism',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/op.svg',\n },\n avax: {\n id: 'avax',\n label: 'Avalanche',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/avax.svg',\n },\n pol: {\n id: 'pol',\n label: 'Polygon',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/pol.svg',\n },\n bsc: {\n id: 'bsc',\n label: 'Binance Smart Chain',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/bsc.svg',\n },\n sui: {\n id: 'sui',\n label: 'Sui',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/sui.svg',\n },\n cardano: {\n id: 'cardano',\n label: 'Cardano',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/cardano.svg',\n },\n};\n\nexport const CHAIN_EXPLORERS: Record<number, string> = {\n 1: 'https://etherscan.io/tx/', // Ethereum Mainnet\n 5: 'https://goerli.etherscan.io/tx/', // Goerli Testnet\n 11155111: 'https://sepolia.etherscan.io/tx/', // Sepolia Testnet\n 137: 'https://polygonscan.com/tx/', // Polygon Mainnet\n 80001: 'https://mumbai.polygonscan.com/tx/', // Polygon Mumbai Testnet\n 56: 'https://bscscan.com/tx/', // BSC Mainnet\n 97: 'https://testnet.bscscan.com/tx/', // BSC Testnet\n 42161: 'https://arbiscan.io/tx/', // Arbitrum One\n 421613: 'https://goerli.arbiscan.io/tx/', // Arbitrum Goerli\n 421614: 'https://sepolia.arbiscan.io/tx/', // Arbitrum Sepolia\n 10: 'https://optimistic.etherscan.io/tx/', // Optimism\n 420: 'https://goerli-optimism.etherscan.io/tx/', // Optimism Goerli\n 11155420: 'https://sepolia-optimism.etherscan.io/tx/', // Optimism Sepolia\n 43114: 'https://snowtrace.io/tx/', // Avalanche C-Chain\n 43113: 'https://testnet.snowtrace.io/tx/', // Avalanche Fuji Testnet\n 250: 'https://ftmscan.com/tx/', // Fantom Opera\n 4002: 'https://testnet.ftmscan.com/tx/', // Fantom Testnet\n 8453: 'https://basescan.org/tx/', // Base Mainnet\n 84531: 'https://goerli.basescan.org/tx/', // Base Goerli\n 84532: 'https://sepolia.basescan.org/tx/', // Base Sepolia\n 1313161554: 'https://aurorascan.dev/tx/', // Aurora Mainnet\n 1313161555: 'https://testnet.aurorascan.dev/tx/', // Aurora Testnet\n 100: 'https://gnosisscan.io/tx/', // Gnosis Chain\n 534352: 'https://scrollscan.com/tx/', // Scroll\n 534351: 'https://sepolia.scrollscan.com/tx/', // Scroll Sepolia\n 59144: 'https://lineascan.build/tx/', // Linea\n 59140: 'https://goerli.lineascan.build/tx/', // Linea Goerli\n 324: 'https://explorer.zksync.io/tx/', // zkSync Era\n 280: 'https://goerli.explorer.zksync.io/tx/', // zkSync Era Goerli\n 1101: 'https://zkevm.polygonscan.com/tx/', // Polygon zkEVM\n 1442: 'https://testnet-zkevm.polygonscan.com/tx/', // Polygon zkEVM Testnet\n 5000: 'https://mantlescan.xyz/tx/', // Mantle\n 5001: 'https://explorer.testnet.mantle.xyz/tx/', // Mantle Testnet\n 167000: 'https://taikoscan.io/tx/', // Taiko\n 167005: 'https://hekla.taikoscan.io/tx/', // Taiko Hekla Testnet\n 397: 'https://nearblocks.io/txns/',\n};\n"],"names":["EVM_CHAINS","EVM_CHAIN_IDS_MAP","CHAIN_IDS_MAP","EVM_CHAIN_IDS_MAP_REVERSED","chain","id","NOT_EVM_CHAINS","CHAINS","DEFAULT_CHAIN_ICON","DRY_QUOTE_ADDRESSES","EVM_CHAIN_BASE_TOKENS","CHAINS_LIST","CHAIN_EXPLORERS"],"mappings":"AAEO,MAAMA,IAAa;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEaC,IAA+C;AAAA,EAC1D,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,IAAI;AAAA,EACJ,KAAK;AACP,GAEaC,IAAiD;AAAA,EAC5D,GAAGD;AAAA,EACH,MAAM;AACR,GAEaE,IACX,OAAO;AAAA,EACL,OAAO,QAAQF,CAAiB,EAAE,IAAI,CAAC,CAACG,GAAOC,CAAE,MAAM,CAAC,GAAGA,CAAE,IAAID,CAAK,CAAC;AACzE,GAEWE,IAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEaC,IAAS,CAAC,GAAGP,GAAY,GAA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,EACP,KAAK;AAAA;AAAA,EACL,KAAK;AAAA;AAAA,EACL,MAAM;AAAA;AAAA,EACN,MAAM;AAAA;AAAA,EACN,KAAM;AAAA;AAAA,EACN,MAAM;AAAA;AAAA,EACN,OAAQ;AAAA;AAAA,EACR,QAAQ;AAAA;AAAA,EACR,KAAK;AACP;"}
1
+ {"version":3,"file":"chains.js","sources":["../../src/constants/chains.ts"],"sourcesContent":["import type { Chain, Chains, EvmChains } from '@/types/chain';\n\nexport const EVM_CHAINS = [\n 'eth',\n 'bera',\n 'base',\n 'gnosis',\n 'arb',\n 'bsc',\n 'avax',\n 'op',\n 'pol',\n] as const;\n\nexport const EVM_CHAIN_IDS_MAP: Record<EvmChains, number> = {\n eth: 1,\n bera: 80094,\n base: 8453,\n gnosis: 100,\n arb: 42161,\n avax: 43114,\n bsc: 56,\n op: 10,\n pol: 137,\n};\n\nexport const CHAIN_IDS_MAP: Partial<Record<Chains, number>> = {\n ...EVM_CHAIN_IDS_MAP,\n near: 397,\n};\n\nexport const EVM_CHAIN_IDS_MAP_REVERSED: Record<string, EvmChains> =\n Object.fromEntries(\n Object.entries(EVM_CHAIN_IDS_MAP).map(([chain, id]) => [`${id}`, chain]),\n ) as Record<string, EvmChains>;\n\nexport const NOT_EVM_CHAINS = [\n 'sui',\n 'xrp',\n 'btc',\n 'doge',\n 'tron',\n 'ton',\n 'near',\n 'sol',\n 'zec',\n 'cardano',\n] as const;\n\nexport const CHAINS = [...EVM_CHAINS, ...NOT_EVM_CHAINS] as const;\n\nexport const DEFAULT_CHAIN_ICON =\n 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/unknown.svg';\n\nexport const DRY_QUOTE_ADDRESSES = {\n evm: '0x0000000000000000000000000000000000000000',\n sol: '11111111111111111111111111111111',\n near: 'system.near',\n} as const;\n\nexport const EVM_CHAIN_BASE_TOKENS: Record<EvmChains, string> = {\n eth: 'ETH',\n bera: 'BERA',\n base: 'ETH',\n gnosis: 'XDAI',\n arb: 'ETH',\n avax: 'AVAX',\n bsc: 'BNB',\n op: 'ETH',\n pol: 'MATIC',\n};\n\nexport const CHAINS_LIST: Record<Chains, Chain> = {\n near: {\n id: 'near',\n label: 'NEAR',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/near.svg',\n },\n eth: {\n id: 'eth',\n label: 'Ethereum',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/eth.svg',\n },\n sol: {\n id: 'sol',\n label: 'Solana',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/sol.svg',\n },\n base: {\n id: 'base',\n label: 'Base',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/base.svg',\n },\n btc: {\n id: 'btc',\n label: 'Bitcoin',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/btc.svg',\n },\n gnosis: {\n id: 'gnosis',\n label: 'Gnosis',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/gnosis.svg',\n },\n xrp: {\n id: 'xrp',\n label: 'XRP',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/xrp.svg',\n },\n bera: {\n id: 'bera',\n label: 'Bera',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/bera.svg',\n },\n tron: {\n id: 'tron',\n label: 'Tron',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/tron.svg',\n },\n zec: {\n id: 'zec',\n label: 'Zcash',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/zec.svg',\n },\n doge: {\n id: 'doge',\n label: 'Dogecoin',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/doge.svg',\n },\n arb: {\n id: 'arb',\n label: 'Arbitrum',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/arb.svg',\n },\n ton: {\n id: 'ton',\n label: 'Toncoin',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/ton.svg',\n },\n op: {\n id: 'op',\n label: 'Optimism',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/op.svg',\n },\n avax: {\n id: 'avax',\n label: 'Avalanche',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/avax.svg',\n },\n pol: {\n id: 'pol',\n label: 'Polygon',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/pol.svg',\n },\n bsc: {\n id: 'bsc',\n label: 'Binance Smart Chain',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/bsc.svg',\n },\n sui: {\n id: 'sui',\n label: 'Sui',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/sui.svg',\n },\n cardano: {\n id: 'cardano',\n label: 'Cardano',\n icon: 'https://wtmcxrwapthiogjpxwfr.supabase.co/storage/v1/object/public/swap-widget/cardano.svg',\n },\n};\n\nexport const CHAIN_EXPLORERS: Record<number, string> = {\n 1: 'https://etherscan.io/tx/', // Ethereum Mainnet\n 5: 'https://goerli.etherscan.io/tx/', // Goerli Testnet\n 11155111: 'https://sepolia.etherscan.io/tx/', // Sepolia Testnet\n 137: 'https://polygonscan.com/tx/', // Polygon Mainnet\n 80001: 'https://mumbai.polygonscan.com/tx/', // Polygon Mumbai Testnet\n 56: 'https://bscscan.com/tx/', // BSC Mainnet\n 97: 'https://testnet.bscscan.com/tx/', // BSC Testnet\n 42161: 'https://arbiscan.io/tx/', // Arbitrum One\n 421613: 'https://goerli.arbiscan.io/tx/', // Arbitrum Goerli\n 421614: 'https://sepolia.arbiscan.io/tx/', // Arbitrum Sepolia\n 10: 'https://optimistic.etherscan.io/tx/', // Optimism\n 420: 'https://goerli-optimism.etherscan.io/tx/', // Optimism Goerli\n 11155420: 'https://sepolia-optimism.etherscan.io/tx/', // Optimism Sepolia\n 43114: 'https://snowtrace.io/tx/', // Avalanche C-Chain\n 43113: 'https://testnet.snowtrace.io/tx/', // Avalanche Fuji Testnet\n 250: 'https://ftmscan.com/tx/', // Fantom Opera\n 4002: 'https://testnet.ftmscan.com/tx/', // Fantom Testnet\n 8453: 'https://basescan.org/tx/', // Base Mainnet\n 84531: 'https://goerli.basescan.org/tx/', // Base Goerli\n 84532: 'https://sepolia.basescan.org/tx/', // Base Sepolia\n 1313161554: 'https://aurorascan.dev/tx/', // Aurora Mainnet\n 1313161555: 'https://testnet.aurorascan.dev/tx/', // Aurora Testnet\n 100: 'https://gnosisscan.io/tx/', // Gnosis Chain\n 534352: 'https://scrollscan.com/tx/', // Scroll\n 534351: 'https://sepolia.scrollscan.com/tx/', // Scroll Sepolia\n 59144: 'https://lineascan.build/tx/', // Linea\n 59140: 'https://goerli.lineascan.build/tx/', // Linea Goerli\n 324: 'https://explorer.zksync.io/tx/', // zkSync Era\n 280: 'https://goerli.explorer.zksync.io/tx/', // zkSync Era Goerli\n 1101: 'https://zkevm.polygonscan.com/tx/', // Polygon zkEVM\n 1442: 'https://testnet-zkevm.polygonscan.com/tx/', // Polygon zkEVM Testnet\n 5000: 'https://mantlescan.xyz/tx/', // Mantle\n 5001: 'https://explorer.testnet.mantle.xyz/tx/', // Mantle Testnet\n 167000: 'https://taikoscan.io/tx/', // Taiko\n 167005: 'https://hekla.taikoscan.io/tx/', // Taiko Hekla Testnet\n 397: 'https://nearblocks.io/txns/',\n};\n"],"names":["EVM_CHAINS","EVM_CHAIN_IDS_MAP","CHAIN_IDS_MAP","EVM_CHAIN_IDS_MAP_REVERSED","chain","id","NOT_EVM_CHAINS","CHAINS","DEFAULT_CHAIN_ICON","DRY_QUOTE_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A,EAAA;AAAA,EAER,SAAS;AAAA,IACP,IAAI;AAAA,IACJ,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAEV,GAEaC,IAA0C;AAAA,EACrD,GAAG;AAAA;AAAA,EACH,GAAG;AAAA;AAAA,EACH,UAAU;AAAA;AAAA,EACV,KAAK;AAAA;AAAA,EACL,OAAO;AAAA;AAAA,EACP,IAAI;AAAA;AAAA,EACJ,IAAI;AAAA;AAAA,EACJ,OAAO;AAAA;AAAA,EACP,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA;AAAA,EACR,IAAI;AAAA;AAAA,EACJ,KAAK;AAAA;AAAA,EACL,UAAU;AAAA;AAAA,EACV,OAAO;AAAA;AAAA,EACP,OAAO;AAAA;AAAA,EACP,KAAK;AAAA;AAAA,EACL,MAAM;AAAA;AAAA,EACN,MAAM;AAAA;AAAA,EACN,OAAO;AAAA;AAAA,EACP,OAAO;AAAA;AAAA,EACP,YAAY;AAAA;AAAA,EACZ,YAAY;AAAA;AAAA,EACZ,KAAK;AAAA;AAAA,EACL,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA;AAAA,EACR,OAAO;AAAA;AAAA,EACP,OAAO;AAAA;AAAA,EACP,KAAK;AAAA;AAAA,EACL,KAAK;AAAA;AAAA,EACL,MAAM;AAAA;AAAA,EACN,MAAM;AAAA;AAAA,EACN,KAAM;AAAA;AAAA,EACN,MAAM;AAAA;AAAA,EACN,OAAQ;AAAA;AAAA,EACR,QAAQ;AAAA;AAAA,EACR,KAAK;AACP;"}
@@ -3,6 +3,7 @@ import { Eip1193Provider } from 'ethers';
3
3
  import { TransferResult } from '../types/transfer';
4
4
  export type IntentsTransferArgs = {
5
5
  providers: {
6
+ sol?: undefined | null | (() => Promise<Eip1193Provider>);
6
7
  evm?: undefined | null | (() => Promise<Eip1193Provider>);
7
8
  near?: undefined | null | (() => NearWallet);
8
9
  };
@@ -1,16 +1,16 @@
1
- import { BridgeSDK as f, createNearWithdrawalRoute as w, createInternalTransferRoute as u } from "@defuse-protocol/bridge-sdk";
2
- import { logger as N } from "../logger.js";
3
- import { useConfig as l } from "../config.js";
1
+ import { BridgeSDK as f, createNearWithdrawalRoute as l, createInternalTransferRoute as N } from "@defuse-protocol/bridge-sdk";
2
+ import { logger as u } from "../logger.js";
3
+ import { useConfig as T } from "../config.js";
4
4
  import { TransferError as r } from "../errors.js";
5
- import { CHAIN_IDS_MAP as T } from "../constants/chains.js";
6
- import { notReachable as R } from "../utils/notReachable.js";
7
- import { IntentSignerPrivy as g } from "../utils/intents/signers/privy.js";
5
+ import { CHAIN_IDS_MAP as R } from "../constants/chains.js";
6
+ import { notReachable as g } from "../utils/notReachable.js";
7
+ import { IntentSignerPrivy as c } from "../utils/intents/signers/privy.js";
8
8
  import { createNearWalletSigner as h } from "../utils/intents/signers/near.js";
9
9
  import { getIntentsAccountId as S } from "../utils/intents/getIntentsAccountId.js";
10
10
  import { getTransactionLink as E } from "../utils/formatters/getTransactionLink.js";
11
- import { isUserDeniedSigning as c } from "../utils/checkers/isUserDeniedSigning.js";
11
+ import { isUserDeniedSigning as A } from "../utils/checkers/isUserDeniedSigning.js";
12
12
  import { useUnsafeSnapshot as _, useComputedSnapshot as p } from "../machine/snap.js";
13
- const D = (t, e) => {
13
+ const L = (t, e) => {
14
14
  if (e) {
15
15
  if (t.sendAddress)
16
16
  return t.sendAddress;
@@ -26,7 +26,7 @@ const D = (t, e) => {
26
26
  });
27
27
  return t.quote.depositAddress;
28
28
  }, B = ({ providers: t }) => {
29
- const { ctx: e } = _(), { isDirectTransfer: i } = p(), { appName: A, intentsAccountType: o } = l();
29
+ const { ctx: e } = _(), { isDirectTransfer: i } = p(), { appName: w, intentsAccountType: a } = T();
30
30
  return { make: async ({
31
31
  onPending: d
32
32
  }) => {
@@ -47,69 +47,78 @@ const D = (t, e) => {
47
47
  message: "For not intents source token use useMakeQuoteTransfer instead"
48
48
  }
49
49
  });
50
- let a;
51
- switch (o) {
50
+ let n;
51
+ switch (a) {
52
52
  case "evm":
53
53
  if (!t.evm)
54
54
  throw new r({
55
55
  code: "TRANSFER_INVALID_INITIAL",
56
56
  meta: { message: "No EVM provider configured" }
57
57
  });
58
- a = new g(
58
+ n = new c(
59
59
  { walletAddress: e.walletAddress },
60
60
  t.evm
61
61
  );
62
62
  break;
63
+ case "sol":
64
+ if (!t.sol)
65
+ throw new r({
66
+ code: "TRANSFER_INVALID_INITIAL",
67
+ meta: { message: "No EVM provider configured" }
68
+ });
69
+ n = new c(
70
+ { walletAddress: e.walletAddress },
71
+ t.sol
72
+ );
73
+ break;
63
74
  case "near":
64
75
  if (!t.near)
65
76
  throw new r({
66
77
  code: "TRANSFER_INVALID_INITIAL",
67
78
  meta: { message: "No NEAR provider configured" }
68
79
  });
69
- a = h({
80
+ n = h({
70
81
  walletAddress: e.walletAddress,
71
82
  getProvider: t.near
72
83
  });
73
84
  break;
74
85
  default:
75
- throw R(o, { throwError: !1 }), new r({
76
- code: "BRIDGE_SDK_FAILED"
77
- });
86
+ g(a);
78
87
  }
79
- const I = new f({ referral: A });
80
- I.setIntentSigner(a);
81
- const s = I.createWithdrawal({
88
+ const I = new f({ referral: w });
89
+ I.setIntentSigner(n);
90
+ const o = I.createWithdrawal({
82
91
  withdrawalParams: {
83
92
  assetId: e.sourceToken.assetId,
84
93
  amount: BigInt(e.sourceTokenAmount),
85
- destinationAddress: D(e, i),
94
+ destinationAddress: L(e, i),
86
95
  destinationMemo: void 0,
87
96
  feeInclusive: !1,
88
- routeConfig: i ? w(
97
+ routeConfig: i ? l(
89
98
  S({
90
99
  walletAddress: e.walletAddress,
91
- addressType: o
100
+ addressType: a
92
101
  }) ?? void 0
93
- ) : u()
102
+ ) : N()
94
103
  }
95
104
  });
96
105
  try {
97
- await s.estimateFee(), d("WAITING_CONFIRMATION");
98
- const n = await s.signAndSendIntent();
106
+ await o.estimateFee(), d("WAITING_CONFIRMATION");
107
+ const s = await o.signAndSendIntent();
99
108
  d("PROCESSING");
100
- const m = await s.waitForIntentSettlement();
101
- return await s.waitForWithdrawalCompletion(), {
109
+ const m = await o.waitForIntentSettlement();
110
+ return await o.waitForWithdrawalCompletion(), {
102
111
  hash: m.hash,
103
- transactionLink: E(T.near, m.hash),
104
- intent: n
112
+ transactionLink: E(R.near, m.hash),
113
+ intent: s
105
114
  };
106
- } catch (n) {
107
- if (N.error("[TRANSFER ERROR]", n), n instanceof Error) {
108
- if (n.message.includes("Fee is not estimated"))
115
+ } catch (s) {
116
+ if (u.error("[TRANSFER ERROR]", s), s instanceof Error) {
117
+ if (s.message.includes("Fee is not estimated"))
109
118
  throw new r({
110
119
  code: "FEES_NOT_ESTIMATED"
111
120
  });
112
- if (c(n.message) || c(`${n.cause}`))
121
+ if (A(s.message) || A(`${s.cause}`))
113
122
  return;
114
123
  }
115
124
  throw new r({
@@ -1 +1 @@
1
- {"version":3,"file":"useMakeIntentsTransfer.js","sources":["../../src/hooks/useMakeIntentsTransfer.ts"],"sourcesContent":["import {\n BridgeSDK,\n createIntentSignerNEP413,\n createInternalTransferRoute,\n createNearWithdrawalRoute,\n} from '@defuse-protocol/bridge-sdk';\nimport type { Wallet as NearWallet } from '@near-wallet-selector/core';\nimport type { Eip1193Provider } from 'ethers';\n\nimport { logger } from '@/logger';\nimport { useConfig } from '@/config';\nimport { TransferError } from '@/errors';\nimport { CHAIN_IDS_MAP } from '@/constants/chains';\nimport { notReachable } from '@/utils/notReachable';\nimport { IntentSignerPrivy } from '@/utils/intents/signers/privy';\nimport { createNearWalletSigner } from '@/utils/intents/signers/near';\nimport { getIntentsAccountId } from '@/utils/intents/getIntentsAccountId';\nimport { getTransactionLink } from '@/utils/formatters/getTransactionLink';\nimport { isUserDeniedSigning } from '@/utils/checkers/isUserDeniedSigning';\nimport { useComputedSnapshot, useUnsafeSnapshot } from '@/machine/snap';\nimport type { TransferResult } from '@/types/transfer';\nimport type { Context } from '@/machine/context';\n\nexport type IntentsTransferArgs = {\n providers: {\n evm?: undefined | null | (() => Promise<Eip1193Provider>);\n near?: undefined | null | (() => NearWallet);\n };\n};\n\ntype MakeArgs = {\n onPending: (reason: 'WAITING_CONFIRMATION' | 'PROCESSING') => void;\n};\n\nconst getDestinationAddress = (ctx: Context, isDirectTransfer: boolean) => {\n if (isDirectTransfer) {\n if (ctx.sendAddress) {\n return ctx.sendAddress;\n }\n\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'Send to address is required for a direct transfer' },\n });\n }\n\n if (!ctx.quote || ctx.quote.dry) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'Quote is required for intents non-direct transfer' },\n });\n }\n\n return ctx.quote.depositAddress;\n};\n\nexport const useMakeIntentsTransfer = ({ providers }: IntentsTransferArgs) => {\n const { ctx } = useUnsafeSnapshot();\n const { isDirectTransfer } = useComputedSnapshot();\n const { appName, intentsAccountType } = useConfig();\n\n const make = async ({\n onPending,\n }: MakeArgs): Promise<TransferResult | undefined> => {\n if (!ctx.walletAddress) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'No connected wallet to sign a transfer.' },\n });\n }\n\n if (!ctx.sourceToken || !ctx.targetToken) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'No token selected to transfer.' },\n });\n }\n\n if (!ctx.sourceToken.isIntent) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: {\n message:\n 'For not intents source token use useMakeQuoteTransfer instead',\n },\n });\n }\n\n let signer:\n | IntentSignerPrivy\n | ReturnType<typeof createIntentSignerNEP413>\n | undefined;\n\n switch (intentsAccountType) {\n case 'evm':\n if (!providers.evm) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'No EVM provider configured' },\n });\n }\n\n signer = new IntentSignerPrivy(\n { walletAddress: ctx.walletAddress },\n providers.evm,\n );\n break;\n case 'near':\n if (!providers.near) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'No NEAR provider configured' },\n });\n }\n\n signer = createNearWalletSigner({\n walletAddress: ctx.walletAddress,\n getProvider: providers.near,\n });\n break;\n default:\n notReachable(intentsAccountType, { throwError: false });\n throw new TransferError({\n code: 'BRIDGE_SDK_FAILED',\n });\n }\n\n const sdk = new BridgeSDK({ referral: appName });\n\n sdk.setIntentSigner(signer);\n\n const withdrawal = sdk.createWithdrawal({\n withdrawalParams: {\n assetId: ctx.sourceToken.assetId,\n amount: BigInt(ctx.sourceTokenAmount),\n destinationAddress: getDestinationAddress(ctx, isDirectTransfer),\n destinationMemo: undefined,\n feeInclusive: false,\n routeConfig: isDirectTransfer\n ? createNearWithdrawalRoute(\n getIntentsAccountId({\n walletAddress: ctx.walletAddress,\n addressType: intentsAccountType,\n }) ?? undefined,\n )\n : createInternalTransferRoute(),\n },\n });\n\n try {\n await withdrawal.estimateFee();\n\n onPending('WAITING_CONFIRMATION');\n const txIntent = await withdrawal.signAndSendIntent();\n\n onPending('PROCESSING');\n const tx = await withdrawal.waitForIntentSettlement();\n\n await withdrawal.waitForWithdrawalCompletion();\n\n return {\n hash: tx.hash,\n transactionLink: getTransactionLink(CHAIN_IDS_MAP.near, tx.hash),\n intent: txIntent,\n };\n } catch (e: unknown) {\n logger.error('[TRANSFER ERROR]', e);\n\n if (e instanceof Error) {\n if (e.message.includes('Fee is not estimated')) {\n throw new TransferError({\n code: 'FEES_NOT_ESTIMATED',\n });\n }\n\n // User rejected\n if (\n isUserDeniedSigning(e.message) ||\n isUserDeniedSigning(`${e.cause}`)\n ) {\n return undefined;\n }\n }\n\n throw new TransferError({\n code: 'DIRECT_TRANSFER_ERROR',\n });\n }\n };\n\n return { make };\n};\n"],"names":["getDestinationAddress","ctx","isDirectTransfer","TransferError","useMakeIntentsTransfer","providers","useUnsafeSnapshot","useComputedSnapshot","appName","intentsAccountType","useConfig","onPending","signer","IntentSignerPrivy","createNearWalletSigner","notReachable","sdk","BridgeSDK","withdrawal","createNearWithdrawalRoute","getIntentsAccountId","createInternalTransferRoute","txIntent","tx","getTransactionLink","CHAIN_IDS_MAP","e","logger","isUserDeniedSigning"],"mappings":";;;;;;;;;;;;AAkCA,MAAMA,IAAwB,CAACC,GAAcC,MAA8B;AACzE,MAAIA,GAAkB;AACpB,QAAID,EAAI;AACN,aAAOA,EAAI;AAGb,UAAM,IAAIE,EAAc;AAAA,MACtB,MAAM;AAAA,MACN,MAAM,EAAE,SAAS,oDAAA;AAAA,IAAoD,CACtE;AAAA,EACH;AAEA,MAAI,CAACF,EAAI,SAASA,EAAI,MAAM;AAC1B,UAAM,IAAIE,EAAc;AAAA,MACtB,MAAM;AAAA,MACN,MAAM,EAAE,SAAS,oDAAA;AAAA,IAAoD,CACtE;AAGH,SAAOF,EAAI,MAAM;AACnB,GAEaG,IAAyB,CAAC,EAAE,WAAAC,QAAqC;AAC5E,QAAM,EAAE,KAAAJ,EAAA,IAAQK,EAAA,GACV,EAAE,kBAAAJ,EAAA,IAAqBK,EAAA,GACvB,EAAE,SAAAC,GAAS,oBAAAC,EAAA,IAAuBC,EAAA;AAmIxC,SAAO,EAAE,MAjII,OAAO;AAAA,IAClB,WAAAC;AAAA,EAAA,MACmD;AACnD,QAAI,CAACV,EAAI;AACP,YAAM,IAAIE,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAAS,0CAAA;AAAA,MAA0C,CAC5D;AAGH,QAAI,CAACF,EAAI,eAAe,CAACA,EAAI;AAC3B,YAAM,IAAIE,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAAS,iCAAA;AAAA,MAAiC,CACnD;AAGH,QAAI,CAACF,EAAI,YAAY;AACnB,YAAM,IAAIE,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM;AAAA,UACJ,SACE;AAAA,QAAA;AAAA,MACJ,CACD;AAGH,QAAIS;AAKJ,YAAQH,GAAA;AAAA,MACN,KAAK;AACH,YAAI,CAACJ,EAAU;AACb,gBAAM,IAAIF,EAAc;AAAA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AA,QACT,iBAAiBC,EAAmBC,EAAc,MAAMF,EAAG,IAAI;AAAA,QAC/D,QAAQD;AAAA,MAAA;AAAA,IAEZ,SAASI,GAAY;AAGnB,UAFAC,EAAO,MAAM,oBAAoBD,CAAC,GAE9BA,aAAa,OAAO;AACtB,YAAIA,EAAE,QAAQ,SAAS,sBAAsB;AAC3C,gBAAM,IAAIvB,EAAc;AAAA,YACtB,MAAM;AAAA,UAAA,CACP;AAIH,YACEyB,EAAoBF,EAAE,OAAO,KAC7BE,EAAoB,GAAGF,EAAE,KAAK,EAAE;AAEhC;AAAA,MAEJ;AAEA,YAAM,IAAIvB,EAAc;AAAA,QACtB,MAAM;AAAA,MAAA,CACP;AAAA,IACH;AAAA,EACF,EAES;AACX;"}
1
+ {"version":3,"file":"useMakeIntentsTransfer.js","sources":["../../src/hooks/useMakeIntentsTransfer.ts"],"sourcesContent":["import {\n BridgeSDK,\n createIntentSignerNEP413,\n createInternalTransferRoute,\n createNearWithdrawalRoute,\n} from '@defuse-protocol/bridge-sdk';\nimport type { Wallet as NearWallet } from '@near-wallet-selector/core';\nimport type { Eip1193Provider } from 'ethers';\n\nimport { logger } from '@/logger';\nimport { useConfig } from '@/config';\nimport { TransferError } from '@/errors';\nimport { CHAIN_IDS_MAP } from '@/constants/chains';\nimport { notReachable } from '@/utils/notReachable';\nimport { IntentSignerPrivy } from '@/utils/intents/signers/privy';\nimport { createNearWalletSigner } from '@/utils/intents/signers/near';\nimport { getIntentsAccountId } from '@/utils/intents/getIntentsAccountId';\nimport { getTransactionLink } from '@/utils/formatters/getTransactionLink';\nimport { isUserDeniedSigning } from '@/utils/checkers/isUserDeniedSigning';\nimport { useComputedSnapshot, useUnsafeSnapshot } from '@/machine/snap';\nimport type { TransferResult } from '@/types/transfer';\nimport type { Context } from '@/machine/context';\n\nexport type IntentsTransferArgs = {\n providers: {\n sol?: undefined | null | (() => Promise<Eip1193Provider>);\n evm?: undefined | null | (() => Promise<Eip1193Provider>);\n near?: undefined | null | (() => NearWallet);\n };\n};\n\ntype MakeArgs = {\n onPending: (reason: 'WAITING_CONFIRMATION' | 'PROCESSING') => void;\n};\n\nconst getDestinationAddress = (ctx: Context, isDirectTransfer: boolean) => {\n if (isDirectTransfer) {\n if (ctx.sendAddress) {\n return ctx.sendAddress;\n }\n\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'Send to address is required for a direct transfer' },\n });\n }\n\n if (!ctx.quote || ctx.quote.dry) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'Quote is required for intents non-direct transfer' },\n });\n }\n\n return ctx.quote.depositAddress;\n};\n\nexport const useMakeIntentsTransfer = ({ providers }: IntentsTransferArgs) => {\n const { ctx } = useUnsafeSnapshot();\n const { isDirectTransfer } = useComputedSnapshot();\n const { appName, intentsAccountType } = useConfig();\n\n const make = async ({\n onPending,\n }: MakeArgs): Promise<TransferResult | undefined> => {\n if (!ctx.walletAddress) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'No connected wallet to sign a transfer.' },\n });\n }\n\n if (!ctx.sourceToken || !ctx.targetToken) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'No token selected to transfer.' },\n });\n }\n\n if (!ctx.sourceToken.isIntent) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: {\n message:\n 'For not intents source token use useMakeQuoteTransfer instead',\n },\n });\n }\n\n let signer:\n | IntentSignerPrivy\n | ReturnType<typeof createIntentSignerNEP413>\n | undefined;\n\n switch (intentsAccountType) {\n case 'evm':\n if (!providers.evm) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'No EVM provider configured' },\n });\n }\n\n signer = new IntentSignerPrivy(\n { walletAddress: ctx.walletAddress },\n providers.evm,\n );\n break;\n case 'sol':\n if (!providers.sol) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'No EVM provider configured' },\n });\n }\n\n signer = new IntentSignerPrivy(\n { walletAddress: ctx.walletAddress },\n providers.sol,\n );\n break;\n case 'near':\n if (!providers.near) {\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: 'No NEAR provider configured' },\n });\n }\n\n signer = createNearWalletSigner({\n walletAddress: ctx.walletAddress,\n getProvider: providers.near,\n });\n break;\n default:\n notReachable(intentsAccountType);\n }\n\n const sdk = new BridgeSDK({ referral: appName });\n\n sdk.setIntentSigner(signer);\n\n const withdrawal = sdk.createWithdrawal({\n withdrawalParams: {\n assetId: ctx.sourceToken.assetId,\n amount: BigInt(ctx.sourceTokenAmount),\n destinationAddress: getDestinationAddress(ctx, isDirectTransfer),\n destinationMemo: undefined,\n feeInclusive: false,\n routeConfig: isDirectTransfer\n ? createNearWithdrawalRoute(\n getIntentsAccountId({\n walletAddress: ctx.walletAddress,\n addressType: intentsAccountType,\n }) ?? undefined,\n )\n : createInternalTransferRoute(),\n },\n });\n\n try {\n await withdrawal.estimateFee();\n\n onPending('WAITING_CONFIRMATION');\n const txIntent = await withdrawal.signAndSendIntent();\n\n onPending('PROCESSING');\n const tx = await withdrawal.waitForIntentSettlement();\n\n await withdrawal.waitForWithdrawalCompletion();\n\n return {\n hash: tx.hash,\n transactionLink: getTransactionLink(CHAIN_IDS_MAP.near, tx.hash),\n intent: txIntent,\n };\n } catch (e: unknown) {\n logger.error('[TRANSFER ERROR]', e);\n\n if (e instanceof Error) {\n if (e.message.includes('Fee is not estimated')) {\n throw new TransferError({\n code: 'FEES_NOT_ESTIMATED',\n });\n }\n\n // User rejected\n if (\n isUserDeniedSigning(e.message) ||\n isUserDeniedSigning(`${e.cause}`)\n ) {\n return undefined;\n }\n }\n\n throw new TransferError({\n code: 'DIRECT_TRANSFER_ERROR',\n });\n }\n };\n\n return { make };\n};\n"],"names":["getDestinationAddress","ctx","isDirectTransfer","TransferError","useMakeIntentsTransfer","providers","useUnsafeSnapshot","useComputedSnapshot","appName","intentsAccountType","useConfig","onPending","signer","IntentSignerPrivy","createNearWalletSigner","notReachable","sdk","BridgeSDK","withdrawal","createNearWithdrawalRoute","getIntentsAccountId","createInternalTransferRoute","txIntent","tx","getTransactionLink","CHAIN_IDS_MAP","e","logger","isUserDeniedSigning"],"mappings":";;;;;;;;;;;;AAmCA,MAAMA,IAAwB,CAACC,GAAcC,MAA8B;AACzE,MAAIA,GAAkB;AACpB,QAAID,EAAI;AACN,aAAOA,EAAI;AAGb,UAAM,IAAIE,EAAc;AAAA,MACtB,MAAM;AAAA,MACN,MAAM,EAAE,SAAS,oDAAA;AAAA,IAAoD,CACtE;AAAA,EACH;AAEA,MAAI,CAACF,EAAI,SAASA,EAAI,MAAM;AAC1B,UAAM,IAAIE,EAAc;AAAA,MACtB,MAAM;AAAA,MACN,MAAM,EAAE,SAAS,oDAAA;AAAA,IAAoD,CACtE;AAGH,SAAOF,EAAI,MAAM;AACnB,GAEaG,IAAyB,CAAC,EAAE,WAAAC,QAAqC;AAC5E,QAAM,EAAE,KAAAJ,EAAA,IAAQK,EAAA,GACV,EAAE,kBAAAJ,EAAA,IAAqBK,EAAA,GACvB,EAAE,SAAAC,GAAS,oBAAAC,EAAA,IAAuBC,EAAA;AA6IxC,SAAO,EAAE,MA3II,OAAO;AAAA,IAClB,WAAAC;AAAA,EAAA,MACmD;AACnD,QAAI,CAACV,EAAI;AACP,YAAM,IAAIE,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAAS,0CAAA;AAAA,MAA0C,CAC5D;AAGH,QAAI,CAACF,EAAI,eAAe,CAACA,EAAI;AAC3B,YAAM,IAAIE,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAAS,iCAAA;AAAA,MAAiC,CACnD;AAGH,QAAI,CAACF,EAAI,YAAY;AACnB,YAAM,IAAIE,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM;AAAA,UACJ,SACE;AAAA,QAAA;AAAA,MACJ,CACD;AAG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IAERY,EAAA;AAAA,MAA4B;AAAA,IAClC,CACD;AAED,QAAI;AACF,YAAMH,EAAW,YAAA,GAEjBP,EAAU,sBAAsB;AAChC,YAAMW,IAAW,MAAMJ,EAAW,kBAAA;AAElC,MAAAP,EAAU,YAAY;AACtB,YAAMY,IAAK,MAAML,EAAW,wBAAA;AAE5B,mBAAMA,EAAW,4BAAA,GAEV;AAAA,QACL,MAAMK,EAAG;AAAA,QACT,iBAAiBC,EAAmBC,EAAc,MAAMF,EAAG,IAAI;AAAA,QAC/D,QAAQD;AAAA,MAAA;AAAA,IAEZ,SAASI,GAAY;AAGnB,UAFAC,EAAO,MAAM,oBAAoBD,CAAC,GAE9BA,aAAa,OAAO;AACtB,YAAIA,EAAE,QAAQ,SAAS,sBAAsB;AAC3C,gBAAM,IAAIvB,EAAc;AAAA,YACtB,MAAM;AAAA,UAAA,CACP;AAIH,YACEyB,EAAoBF,EAAE,OAAO,KAC7BE,EAAoB,GAAGF,EAAE,KAAK,EAAE;AAEhC;AAAA,MAEJ;AAEA,YAAM,IAAIvB,EAAc;AAAA,QACtB,MAAM;AAAA,MAAA,CACP;AAAA,IACH;AAAA,EACF,EAES;AACX;"}
@@ -1,170 +1,171 @@
1
- import { useRef as y } from "react";
2
- import { QuoteRequest as o, OneClickService as I, CancelError as _, ApiError as E } from "@defuse-protocol/one-click-sdk-typescript";
1
+ import { useRef as _ } from "react";
2
+ import { QuoteRequest as r, OneClickService as I, CancelError as g, ApiError as A } from "@defuse-protocol/one-click-sdk-typescript";
3
3
  import { logger as u } from "../logger.js";
4
- import { useConfig as g } from "../config.js";
5
- import { QuoteError as i } from "../errors.js";
4
+ import { useConfig as E } from "../config.js";
5
+ import { QuoteError as a } from "../errors.js";
6
6
  import { guardStates as O } from "../machine/guards/index.js";
7
7
  import { useUnsafeSnapshot as k } from "../machine/snap.js";
8
- import { getIntentsAccountId as S } from "../utils/intents/getIntentsAccountId.js";
9
- import { formatBigToHuman as h } from "../utils/formatters/formatBigToHuman.js";
10
- import { DRY_QUOTE_ADDRESSES as A } from "../constants/chains.js";
8
+ import { getIntentsAccountId as h } from "../utils/intents/getIntentsAccountId.js";
9
+ import { formatBigToHuman as S } from "../utils/formatters/formatBigToHuman.js";
10
+ import { DRY_QUOTE_ADDRESSES as N } from "../constants/chains.js";
11
11
  import { useTokens as D } from "./useTokens.js";
12
- const M = ({ variant: N }) => {
13
- const { ctx: e } = k(), { intentsAccountType: T } = g(), n = !e.walletAddress, { tokens: w } = D(), a = S({
12
+ const P = ({ variant: w }) => {
13
+ const { ctx: e } = k(), { intentsAccountType: T } = E(), s = !e.walletAddress, { tokens: y } = D(), d = h({
14
14
  addressType: T,
15
- walletAddress: n ? A[T] : e.walletAddress ?? ""
16
- }), s = y(null), m = n ? A[T] : e.walletAddress ?? "";
15
+ walletAddress: s ? N[T] : e.walletAddress ?? ""
16
+ }), n = _(null), m = s ? N[T] : e.walletAddress ?? "";
17
17
  return { make: async ({ message: l } = {}) => {
18
18
  if (!O(e, [
19
19
  "input_valid_dry",
20
20
  "input_valid_external",
21
21
  "input_valid_internal"
22
22
  ])) {
23
- const r = `Unable to run quote in current state ${e.state}`;
24
- throw u.error(`[WIDGET] ${r}`), new i({
23
+ const t = `Unable to run quote in current state ${e.state}`;
24
+ throw u.error(`[WIDGET] ${t}`), new a({
25
25
  code: "QUOTE_INVALID_INITIAL",
26
- meta: { isDry: n, message: r }
26
+ meta: { isDry: s, message: t }
27
27
  });
28
28
  }
29
- if (!a) {
30
- const r = "No corresponding intents account to run a quote";
31
- throw u.error(`[WIDGET] ${r}`), new i({
29
+ if (!d) {
30
+ const t = "No corresponding intents account to run a quote";
31
+ throw u.error(`[WIDGET] ${t}`), new a({
32
32
  code: "QUOTE_INVALID_INITIAL",
33
- meta: { isDry: n, message: r }
33
+ meta: { isDry: s, message: t }
34
34
  });
35
35
  }
36
- s.current && !s.current.isCancelled && s.current.cancel();
37
- let d;
36
+ n.current && !n.current.isCancelled && n.current.cancel();
37
+ let i;
38
38
  try {
39
- const r = {
39
+ const t = {
40
40
  // Settings
41
41
  slippageTolerance: 100,
42
42
  // 1%
43
- swapType: o.swapType.EXACT_INPUT,
43
+ swapType: r.swapType.EXACT_INPUT,
44
44
  deadline: new Date(Date.now() + 36e5).toISOString(),
45
45
  // 1 hour
46
- dry: n,
46
+ dry: s,
47
47
  // Source
48
48
  originAsset: e.sourceToken.assetId,
49
49
  amount: e.sourceTokenAmount
50
50
  };
51
- l && (r.customRecipientMsg = l);
51
+ l && (t.customRecipientMsg = l);
52
52
  try {
53
- switch (N) {
53
+ switch (w) {
54
54
  case "deposit": {
55
- const t = w.find(
55
+ const o = y.find(
56
56
  (c) => c.blockchain === "near" && c.symbol === e.sourceToken.symbol
57
57
  );
58
- if (!t)
59
- throw new i({
58
+ if (!o)
59
+ throw new a({
60
60
  code: "NO_NEAR_TOKEN_FOUND",
61
61
  meta: { symbol: e.sourceToken.symbol }
62
62
  });
63
- s.current = I.getQuote({
64
- ...r,
65
- recipient: a,
66
- recipientType: o.recipientType.INTENTS,
67
- depositType: o.depositType.ORIGIN_CHAIN,
68
- destinationAsset: t.assetId,
63
+ n.current = I.getQuote({
64
+ ...t,
65
+ recipient: d,
66
+ recipientType: r.recipientType.INTENTS,
67
+ depositType: r.depositType.ORIGIN_CHAIN,
68
+ destinationAsset: o.assetId,
69
69
  // Refund
70
70
  refundTo: m,
71
- refundType: o.refundType.ORIGIN_CHAIN
72
- }), d = await s.current;
71
+ refundType: r.refundType.ORIGIN_CHAIN
72
+ }), i = await n.current;
73
73
  break;
74
74
  }
75
75
  case "swap": {
76
76
  if (e.sourceToken.isIntent && e.targetToken.isIntent) {
77
- s.current = I.getQuote({
78
- ...r,
79
- recipient: a,
80
- recipientType: o.recipientType.INTENTS,
77
+ n.current = I.getQuote({
78
+ ...t,
79
+ recipient: d,
80
+ recipientType: r.recipientType.INTENTS,
81
81
  destinationAsset: e.targetToken.assetId,
82
- depositType: o.depositType.INTENTS,
82
+ depositType: r.depositType.INTENTS,
83
83
  // Refund
84
- refundTo: a,
85
- refundType: o.refundType.INTENTS
86
- }), d = await s.current;
84
+ refundTo: d,
85
+ refundType: r.refundType.INTENTS
86
+ }), i = await n.current;
87
87
  break;
88
88
  }
89
- s.current = I.getQuote({
90
- ...r,
91
- recipient: !e.targetToken.isIntent && e.sendAddress ? e.sendAddress : a,
92
- recipientType: e.targetToken.isIntent ? o.recipientType.INTENTS : o.recipientType.DESTINATION_CHAIN,
89
+ n.current = I.getQuote({
90
+ ...t,
91
+ recipient: !e.targetToken.isIntent && e.sendAddress ? e.sendAddress : d,
92
+ recipientType: e.targetToken.isIntent ? r.recipientType.INTENTS : r.recipientType.DESTINATION_CHAIN,
93
93
  destinationAsset: e.targetToken.assetId,
94
- depositType: e.sourceToken.isIntent ? o.depositType.INTENTS : o.depositType.ORIGIN_CHAIN,
94
+ depositType: e.sourceToken.isIntent ? r.depositType.INTENTS : r.depositType.ORIGIN_CHAIN,
95
95
  // Refund
96
- refundTo: e.sourceToken.isIntent ? a : m,
97
- refundType: e.sourceToken.isIntent ? o.refundType.INTENTS : o.refundType.ORIGIN_CHAIN
98
- }), d = await s.current;
96
+ refundTo: e.sourceToken.isIntent ? d : m,
97
+ refundType: e.sourceToken.isIntent ? r.refundType.INTENTS : r.refundType.ORIGIN_CHAIN
98
+ }), i = await n.current;
99
99
  break;
100
100
  }
101
101
  default: {
102
- const t = "Unknown swap variant (deposit or swap expected)";
103
- throw u.error(`[WIDGET] ${t}`), new i({
102
+ const o = "Unknown swap variant (deposit or swap expected)";
103
+ throw u.error(`[WIDGET] ${o}`), new a({
104
104
  code: "QUOTE_INVALID_INITIAL",
105
- meta: { isDry: n, message: t }
105
+ meta: { isDry: s, message: o }
106
106
  });
107
107
  }
108
108
  }
109
- } catch (t) {
110
- if (t instanceof _)
109
+ } catch (o) {
110
+ if (o instanceof g)
111
111
  return;
112
- throw t instanceof E ? (u.error(t), new i({
112
+ throw o instanceof A ? (u.error(o), o) : (u.error("[WIDGET] Failed to get a deposit address from the quote"), new a({
113
113
  code: "QUOTE_INVALID",
114
- meta: { isDry: n }
115
- })) : (u.error("[WIDGET] Failed to get a deposit address from the quote"), new i({
116
- code: "QUOTE_INVALID",
117
- meta: { isDry: n }
114
+ meta: { isDry: s }
118
115
  }));
119
116
  }
120
- if (!d.quote.depositAddress && !s.current.isCancelled && !n)
117
+ if (!i.quote.depositAddress && !n.current.isCancelled && !s)
121
118
  throw new Error("Failed to get a deposit address from the quote");
122
- } catch (r) {
123
- const t = r?.message;
124
- if (t.includes("Amount is too low")) {
125
- const c = t.match(/\d+/), f = c ? c[0] : void 0;
126
- throw new i({
127
- code: "QUOTE_AMOUNT_IS_TOO_LOW",
128
- meta: {
129
- minAmount: (f && h(f, e.sourceToken.decimals)) ?? "0"
130
- }
131
- });
119
+ } catch (t) {
120
+ if (t instanceof A) {
121
+ const o = t.body.message ?? t.message;
122
+ if (o.includes("Amount is too low")) {
123
+ const c = o.match(/\d+/), f = c ? c[0] : void 0;
124
+ throw new a({
125
+ code: "QUOTE_AMOUNT_IS_TOO_LOW",
126
+ meta: {
127
+ minAmount: (f && S(f, e.sourceToken.decimals)) ?? "0"
128
+ }
129
+ });
130
+ }
131
+ throw o.includes("recipient is not valid") ? new a({
132
+ code: "TOKEN_IS_NOT_SUPPORTED"
133
+ }) : o.includes("Failed to get a deposit address") ? new a({
134
+ code: "QUOTE_NO_ONE_TIME_ADDRESS"
135
+ }) : t;
132
136
  }
133
- throw t.includes("recipient is not valid") ? new i({
134
- code: "TOKEN_IS_NOT_SUPPORTED"
135
- }) : t.includes("Failed to get a deposit address") ? new i({
136
- code: "QUOTE_NO_ONE_TIME_ADDRESS"
137
- }) : new i({
137
+ throw new a({
138
138
  code: "QUOTE_FAILED",
139
139
  meta: {
140
- message: t ?? "Failed to fetch quote. Please try again."
140
+ // @ts-expect-error In case error has a message
141
+ message: t?.message ?? "Failed to fetch quote. Please try again."
141
142
  }
142
143
  });
143
144
  }
144
145
  let p;
145
- if (n)
146
+ if (s)
146
147
  p = {
147
148
  dry: !0,
148
- ...d.quote,
149
+ ...i.quote,
149
150
  deadline: void 0,
150
151
  depositAddress: void 0
151
152
  };
152
- else if (d.quote.deadline && d.quote.depositAddress)
153
+ else if (i.quote.deadline && i.quote.depositAddress)
153
154
  p = {
154
155
  dry: !1,
155
- ...d.quote,
156
- deadline: d.quote.deadline,
157
- depositAddress: d.quote.depositAddress
156
+ ...i.quote,
157
+ deadline: i.quote.deadline,
158
+ depositAddress: i.quote.depositAddress
158
159
  };
159
160
  else
160
- throw new i({
161
+ throw new a({
161
162
  code: "QUOTE_INVALID",
162
- meta: { isDry: n }
163
+ meta: { isDry: s }
163
164
  });
164
165
  return p;
165
- }, cancel: () => s.current?.cancel() };
166
+ }, cancel: () => n.current?.cancel() };
166
167
  };
167
168
  export {
168
- M as useMakeQuote
169
+ P as useMakeQuote
169
170
  };
170
171
  //# sourceMappingURL=useMakeQuote.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMakeQuote.js","sources":["../../src/hooks/useMakeQuote.ts"],"sourcesContent":["import { useRef } from 'react';\nimport {\n ApiError,\n CancelablePromise,\n CancelError,\n OneClickService,\n QuoteRequest,\n QuoteResponse,\n} from '@defuse-protocol/one-click-sdk-typescript';\n\nimport { logger } from '@/logger';\nimport { useConfig } from '@/config';\nimport { QuoteError } from '@/errors';\nimport { guardStates } from '@/machine/guards';\nimport { useUnsafeSnapshot } from '@/machine/snap';\nimport { getIntentsAccountId } from '@/utils/intents/getIntentsAccountId';\nimport { formatBigToHuman } from '@/utils/formatters/formatBigToHuman';\nimport { DRY_QUOTE_ADDRESSES } from '@/constants/chains';\nimport { Quote } from '@/types/quote';\n\nimport { useTokens } from './useTokens';\n\ntype Props = {\n variant: 'deposit' | 'swap';\n};\n\nexport const useMakeQuote = ({ variant }: Props) => {\n const { ctx } = useUnsafeSnapshot();\n const { intentsAccountType } = useConfig();\n\n const isDry = !ctx.walletAddress;\n\n const { tokens: tokenList } = useTokens();\n const intentsAccountId = getIntentsAccountId({\n addressType: intentsAccountType,\n walletAddress: isDry\n ? DRY_QUOTE_ADDRESSES[intentsAccountType]\n : (ctx.walletAddress ?? ''),\n });\n\n const request = useRef<CancelablePromise<QuoteResponse>>(null);\n\n const targetWalletAddress = isDry\n ? DRY_QUOTE_ADDRESSES[intentsAccountType]\n : (ctx.walletAddress ?? '');\n\n const make = async ({ message }: { message?: string } = {}) => {\n const guardCurrentState = guardStates(ctx, [\n 'input_valid_dry',\n 'input_valid_external',\n 'input_valid_internal',\n ]);\n\n if (!guardCurrentState) {\n const msg = `Unable to run quote in current state ${ctx.state}`;\n\n logger.error(`[WIDGET] ${msg}`);\n\n throw new QuoteError({\n code: 'QUOTE_INVALID_INITIAL',\n meta: { isDry, message: msg },\n });\n }\n\n if (!intentsAccountId) {\n const msg = 'No corresponding intents account to run a quote';\n\n logger.error(`[WIDGET] ${msg}`);\n\n throw new QuoteError({\n code: 'QUOTE_INVALID_INITIAL',\n meta: { isDry, message: msg },\n });\n }\n\n if (request.current && !request.current.isCancelled) {\n request.current.cancel();\n }\n\n let quoteResponse: QuoteResponse;\n\n try {\n const commonQuoteParams = {\n // Settings\n slippageTolerance: 100, // 1%\n swapType: QuoteRequest.swapType.EXACT_INPUT,\n deadline: new Date(Date.now() + 60 * 60 * 1000).toISOString(), // 1 hour\n dry: isDry,\n\n // Source\n originAsset: ctx.sourceToken.assetId,\n amount: ctx.sourceTokenAmount,\n };\n\n if (message) {\n // @ts-expect-error customRecipientMsg is not in the types\n commonQuoteParams.customRecipientMsg = message;\n }\n\n try {\n switch (variant) {\n case 'deposit': {\n const destinationAsset = tokenList.find(\n (t) =>\n t.blockchain === 'near' && t.symbol === ctx.sourceToken.symbol,\n );\n\n if (!destinationAsset) {\n throw new QuoteError({\n code: 'NO_NEAR_TOKEN_FOUND',\n meta: { symbol: ctx.sourceToken.symbol },\n });\n }\n\n request.current = OneClickService.getQuote({\n ...commonQuoteParams,\n recipient: intentsAccountId,\n recipientType: QuoteRequest.recipientType.INTENTS,\n depositType: QuoteRequest.depositType.ORIGIN_CHAIN,\n destinationAsset: destinationAsset.assetId,\n\n // Refund\n refundTo: targetWalletAddress,\n refundType: QuoteRequest.refundType.ORIGIN_CHAIN,\n });\n\n quoteResponse = await request.current;\n break;\n }\n\n case 'swap': {\n if (ctx.sourceToken.isIntent && ctx.targetToken.isIntent) {\n request.current = OneClickService.getQuote({\n ...commonQuoteParams,\n recipient: intentsAccountId,\n recipientType: QuoteRequest.recipientType.INTENTS,\n destinationAsset: ctx.targetToken.assetId,\n depositType: QuoteRequest.depositType.INTENTS,\n\n // Refund\n refundTo: intentsAccountId,\n refundType: QuoteRequest.refundType.INTENTS,\n });\n\n quoteResponse = await request.current;\n break;\n }\n\n request.current = OneClickService.getQuote({\n ...commonQuoteParams,\n recipient:\n !ctx.targetToken.isIntent && ctx.sendAddress\n ? ctx.sendAddress\n : intentsAccountId,\n recipientType: ctx.targetToken.isIntent\n ? QuoteRequest.recipientType.INTENTS\n : QuoteRequest.recipientType.DESTINATION_CHAIN,\n destinationAsset: ctx.targetToken.assetId,\n depositType: ctx.sourceToken.isIntent\n ? QuoteRequest.depositType.INTENTS\n : QuoteRequest.depositType.ORIGIN_CHAIN,\n\n // Refund\n refundTo: ctx.sourceToken.isIntent\n ? intentsAccountId\n : targetWalletAddress,\n refundType: ctx.sourceToken.isIntent\n ? QuoteRequest.refundType.INTENTS\n : QuoteRequest.refundType.ORIGIN_CHAIN,\n });\n\n quoteResponse = await request.current;\n break;\n }\n\n default: {\n const msg = 'Unknown swap variant (deposit or swap expected)';\n\n logger.error(`[WIDGET] ${msg}`);\n\n throw new QuoteError({\n code: 'QUOTE_INVALID_INITIAL',\n meta: { isDry, message: msg },\n });\n }\n }\n } catch (error: unknown) {\n if (error instanceof CancelError) {\n return;\n }\n\n if (error instanceof ApiError) {\n logger.error(error);\n\n throw new QuoteError({\n code: 'QUOTE_INVALID',\n meta: { isDry },\n });\n }\n\n logger.error('[WIDGET] Failed to get a deposit address from the quote');\n\n throw new QuoteError({\n code: 'QUOTE_INVALID',\n meta: { isDry },\n });\n }\n\n if (\n !quoteResponse.quote.depositAddress &&\n !request.current.isCancelled &&\n !isDry\n ) {\n throw new Error('Failed to get a deposit address from the quote');\n }\n } catch (error: unknown) {\n // @ts-expect-error In case error has a message\n const errorMessage: string = error?.message;\n\n if (errorMessage.includes('Amount is too low')) {\n const match = errorMessage.match(/\\d+/);\n const minAmount = match ? match[0] : undefined;\n\n throw new QuoteError({\n code: 'QUOTE_AMOUNT_IS_TOO_LOW',\n meta: {\n minAmount:\n (minAmount &&\n formatBigToHuman(minAmount, ctx.sourceToken.decimals)) ??\n '0',\n },\n });\n }\n\n if (errorMessage.includes('recipient is not valid')) {\n throw new QuoteError({\n code: 'TOKEN_IS_NOT_SUPPORTED',\n });\n }\n\n if (errorMessage.includes('Failed to get a deposit address')) {\n throw new QuoteError({\n code: 'QUOTE_NO_ONE_TIME_ADDRESS',\n });\n }\n\n throw new QuoteError({\n code: 'QUOTE_FAILED',\n meta: {\n message: errorMessage ?? 'Failed to fetch quote. Please try again.',\n },\n });\n }\n\n let result: Quote;\n\n if (isDry) {\n result = {\n dry: true,\n ...quoteResponse.quote,\n deadline: undefined,\n depositAddress: undefined,\n };\n } else if (\n quoteResponse.quote.deadline &&\n quoteResponse.quote.depositAddress\n ) {\n result = {\n dry: false,\n ...quoteResponse.quote,\n deadline: quoteResponse.quote.deadline,\n depositAddress: quoteResponse.quote.depositAddress,\n };\n } else {\n throw new QuoteError({\n code: 'QUOTE_INVALID',\n meta: { isDry },\n });\n }\n\n return result;\n };\n\n return { make, cancel: () => request.current?.cancel() };\n};\n"],"names":["useMakeQuote","variant","ctx","useUnsafeSnapshot","intentsAccountType","useConfig","isDry","tokenList","useTokens","intentsAccountId","getIntentsAccountId","DRY_QUOTE_ADDRESSES","request","useRef","targetWalletAddress","message","guardStates","msg","logger","QuoteError","quoteResponse","commonQuoteParams","QuoteRequest","destinationAsset","t","OneClickService","error","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GAChCE,IAAYD,IAAQA,EAAM,CAAC,IAAI;AAErC,cAAM,IAAIX,EAAW;AAAA,UACnB,MAAM;AAAA,UACN,MAAM;AAAA,YACJ,YACGY,KACCC,EAAiBD,GAAW7B,EAAI,YAAY,QAAQ,MACtD;AAAA,UAAA;AAAA,QACJ,CACD;AAAA,MACH;AAEA,YAAI2B,EAAa,SAAS,wBAAwB,IAC1C,IAAIV,EAAW;AAAA,QACnB,MAAM;AAAA,MAAA,CACP,IAGCU,EAAa,SAAS,iCAAiC,IACnD,IAAIV,EAAW;AAAA,QACnB,MAAM;AAAA,MAAA,CACP,IAGG,IAAIA,EAAW;AAAA,QACnB,MAAM;AAAA,QACN,MAAM;AAAA,UACJ,SAASU,KAAgB;AAAA,QAAA;AAAA,MAC3B,CACD;AAAA,IACH;AAEA,QAAII;AAEJ,QAAI3B;AACF,MAAA2B,IAAS;AAAA,QACP,KAAK;AAAA,QACL,GAAGb,EAAc;AAAA,QACjB,UAAU;AAAA,QACV,gBAAgB;AAAA,MAAA;AAAA,aAGlBA,EAAc,MAAM,YACpBA,EAAc,MAAM;AAEpB,MAAAa,IAAS;AAAA,QACP,KAAK;AAAA,QACL,GAAGb,EAAc;AAAA,QACjB,UAAUA,EAAc,MAAM;AAAA,QAC9B,gBAAgBA,EAAc,MAAM;AAAA,MAAA;AAAA;AAGtC,YAAM,IAAID,EAAW;AAAA,QACnB,MAAM;AAAA,QACN,MAAM,EAAE,OAAAb,EAAA;AAAA,MAAM,CACf;AAGH,WAAO2B;AAAA,EACT,GAEe,QAAQ,MAAMrB,EAAQ,SAAS,SAAO;AACvD;"}
1
+ {"version":3,"file":"useMakeQuote.js","sources":["../../src/hooks/useMakeQuote.ts"],"sourcesContent":["import { useRef } from 'react';\nimport {\n ApiError,\n CancelablePromise,\n CancelError,\n OneClickService,\n QuoteRequest,\n QuoteResponse,\n} from '@defuse-protocol/one-click-sdk-typescript';\n\nimport { logger } from '@/logger';\nimport { useConfig } from '@/config';\nimport { QuoteError } from '@/errors';\nimport { guardStates } from '@/machine/guards';\nimport { useUnsafeSnapshot } from '@/machine/snap';\nimport { getIntentsAccountId } from '@/utils/intents/getIntentsAccountId';\nimport { formatBigToHuman } from '@/utils/formatters/formatBigToHuman';\nimport { DRY_QUOTE_ADDRESSES } from '@/constants/chains';\nimport { Quote } from '@/types/quote';\n\nimport { useTokens } from './useTokens';\n\ntype Props = {\n variant: 'deposit' | 'swap';\n};\n\nexport const useMakeQuote = ({ variant }: Props) => {\n const { ctx } = useUnsafeSnapshot();\n const { intentsAccountType } = useConfig();\n\n const isDry = !ctx.walletAddress;\n\n const { tokens: tokenList } = useTokens();\n const intentsAccountId = getIntentsAccountId({\n addressType: intentsAccountType,\n walletAddress: isDry\n ? DRY_QUOTE_ADDRESSES[intentsAccountType]\n : (ctx.walletAddress ?? ''),\n });\n\n const request = useRef<CancelablePromise<QuoteResponse>>(null);\n\n const targetWalletAddress = isDry\n ? DRY_QUOTE_ADDRESSES[intentsAccountType]\n : (ctx.walletAddress ?? '');\n\n const make = async ({ message }: { message?: string } = {}) => {\n const guardCurrentState = guardStates(ctx, [\n 'input_valid_dry',\n 'input_valid_external',\n 'input_valid_internal',\n ]);\n\n if (!guardCurrentState) {\n const msg = `Unable to run quote in current state ${ctx.state}`;\n\n logger.error(`[WIDGET] ${msg}`);\n\n throw new QuoteError({\n code: 'QUOTE_INVALID_INITIAL',\n meta: { isDry, message: msg },\n });\n }\n\n if (!intentsAccountId) {\n const msg = 'No corresponding intents account to run a quote';\n\n logger.error(`[WIDGET] ${msg}`);\n\n throw new QuoteError({\n code: 'QUOTE_INVALID_INITIAL',\n meta: { isDry, message: msg },\n });\n }\n\n if (request.current && !request.current.isCancelled) {\n request.current.cancel();\n }\n\n let quoteResponse: QuoteResponse;\n\n try {\n const commonQuoteParams = {\n // Settings\n slippageTolerance: 100, // 1%\n swapType: QuoteRequest.swapType.EXACT_INPUT,\n deadline: new Date(Date.now() + 60 * 60 * 1000).toISOString(), // 1 hour\n dry: isDry,\n\n // Source\n originAsset: ctx.sourceToken.assetId,\n amount: ctx.sourceTokenAmount,\n };\n\n if (message) {\n // @ts-expect-error customRecipientMsg is not in the types\n commonQuoteParams.customRecipientMsg = message;\n }\n\n try {\n switch (variant) {\n case 'deposit': {\n const destinationAsset = tokenList.find(\n (t) =>\n t.blockchain === 'near' && t.symbol === ctx.sourceToken.symbol,\n );\n\n if (!destinationAsset) {\n throw new QuoteError({\n code: 'NO_NEAR_TOKEN_FOUND',\n meta: { symbol: ctx.sourceToken.symbol },\n });\n }\n\n request.current = OneClickService.getQuote({\n ...commonQuoteParams,\n recipient: intentsAccountId,\n recipientType: QuoteRequest.recipientType.INTENTS,\n depositType: QuoteRequest.depositType.ORIGIN_CHAIN,\n destinationAsset: destinationAsset.assetId,\n\n // Refund\n refundTo: targetWalletAddress,\n refundType: QuoteRequest.refundType.ORIGIN_CHAIN,\n });\n\n quoteResponse = await request.current;\n break;\n }\n\n case 'swap': {\n if (ctx.sourceToken.isIntent && ctx.targetToken.isIntent) {\n request.current = OneClickService.getQuote({\n ...commonQuoteParams,\n recipient: intentsAccountId,\n recipientType: QuoteRequest.recipientType.INTENTS,\n destinationAsset: ctx.targetToken.assetId,\n depositType: QuoteRequest.depositType.INTENTS,\n\n // Refund\n refundTo: intentsAccountId,\n refundType: QuoteRequest.refundType.INTENTS,\n });\n\n quoteResponse = await request.current;\n break;\n }\n\n request.current = OneClickService.getQuote({\n ...commonQuoteParams,\n recipient:\n !ctx.targetToken.isIntent && ctx.sendAddress\n ? ctx.sendAddress\n : intentsAccountId,\n recipientType: ctx.targetToken.isIntent\n ? QuoteRequest.recipientType.INTENTS\n : QuoteRequest.recipientType.DESTINATION_CHAIN,\n destinationAsset: ctx.targetToken.assetId,\n depositType: ctx.sourceToken.isIntent\n ? QuoteRequest.depositType.INTENTS\n : QuoteRequest.depositType.ORIGIN_CHAIN,\n\n // Refund\n refundTo: ctx.sourceToken.isIntent\n ? intentsAccountId\n : targetWalletAddress,\n refundType: ctx.sourceToken.isIntent\n ? QuoteRequest.refundType.INTENTS\n : QuoteRequest.refundType.ORIGIN_CHAIN,\n });\n\n quoteResponse = await request.current;\n break;\n }\n\n default: {\n const msg = 'Unknown swap variant (deposit or swap expected)';\n\n logger.error(`[WIDGET] ${msg}`);\n\n throw new QuoteError({\n code: 'QUOTE_INVALID_INITIAL',\n meta: { isDry, message: msg },\n });\n }\n }\n } catch (error: unknown) {\n if (error instanceof CancelError) {\n return;\n }\n\n if (error instanceof ApiError) {\n logger.error(error);\n throw error;\n }\n\n logger.error('[WIDGET] Failed to get a deposit address from the quote');\n\n throw new QuoteError({\n code: 'QUOTE_INVALID',\n meta: { isDry },\n });\n }\n\n if (\n !quoteResponse.quote.depositAddress &&\n !request.current.isCancelled &&\n !isDry\n ) {\n throw new Error('Failed to get a deposit address from the quote');\n }\n } catch (error: unknown) {\n if (error instanceof ApiError) {\n const errorMessage = error.body.message ?? error.message;\n\n if (errorMessage.includes('Amount is too low')) {\n const match = errorMessage.match(/\\d+/);\n const minAmount = match ? match[0] : undefined;\n\n throw new QuoteError({\n code: 'QUOTE_AMOUNT_IS_TOO_LOW',\n meta: {\n minAmount:\n (minAmount &&\n formatBigToHuman(minAmount, ctx.sourceToken.decimals)) ??\n '0',\n },\n });\n }\n\n if (errorMessage.includes('recipient is not valid')) {\n throw new QuoteError({\n code: 'TOKEN_IS_NOT_SUPPORTED',\n });\n }\n\n if (errorMessage.includes('Failed to get a deposit address')) {\n throw new QuoteError({\n code: 'QUOTE_NO_ONE_TIME_ADDRESS',\n });\n }\n\n throw error;\n }\n\n throw new QuoteError({\n code: 'QUOTE_FAILED',\n meta: {\n // @ts-expect-error In case error has a message\n message: error?.message ?? 'Failed to fetch quote. Please try again.',\n },\n });\n }\n\n let result: Quote;\n\n if (isDry) {\n result = {\n dry: true,\n ...quoteResponse.quote,\n deadline: undefined,\n depositAddress: undefined,\n };\n } else if (\n quoteResponse.quote.deadline &&\n quoteResponse.quote.depositAddress\n ) {\n result = {\n dry: false,\n ...quoteResponse.quote,\n deadline: quoteResponse.quote.deadline,\n depositAddress: quoteResponse.quote.depositAddress,\n };\n } else {\n throw new QuoteError({\n code: 'QUOTE_INVALID',\n meta: { isDry },\n });\n }\n\n return result;\n };\n\n return { make, cancel: () => request.current?.cancel() };\n};\n"],"names":["useMakeQuote","variant","ctx","useUnsafeSnapshot","intentsAccountType","useConfig","isDry","tokenList","useTokens","intentsAccountId","getIntentsAccountId","DRY_QUOTE_ADDRESSES","request","useRef","targetWalletAddress","message","guardStates","msg","logger","QuoteError","quoteResponse","commonQuoteParams","QuoteRequest","destinationAsset","t","OneClickService","error","CancelError","ApiError","errorMessage","match","minAmount","formatBigToHuman","result"],"mappings":";;;;;;;;;;;AA0BO,MAAMA,IAAe,CAAC,EAAE,SAAAC,QAAqB;AAClD,QAAM,EAAE,KAAAC,EAAA,IAAQC,EAAA,GACV,EAAE,oBAAAC,EAAA,IAAuBC,EAAA,GAEzBC,IAAQ,CAACJ,EAAI,eAEb,EAAE,QAAQK,EAAA,IAAcC,EAAA,GACxBC,IAAmBC,EAAoB;AAAA,IAC3C,aAAaN;AAAA,IACb,eAAeE,IACXK,EAAoBP,CAAkB,IACrCF,EAAI,iBAAiB;AAAA,EAAA,CAC3B,GAEKU,IAAUC,EAAyC,IAAI,GAEvDC,IAAsBR,IACxBK,EAAoBP,CAAkB,IACrCF,EAAI,iBAAiB;AA+O1B,SAAO,EAAE,MA7OI,OAAO,EAAE,SAAAa,EAAA,IAAkC,CAAA,MAAO;AAO7D,QAAI,CANsBC,EAAYd,GAAK;AAAA,MACzC;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD,GAEuB;AACtB,YAAMe,IAAM,wCAAwCf,EAAI,KAAK;AAE7D,YAAAgB,EAAO,MAAM,YAAYD,CAAG,EAAE,GAExB,IAAIE,EAAW;AAAA,QACnB,MAAM;AAAA,QACN,MAAM,EAAE,OAAAb,GAAO,SAASW,EAAA;AAAA,MAAI,CAC7B;AAAA,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AAM,IAAID,EAAW;AAAA,QACnB,MAAM;AAAA,QACN,MAAM,EAAE,OAAAb,EAAA;AAAA,MAAM,CACf;AAGH,WAAO2B;AAAA,EACT,GAEe,QAAQ,MAAMrB,EAAQ,SAAS,SAAO;AACvD;"}
@@ -77,3 +77,7 @@ export type QuoteSuccessTransferError = {
77
77
  };
78
78
  export type QuoteSuccessError = QuoteSuccessDirectTransferError | QuoteSuccessTransferError;
79
79
  export type ErrorType = InitialDryStateError | InitialInternalStateError | InitialExternalStateError | InputValidDryError | InputValidWalletError | QuoteSuccessError;
80
+ export declare const QUOTE_ERRORS: Array<InputValidDryError['code'] | InputValidWalletError['code']>;
81
+ export declare const TRANSFER_ERRORS: Array<QuoteSuccessDirectTransferError['code'] | QuoteSuccessTransferError['code']>;
82
+ export declare const isQuoteError: (error: ErrorType) => error is InputValidDryError | InputValidWalletError;
83
+ export declare const isTransferError: (error: ErrorType) => error is QuoteSuccessError;
@@ -1,2 +1,24 @@
1
-
1
+ const _ = [
2
+ "NO_NEAR_TOKEN_FOUND",
3
+ "TOKEN_IS_NOT_SUPPORTED",
4
+ "QUOTE_FAILED",
5
+ "QUOTE_INVALID",
6
+ "QUOTE_INVALID_INITIAL",
7
+ "QUOTE_AMOUNT_IS_TOO_LOW",
8
+ "QUOTE_NO_ONE_TIME_ADDRESS"
9
+ ], O = [
10
+ "DIRECT_TRANSFER_ERROR",
11
+ "BRIDGE_SDK_FAILED",
12
+ "FEES_NOT_ESTIMATED",
13
+ "NO_QUOTE_FOUND",
14
+ "NO_DEPOSIT_RESULT",
15
+ "QUOTE_ERROR",
16
+ "TRANSFER_INVALID_INITIAL"
17
+ ], T = (E) => _.includes(E.code), R = (E) => O.includes(E.code);
18
+ export {
19
+ _ as QUOTE_ERRORS,
20
+ O as TRANSFER_ERRORS,
21
+ T as isQuoteError,
22
+ R as isTransferError
23
+ };
2
24
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"errors.js","sources":["../../src/machine/errors.ts"],"sourcesContent":["export type InitialDryStateError =\n | { code: 'SOURCE_TOKEN_IS_EMPTY' }\n | { code: 'TARGET_TOKEN_IS_EMPTY' }\n | { code: 'SOURCE_TOKEN_AMOUNT_IS_EMPTY' };\n\nexport type InitialInternalStateError =\n | InitialDryStateError\n | { code: 'SOURCE_TOKEN_NOT_INTENT' }\n | { code: 'SOURCE_BALANCE_INSUFFICIENT' }\n | { code: 'INVALID_SOURCE_BALANCE' };\n\nexport type InitialExternalStateError =\n | InitialDryStateError\n | { code: 'SOURCE_TOKEN_IS_INTENT' }\n | { code: 'SOURCE_BALANCE_INSUFFICIENT' }\n | { code: 'INVALID_SOURCE_BALANCE' }\n | { code: 'SEND_ADDRESS_IS_EMPTY' };\n\nexport type InputValidDryError =\n | { code: 'NO_NEAR_TOKEN_FOUND'; meta: { symbol: string } }\n | { code: 'TOKEN_IS_NOT_SUPPORTED' }\n | { code: 'QUOTE_FAILED'; meta: { message: string } }\n | { code: 'QUOTE_INVALID'; meta: { isDry: boolean } }\n | { code: 'QUOTE_INVALID_INITIAL'; meta: { isDry: boolean; message: string } }\n | {\n code: 'QUOTE_AMOUNT_IS_TOO_LOW';\n meta: { minAmount?: string };\n };\n\nexport type InputValidWalletError =\n | InputValidDryError\n | { code: 'QUOTE_NO_ONE_TIME_ADDRESS' };\n\nexport type QuoteSuccessDirectTransferError =\n | { code: 'DIRECT_TRANSFER_ERROR' }\n | { code: 'BRIDGE_SDK_FAILED' }\n | { code: 'FEES_NOT_ESTIMATED' };\n\nexport type QuoteSuccessTransferError =\n | { code: 'NO_QUOTE_FOUND' }\n | { code: 'NO_DEPOSIT_RESULT' }\n | { code: 'QUOTE_ERROR'; meta: { message: string } }\n | { code: 'TRANSFER_INVALID_INITIAL'; meta: { message: string } };\n\nexport type QuoteSuccessError =\n | QuoteSuccessDirectTransferError\n | QuoteSuccessTransferError;\n\nexport type ErrorType =\n | InitialDryStateError\n | InitialInternalStateError\n | InitialExternalStateError\n | InputValidDryError\n | InputValidWalletError\n | QuoteSuccessError;\n\nexport const QUOTE_ERRORS: Array<\n InputValidDryError['code'] | InputValidWalletError['code']\n> = [\n 'NO_NEAR_TOKEN_FOUND',\n 'TOKEN_IS_NOT_SUPPORTED',\n 'QUOTE_FAILED',\n 'QUOTE_INVALID',\n 'QUOTE_INVALID_INITIAL',\n 'QUOTE_AMOUNT_IS_TOO_LOW',\n 'QUOTE_NO_ONE_TIME_ADDRESS',\n];\n\nexport const TRANSFER_ERRORS: Array<\n QuoteSuccessDirectTransferError['code'] | QuoteSuccessTransferError['code']\n> = [\n 'DIRECT_TRANSFER_ERROR',\n 'BRIDGE_SDK_FAILED',\n 'FEES_NOT_ESTIMATED',\n 'NO_QUOTE_FOUND',\n 'NO_DEPOSIT_RESULT',\n 'QUOTE_ERROR',\n 'TRANSFER_INVALID_INITIAL',\n];\n\nexport const isQuoteError = (\n error: ErrorType,\n): error is InputValidDryError | InputValidWalletError => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return QUOTE_ERRORS.includes(error.code as any);\n};\n\nexport const isTransferError = (\n error: ErrorType,\n): error is QuoteSuccessError => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return TRANSFER_ERRORS.includes(error.code as any);\n};\n"],"names":["QUOTE_ERRORS","TRANSFER_ERRORS","isQuoteError","error","isTransferError"],"mappings":"AAwDO,MAAMA,IAET;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEaC,IAET;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEaC,IAAe,CAC1BC,MAGOH,EAAa,SAASG,EAAM,IAAW,GAGnCC,IAAkB,CAC7BD,MAGOF,EAAgB,SAASE,EAAM,IAAW;"}
@@ -1,32 +1,33 @@
1
- import { isNotEmptyAmount as s } from "../../utils/checkers/isNotEmptyAmount.js";
2
- import { isValidBigint as _ } from "../../utils/checkers/isValidBigint.js";
3
- import { guardStates as n } from "../guards/index.js";
4
- import { isBalanceSufficient as a } from "../guards/checks/isBalanceSufficient.js";
5
- import { fireEvent as l } from "./utils/fireEvent.js";
6
- const I = (e) => {
7
- const r = n(e, ["initial_dry"]), o = n(e, ["input_valid_dry"]);
8
- if (!r && !o)
1
+ import { isNotEmptyAmount as l } from "../../utils/checkers/isNotEmptyAmount.js";
2
+ import { isValidBigint as E } from "../../utils/checkers/isValidBigint.js";
3
+ import { guardStates as t } from "../guards/index.js";
4
+ import { isBalanceSufficient as T } from "../guards/checks/isBalanceSufficient.js";
5
+ import { isQuoteError as a, isTransferError as _ } from "../errors.js";
6
+ import { fireEvent as s } from "./utils/fireEvent.js";
7
+ const O = (e) => {
8
+ const n = t(e, ["initial_dry"]), i = t(e, ["input_valid_dry"]);
9
+ if (!n && !i)
9
10
  return;
10
- let t;
11
- return r && (e.sourceToken ? e.targetToken ? s(e.sourceTokenAmount) || (t = { code: "SOURCE_TOKEN_AMOUNT_IS_EMPTY" }) : t = { code: "TARGET_TOKEN_IS_EMPTY" } : t = { code: "SOURCE_TOKEN_IS_EMPTY" }), !o && t ? l("errorSet", t) : l("errorSet", null), o;
12
- }, u = (e) => {
13
- const r = n(e, ["initial_wallet"]), o = n(e, ["input_valid_external"]);
14
- if (!r && !o)
11
+ let o;
12
+ return n && (e.sourceToken ? e.targetToken ? l(e.sourceTokenAmount) || (o = { code: "SOURCE_TOKEN_AMOUNT_IS_EMPTY" }) : o = { code: "TARGET_TOKEN_IS_EMPTY" } : o = { code: "SOURCE_TOKEN_IS_EMPTY" }), !i && o ? s("errorSet", o) : e.error && !a(e.error) && !_(e.error) && s("errorSet", null), i;
13
+ }, A = (e) => {
14
+ const n = t(e, ["initial_wallet"]), i = t(e, ["input_valid_external"]);
15
+ if (!n && !i)
15
16
  return;
16
- const t = e.sourceTokenBalance;
17
- let i;
18
- return r && (e.sourceToken ? e.targetToken ? e.targetToken.isIntent ? i = { code: "SOURCE_TOKEN_IS_INTENT" } : s(e.sourceTokenAmount) ? e.sendAddress ? e.isDepositFromExternalWallet || (!t || !_(t) ? i = { code: "INVALID_SOURCE_BALANCE" } : a(e) || (i = { code: "SOURCE_BALANCE_INSUFFICIENT" })) : i = { code: "SEND_ADDRESS_IS_EMPTY" } : i = { code: "SOURCE_TOKEN_AMOUNT_IS_EMPTY" } : i = { code: "TARGET_TOKEN_IS_EMPTY" } : i = { code: "SOURCE_TOKEN_IS_EMPTY" }), !o && i ? l("errorSet", i) : l("errorSet", null), o;
19
- }, N = (e) => {
20
- const r = n(e, ["initial_wallet"]), o = n(e, ["input_valid_internal"]);
21
- if (!r && !o)
17
+ const o = e.sourceTokenBalance;
18
+ let r;
19
+ return n && (e.sourceToken ? e.targetToken ? e.targetToken.isIntent ? r = { code: "SOURCE_TOKEN_IS_INTENT" } : l(e.sourceTokenAmount) ? e.sendAddress ? e.isDepositFromExternalWallet || (!o || !E(o) ? r = { code: "INVALID_SOURCE_BALANCE" } : T(e) || (r = { code: "SOURCE_BALANCE_INSUFFICIENT" })) : r = { code: "SEND_ADDRESS_IS_EMPTY" } : r = { code: "SOURCE_TOKEN_AMOUNT_IS_EMPTY" } : r = { code: "TARGET_TOKEN_IS_EMPTY" } : r = { code: "SOURCE_TOKEN_IS_EMPTY" }), !i && r ? s("errorSet", r) : e.error && !a(e.error) && !_(e.error) && s("errorSet", null), i;
20
+ }, m = (e) => {
21
+ const n = t(e, ["initial_wallet"]), i = t(e, ["input_valid_internal"]);
22
+ if (!n && !i)
22
23
  return;
23
- const t = e.sourceTokenBalance;
24
- let i;
25
- return r && (e.sourceToken ? e.targetToken ? e.targetToken.isIntent ? s(e.sourceTokenAmount) ? e.isDepositFromExternalWallet || (!t || !_(t) ? i = { code: "INVALID_SOURCE_BALANCE" } : a(e) || (i = { code: "SOURCE_BALANCE_INSUFFICIENT" })) : i = { code: "SOURCE_TOKEN_AMOUNT_IS_EMPTY" } : i = { code: "SOURCE_TOKEN_NOT_INTENT" } : i = { code: "TARGET_TOKEN_IS_EMPTY" } : i = { code: "SOURCE_TOKEN_IS_EMPTY" }), !o && i ? l("errorSet", i) : l("errorSet", null), o;
24
+ const o = e.sourceTokenBalance;
25
+ let r;
26
+ return n && (e.sourceToken ? e.targetToken ? e.targetToken.isIntent ? l(e.sourceTokenAmount) ? e.isDepositFromExternalWallet || (!o || !E(o) ? r = { code: "INVALID_SOURCE_BALANCE" } : T(e) || (r = { code: "SOURCE_BALANCE_INSUFFICIENT" })) : r = { code: "SOURCE_TOKEN_AMOUNT_IS_EMPTY" } : r = { code: "SOURCE_TOKEN_NOT_INTENT" } : r = { code: "TARGET_TOKEN_IS_EMPTY" } : r = { code: "SOURCE_TOKEN_IS_EMPTY" }), !i && r ? s("errorSet", r) : e.error && !a(e.error) && !_(e.error) && s("errorSet", null), i;
26
27
  };
27
28
  export {
28
- I as validateDryInputs,
29
- u as validateExternalInputs,
30
- N as validateInternalInputs
29
+ O as validateDryInputs,
30
+ A as validateExternalInputs,
31
+ m as validateInternalInputs
31
32
  };
32
33
  //# sourceMappingURL=validateInputs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateInputs.js","sources":["../../../src/machine/events/validateInputs.ts"],"sourcesContent":["import { isNotEmptyAmount } from '@/utils/checkers/isNotEmptyAmount';\nimport { isValidBigint } from '@/utils/checkers/isValidBigint';\n\nimport { guardStates } from '@/machine/guards';\nimport { isBalanceSufficient } from '@/machine/guards/checks/isBalanceSufficient';\nimport type { Context } from '@/machine/context';\nimport type {\n InitialDryStateError,\n InitialExternalStateError,\n InitialInternalStateError,\n} from '@/machine/errors';\n\nimport { fireEvent } from './utils/fireEvent';\n\nexport const validateDryInputs = (ctx: Context): boolean | undefined => {\n const isValidInitialState = guardStates(ctx, ['initial_dry']);\n const isValidInputsState = guardStates(ctx, ['input_valid_dry']);\n\n if (!isValidInitialState && !isValidInputsState) {\n return undefined;\n }\n\n let err: InitialDryStateError | undefined;\n\n if (isValidInitialState) {\n if (!ctx.sourceToken) {\n err = { code: 'SOURCE_TOKEN_IS_EMPTY' };\n } else if (!ctx.targetToken) {\n err = { code: 'TARGET_TOKEN_IS_EMPTY' };\n } else if (!isNotEmptyAmount(ctx.sourceTokenAmount)) {\n err = { code: 'SOURCE_TOKEN_AMOUNT_IS_EMPTY' };\n }\n }\n\n if (!isValidInputsState && err) {\n fireEvent('errorSet', err);\n } else {\n fireEvent('errorSet', null);\n }\n\n return isValidInputsState;\n};\n\nexport const validateExternalInputs = (ctx: Context): boolean | undefined => {\n const isValidInitialState = guardStates(ctx, ['initial_wallet']);\n const isValidInputsState = guardStates(ctx, ['input_valid_external']);\n\n if (!isValidInitialState && !isValidInputsState) {\n return undefined;\n }\n\n const sourceBalance = ctx.sourceTokenBalance;\n let err: InitialExternalStateError | undefined;\n\n if (isValidInitialState) {\n if (!ctx.sourceToken) {\n err = { code: 'SOURCE_TOKEN_IS_EMPTY' };\n } else if (!ctx.targetToken) {\n err = { code: 'TARGET_TOKEN_IS_EMPTY' };\n } else if (ctx.targetToken.isIntent) {\n err = { code: 'SOURCE_TOKEN_IS_INTENT' };\n } else if (!isNotEmptyAmount(ctx.sourceTokenAmount)) {\n err = { code: 'SOURCE_TOKEN_AMOUNT_IS_EMPTY' };\n } else if (!ctx.sendAddress) {\n err = { code: 'SEND_ADDRESS_IS_EMPTY' };\n } else if (!ctx.isDepositFromExternalWallet) {\n if (!sourceBalance || !isValidBigint(sourceBalance)) {\n err = { code: 'INVALID_SOURCE_BALANCE' };\n } else if (!isBalanceSufficient(ctx)) {\n err = { code: 'SOURCE_BALANCE_INSUFFICIENT' };\n }\n }\n }\n\n if (!isValidInputsState && err) {\n fireEvent('errorSet', err);\n } else {\n fireEvent('errorSet', null);\n }\n\n return isValidInputsState;\n};\n\nexport const validateInternalInputs = (ctx: Context): boolean | undefined => {\n const isValidInitialState = guardStates(ctx, ['initial_wallet']);\n const isValidInputsState = guardStates(ctx, ['input_valid_internal']);\n\n if (!isValidInitialState && !isValidInputsState) {\n return undefined;\n }\n\n const sourceBalance = ctx.sourceTokenBalance;\n let err: InitialInternalStateError | undefined;\n\n if (isValidInitialState) {\n if (!ctx.sourceToken) {\n err = { code: 'SOURCE_TOKEN_IS_EMPTY' };\n } else if (!ctx.targetToken) {\n err = { code: 'TARGET_TOKEN_IS_EMPTY' };\n } else if (!ctx.targetToken.isIntent) {\n err = { code: 'SOURCE_TOKEN_NOT_INTENT' };\n } else if (!isNotEmptyAmount(ctx.sourceTokenAmount)) {\n err = { code: 'SOURCE_TOKEN_AMOUNT_IS_EMPTY' };\n } else if (!ctx.isDepositFromExternalWallet) {\n if (!sourceBalance || !isValidBigint(sourceBalance)) {\n err = { code: 'INVALID_SOURCE_BALANCE' };\n } else if (!isBalanceSufficient(ctx)) {\n err = { code: 'SOURCE_BALANCE_INSUFFICIENT' };\n }\n }\n }\n\n if (!isValidInputsState && err) {\n fireEvent('errorSet', err);\n } else {\n fireEvent('errorSet', null);\n }\n\n return isValidInputsState;\n};\n"],"names":["validateDryInputs","ctx","isValidInitialState","guardStates","isValidInputsState","err","isNotEmptyAmount","fireEvent","validateExternalInputs","sourceBalance","isValidBigint","isBalanceSufficient","validateInternalInputs"],"mappings":";;;;;AAcO,MAAMA,IAAoB,CAACC,MAAsC;AACtE,QAAMC,IAAsBC,EAAYF,GAAK,CAAC,aAAa,CAAC,GACtDG,IAAqBD,EAAYF,GAAK,CAAC,iBAAiB,CAAC;AAE/D,MAAI,CAACC,KAAuB,CAACE;AAC3B;AAGF,MAAIC;AAEJ,SAAIH,MACGD,EAAI,cAEGA,EAAI,cAEJK,EAAiBL,EAAI,iBAAiB,MAChDI,IAAM,EAAE,MAAM,+BAAA,KAFdA,IAAM,EAAE,MAAM,wBAAA,IAFdA,IAAM,EAAE,MAAM,wBAAA,IAQd,CAACD,KAAsBC,IACzBE,EAAU,YAAYF,CAAG,IAEzBE,EAAU,YAAY,IAAI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AFdA,IAAM,EAAE,MAAM,wBAAA,IAFdA,IAAM,EAAE,MAAM,wBAAA,IAgBd,CAACD,KAAsBC,IACzBE,EAAU,YAAYF,CAAG,IAEzBE,EAAU,YAAY,IAAI,GAGrBH;AACT;"}
1
+ {"version":3,"file":"validateInputs.js","sources":["../../../src/machine/events/validateInputs.ts"],"sourcesContent":["import { isNotEmptyAmount } from '@/utils/checkers/isNotEmptyAmount';\nimport { isValidBigint } from '@/utils/checkers/isValidBigint';\n\nimport { guardStates } from '@/machine/guards';\nimport { isBalanceSufficient } from '@/machine/guards/checks/isBalanceSufficient';\nimport { isQuoteError, isTransferError } from '@/machine/errors';\nimport type { Context } from '@/machine/context';\nimport type {\n InitialDryStateError,\n InitialExternalStateError,\n InitialInternalStateError,\n} from '@/machine/errors';\n\nimport { fireEvent } from './utils/fireEvent';\n\nexport const validateDryInputs = (ctx: Context): boolean | undefined => {\n const isValidInitialState = guardStates(ctx, ['initial_dry']);\n const isValidInputsState = guardStates(ctx, ['input_valid_dry']);\n\n if (!isValidInitialState && !isValidInputsState) {\n return undefined;\n }\n\n let err: InitialDryStateError | undefined;\n\n if (isValidInitialState) {\n if (!ctx.sourceToken) {\n err = { code: 'SOURCE_TOKEN_IS_EMPTY' };\n } else if (!ctx.targetToken) {\n err = { code: 'TARGET_TOKEN_IS_EMPTY' };\n } else if (!isNotEmptyAmount(ctx.sourceTokenAmount)) {\n err = { code: 'SOURCE_TOKEN_AMOUNT_IS_EMPTY' };\n }\n }\n\n if (!isValidInputsState && err) {\n fireEvent('errorSet', err);\n } else if (\n ctx.error &&\n !isQuoteError(ctx.error) &&\n !isTransferError(ctx.error)\n ) {\n fireEvent('errorSet', null);\n }\n\n return isValidInputsState;\n};\n\nexport const validateExternalInputs = (ctx: Context): boolean | undefined => {\n const isValidInitialState = guardStates(ctx, ['initial_wallet']);\n const isValidInputsState = guardStates(ctx, ['input_valid_external']);\n\n if (!isValidInitialState && !isValidInputsState) {\n return undefined;\n }\n\n const sourceBalance = ctx.sourceTokenBalance;\n let err: InitialExternalStateError | undefined;\n\n if (isValidInitialState) {\n if (!ctx.sourceToken) {\n err = { code: 'SOURCE_TOKEN_IS_EMPTY' };\n } else if (!ctx.targetToken) {\n err = { code: 'TARGET_TOKEN_IS_EMPTY' };\n } else if (ctx.targetToken.isIntent) {\n err = { code: 'SOURCE_TOKEN_IS_INTENT' };\n } else if (!isNotEmptyAmount(ctx.sourceTokenAmount)) {\n err = { code: 'SOURCE_TOKEN_AMOUNT_IS_EMPTY' };\n } else if (!ctx.sendAddress) {\n err = { code: 'SEND_ADDRESS_IS_EMPTY' };\n } else if (!ctx.isDepositFromExternalWallet) {\n if (!sourceBalance || !isValidBigint(sourceBalance)) {\n err = { code: 'INVALID_SOURCE_BALANCE' };\n } else if (!isBalanceSufficient(ctx)) {\n err = { code: 'SOURCE_BALANCE_INSUFFICIENT' };\n }\n }\n }\n\n if (!isValidInputsState && err) {\n fireEvent('errorSet', err);\n } else if (\n ctx.error &&\n !isQuoteError(ctx.error) &&\n !isTransferError(ctx.error)\n ) {\n fireEvent('errorSet', null);\n }\n\n return isValidInputsState;\n};\n\nexport const validateInternalInputs = (ctx: Context): boolean | undefined => {\n const isValidInitialState = guardStates(ctx, ['initial_wallet']);\n const isValidInputsState = guardStates(ctx, ['input_valid_internal']);\n\n if (!isValidInitialState && !isValidInputsState) {\n return undefined;\n }\n\n const sourceBalance = ctx.sourceTokenBalance;\n let err: InitialInternalStateError | undefined;\n\n if (isValidInitialState) {\n if (!ctx.sourceToken) {\n err = { code: 'SOURCE_TOKEN_IS_EMPTY' };\n } else if (!ctx.targetToken) {\n err = { code: 'TARGET_TOKEN_IS_EMPTY' };\n } else if (!ctx.targetToken.isIntent) {\n err = { code: 'SOURCE_TOKEN_NOT_INTENT' };\n } else if (!isNotEmptyAmount(ctx.sourceTokenAmount)) {\n err = { code: 'SOURCE_TOKEN_AMOUNT_IS_EMPTY' };\n } else if (!ctx.isDepositFromExternalWallet) {\n if (!sourceBalance || !isValidBigint(sourceBalance)) {\n err = { code: 'INVALID_SOURCE_BALANCE' };\n } else if (!isBalanceSufficient(ctx)) {\n err = { code: 'SOURCE_BALANCE_INSUFFICIENT' };\n }\n }\n }\n\n if (!isValidInputsState && err) {\n fireEvent('errorSet', err);\n } else if (\n ctx.error &&\n !isQuoteError(ctx.error) &&\n !isTransferError(ctx.error)\n ) {\n fireEvent('errorSet', null);\n }\n\n return isValidInputsState;\n};\n"],"names":["validateDryInputs","ctx","isValidInitialState","guardStates","isValidInputsState","err","isNotEmptyAmount","fireEvent","isQuoteError","isTransferError","validateExternalInputs","sourceBalance","isValidBigint","isBalanceSufficient","validateInternalInputs"],"mappings":";;;;;;AAeO,MAAMA,IAAoB,CAACC,MAAsC;AACtE,QAAMC,IAAsBC,EAAYF,GAAK,CAAC,aAAa,CAAC,GACtDG,IAAqBD,EAAYF,GAAK,CAAC,iBAAiB,CAAC;AAE/D,MAAI,CAACC,KAAuB,CAACE;AAC3B;AAGF,MAAIC;AAEJ,SAAIH,MACGD,EAAI,cAEGA,EAAI,cAEJK,EAAiBL,EAAI,iBAAiB,MAChDI,IAAM,EAAE,MAAM,+BAAA,KAFdA,IAAM,EAAE,MAAM,wBAAA,IAFdA,IAAM,EAAE,MAAM,wBAAA,IAQd,CAACD,KAAsBC,IACzBE,EAAU,YAAYF,CAAG,IAEzBJ,EAAI,SACJ,CAACO,EAAaP,EAAI,KAAK,KACvB,CAACQ,EAAgBR,EAAI,KAAK,KAE1BM,EAAU,YAAY,IAAI,GAGrBH;AACT,GAEaM,IAAyB,CAACT,MAAsC;AAC3E,QAAMC,IAAsBC,EAAYF,GAAK,CAAC,gBAAgB,CAAC,GACzDG,IAAqBD,EAAYF,GAAK,CAAC,sBAAsB,CAAC;AAEpE,MAAI,CAACC,KAAuB,CAACE;AAC3B;AAGF,QAAMO,IAAgBV,EAAI;AAC1B,MAAII;AAEJ,SAAIH,MACGD,EAAI,cAEGA,EAAI,cAELA,EAAI,YAAY,WACzBI,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AAI,GAGrBH;AACT;"}
@@ -1,12 +1,14 @@
1
- const a = ({
2
- tokens: e,
3
- walletSupportedChains: i
4
- }) => i.includes("near") ? e.find(
1
+ const e = ({
2
+ tokens: i,
3
+ walletSupportedChains: a
4
+ }) => a.includes("near") ? i.find(
5
5
  (n) => !n.isIntent && n.name === "Near" && n.blockchain === "near"
6
- ) ?? e[0] : e.find(
6
+ ) ?? i[0] : a.includes("sol") ? i.find(
7
+ (n) => !n.isIntent && n.name === "Solana" && n.blockchain === "sol"
8
+ ) ?? i[0] : i.find(
7
9
  (n) => !n.isIntent && n.name === "ETH" && n.blockchain === "eth"
8
- ) ?? e[0];
10
+ ) ?? i[0];
9
11
  export {
10
- a as getMainTokenByChain
12
+ e as getMainTokenByChain
11
13
  };
12
14
  //# sourceMappingURL=getMainTokenByChain.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getMainTokenByChain.js","sources":["../../../src/utils/tokens/getMainTokenByChain.ts"],"sourcesContent":["import type { Chains } from '@/types/chain';\nimport type { Token } from '@/types/token';\n\ntype Args = {\n tokens: ReadonlyArray<Token>;\n walletSupportedChains: ReadonlyArray<Chains>;\n};\n\nexport const getMainTokenByChain = ({\n tokens,\n walletSupportedChains,\n}: Args) => {\n if (walletSupportedChains.includes('near')) {\n return (\n tokens.find(\n (t) => !t.isIntent && t.name === 'Near' && t.blockchain === 'near',\n ) ?? tokens[0]\n );\n }\n\n return (\n tokens.find(\n (t) => !t.isIntent && t.name === 'ETH' && t.blockchain === 'eth',\n ) ?? tokens[0]\n );\n};\n"],"names":["getMainTokenByChain","tokens","walletSupportedChains","t"],"mappings":"AAQO,MAAMA,IAAsB,CAAC;AAAA,EAClC,QAAAC;AAAA,EACA,uBAAAC;AACF,MACMA,EAAsB,SAAS,MAAM,IAErCD,EAAO;AAAA,EACL,CAACE,MAAM,CAACA,EAAE,YAAYA,EAAE,SAAS,UAAUA,EAAE,eAAe;AAAA,KACzDF,EAAO,CAAC,IAKfA,EAAO;AAAA,EACL,CAACE,MAAM,CAACA,EAAE,YAAYA,EAAE,SAAS,SAASA,EAAE,eAAe;AAAA,KACxDF,EAAO,CAAC;"}
1
+ {"version":3,"file":"getMainTokenByChain.js","sources":["../../../src/utils/tokens/getMainTokenByChain.ts"],"sourcesContent":["import type { Chains } from '@/types/chain';\nimport type { Token } from '@/types/token';\n\ntype Args = {\n tokens: ReadonlyArray<Token>;\n walletSupportedChains: ReadonlyArray<Chains>;\n};\n\nexport const getMainTokenByChain = ({\n tokens,\n walletSupportedChains,\n}: Args) => {\n if (walletSupportedChains.includes('near')) {\n return (\n tokens.find(\n (t) => !t.isIntent && t.name === 'Near' && t.blockchain === 'near',\n ) ?? tokens[0]\n );\n }\n\n if (walletSupportedChains.includes('sol')) {\n return (\n tokens.find(\n (t) => !t.isIntent && t.name === 'Solana' && t.blockchain === 'sol',\n ) ?? tokens[0]\n );\n }\n\n return (\n tokens.find(\n (t) => !t.isIntent && t.name === 'ETH' && t.blockchain === 'eth',\n ) ?? tokens[0]\n );\n};\n"],"names":["getMainTokenByChain","tokens","walletSupportedChains","t"],"mappings":"AAQO,MAAMA,IAAsB,CAAC;AAAA,EAClC,QAAAC;AAAA,EACA,uBAAAC;AACF,MACMA,EAAsB,SAAS,MAAM,IAErCD,EAAO;AAAA,EACL,CAACE,MAAM,CAACA,EAAE,YAAYA,EAAE,SAAS,UAAUA,EAAE,eAAe;AAAA,KACzDF,EAAO,CAAC,IAIbC,EAAsB,SAAS,KAAK,IAEpCD,EAAO;AAAA,EACL,CAACE,MAAM,CAACA,EAAE,YAAYA,EAAE,SAAS,YAAYA,EAAE,eAAe;AAAA,KAC3DF,EAAO,CAAC,IAKfA,EAAO;AAAA,EACL,CAACE,MAAM,CAACA,EAAE,YAAYA,EAAE,SAAS,SAASA,EAAE,eAAe;AAAA,KACxDF,EAAO,CAAC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurora-is-near/intents-swap-widget",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Provides components and hooks to build your own Intents swap widget",
5
5
  "author": "Maksim Vashchuk",
6
6
  "license": "UNLICENSED",
package/src/config.tsx CHANGED
@@ -18,7 +18,7 @@ export type WipgetConfig = {
18
18
  topScreenOffset: string;
19
19
 
20
20
  // Connected wallet
21
- intentsAccountType: 'evm' | 'near';
21
+ intentsAccountType: 'evm' | 'near' | 'sol';
22
22
  walletSupportedChains: ReadonlyArray<Chains>;
23
23
  walletAddress: string | undefined | null;
24
24
 
@@ -54,6 +54,7 @@ export const DEFAULT_CHAIN_ICON =
54
54
 
55
55
  export const DRY_QUOTE_ADDRESSES = {
56
56
  evm: '0x0000000000000000000000000000000000000000',
57
+ sol: '11111111111111111111111111111111',
57
58
  near: 'system.near',
58
59
  } as const;
59
60
 
@@ -23,6 +23,7 @@ import type { Context } from '@/machine/context';
23
23
 
24
24
  export type IntentsTransferArgs = {
25
25
  providers: {
26
+ sol?: undefined | null | (() => Promise<Eip1193Provider>);
26
27
  evm?: undefined | null | (() => Promise<Eip1193Provider>);
27
28
  near?: undefined | null | (() => NearWallet);
28
29
  };
@@ -105,6 +106,19 @@ export const useMakeIntentsTransfer = ({ providers }: IntentsTransferArgs) => {
105
106
  providers.evm,
106
107
  );
107
108
  break;
109
+ case 'sol':
110
+ if (!providers.sol) {
111
+ throw new TransferError({
112
+ code: 'TRANSFER_INVALID_INITIAL',
113
+ meta: { message: 'No EVM provider configured' },
114
+ });
115
+ }
116
+
117
+ signer = new IntentSignerPrivy(
118
+ { walletAddress: ctx.walletAddress },
119
+ providers.sol,
120
+ );
121
+ break;
108
122
  case 'near':
109
123
  if (!providers.near) {
110
124
  throw new TransferError({
@@ -119,10 +133,7 @@ export const useMakeIntentsTransfer = ({ providers }: IntentsTransferArgs) => {
119
133
  });
120
134
  break;
121
135
  default:
122
- notReachable(intentsAccountType, { throwError: false });
123
- throw new TransferError({
124
- code: 'BRIDGE_SDK_FAILED',
125
- });
136
+ notReachable(intentsAccountType);
126
137
  }
127
138
 
128
139
  const sdk = new BridgeSDK({ referral: appName });
@@ -191,11 +191,7 @@ export const useMakeQuote = ({ variant }: Props) => {
191
191
 
192
192
  if (error instanceof ApiError) {
193
193
  logger.error(error);
194
-
195
- throw new QuoteError({
196
- code: 'QUOTE_INVALID',
197
- meta: { isDry },
198
- });
194
+ throw error;
199
195
  }
200
196
 
201
197
  logger.error('[WIDGET] Failed to get a deposit address from the quote');
@@ -214,40 +210,44 @@ export const useMakeQuote = ({ variant }: Props) => {
214
210
  throw new Error('Failed to get a deposit address from the quote');
215
211
  }
216
212
  } catch (error: unknown) {
217
- // @ts-expect-error In case error has a message
218
- const errorMessage: string = error?.message;
213
+ if (error instanceof ApiError) {
214
+ const errorMessage = error.body.message ?? error.message;
219
215
 
220
- if (errorMessage.includes('Amount is too low')) {
221
- const match = errorMessage.match(/\d+/);
222
- const minAmount = match ? match[0] : undefined;
216
+ if (errorMessage.includes('Amount is too low')) {
217
+ const match = errorMessage.match(/\d+/);
218
+ const minAmount = match ? match[0] : undefined;
223
219
 
224
- throw new QuoteError({
225
- code: 'QUOTE_AMOUNT_IS_TOO_LOW',
226
- meta: {
227
- minAmount:
228
- (minAmount &&
229
- formatBigToHuman(minAmount, ctx.sourceToken.decimals)) ??
230
- '0',
231
- },
232
- });
233
- }
220
+ throw new QuoteError({
221
+ code: 'QUOTE_AMOUNT_IS_TOO_LOW',
222
+ meta: {
223
+ minAmount:
224
+ (minAmount &&
225
+ formatBigToHuman(minAmount, ctx.sourceToken.decimals)) ??
226
+ '0',
227
+ },
228
+ });
229
+ }
234
230
 
235
- if (errorMessage.includes('recipient is not valid')) {
236
- throw new QuoteError({
237
- code: 'TOKEN_IS_NOT_SUPPORTED',
238
- });
239
- }
231
+ if (errorMessage.includes('recipient is not valid')) {
232
+ throw new QuoteError({
233
+ code: 'TOKEN_IS_NOT_SUPPORTED',
234
+ });
235
+ }
240
236
 
241
- if (errorMessage.includes('Failed to get a deposit address')) {
242
- throw new QuoteError({
243
- code: 'QUOTE_NO_ONE_TIME_ADDRESS',
244
- });
237
+ if (errorMessage.includes('Failed to get a deposit address')) {
238
+ throw new QuoteError({
239
+ code: 'QUOTE_NO_ONE_TIME_ADDRESS',
240
+ });
241
+ }
242
+
243
+ throw error;
245
244
  }
246
245
 
247
246
  throw new QuoteError({
248
247
  code: 'QUOTE_FAILED',
249
248
  meta: {
250
- message: errorMessage ?? 'Failed to fetch quote. Please try again.',
249
+ // @ts-expect-error In case error has a message
250
+ message: error?.message ?? 'Failed to fetch quote. Please try again.',
251
251
  },
252
252
  });
253
253
  }
@@ -53,3 +53,41 @@ export type ErrorType =
53
53
  | InputValidDryError
54
54
  | InputValidWalletError
55
55
  | QuoteSuccessError;
56
+
57
+ export const QUOTE_ERRORS: Array<
58
+ InputValidDryError['code'] | InputValidWalletError['code']
59
+ > = [
60
+ 'NO_NEAR_TOKEN_FOUND',
61
+ 'TOKEN_IS_NOT_SUPPORTED',
62
+ 'QUOTE_FAILED',
63
+ 'QUOTE_INVALID',
64
+ 'QUOTE_INVALID_INITIAL',
65
+ 'QUOTE_AMOUNT_IS_TOO_LOW',
66
+ 'QUOTE_NO_ONE_TIME_ADDRESS',
67
+ ];
68
+
69
+ export const TRANSFER_ERRORS: Array<
70
+ QuoteSuccessDirectTransferError['code'] | QuoteSuccessTransferError['code']
71
+ > = [
72
+ 'DIRECT_TRANSFER_ERROR',
73
+ 'BRIDGE_SDK_FAILED',
74
+ 'FEES_NOT_ESTIMATED',
75
+ 'NO_QUOTE_FOUND',
76
+ 'NO_DEPOSIT_RESULT',
77
+ 'QUOTE_ERROR',
78
+ 'TRANSFER_INVALID_INITIAL',
79
+ ];
80
+
81
+ export const isQuoteError = (
82
+ error: ErrorType,
83
+ ): error is InputValidDryError | InputValidWalletError => {
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ return QUOTE_ERRORS.includes(error.code as any);
86
+ };
87
+
88
+ export const isTransferError = (
89
+ error: ErrorType,
90
+ ): error is QuoteSuccessError => {
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
+ return TRANSFER_ERRORS.includes(error.code as any);
93
+ };
@@ -3,6 +3,7 @@ import { isValidBigint } from '@/utils/checkers/isValidBigint';
3
3
 
4
4
  import { guardStates } from '@/machine/guards';
5
5
  import { isBalanceSufficient } from '@/machine/guards/checks/isBalanceSufficient';
6
+ import { isQuoteError, isTransferError } from '@/machine/errors';
6
7
  import type { Context } from '@/machine/context';
7
8
  import type {
8
9
  InitialDryStateError,
@@ -34,7 +35,11 @@ export const validateDryInputs = (ctx: Context): boolean | undefined => {
34
35
 
35
36
  if (!isValidInputsState && err) {
36
37
  fireEvent('errorSet', err);
37
- } else {
38
+ } else if (
39
+ ctx.error &&
40
+ !isQuoteError(ctx.error) &&
41
+ !isTransferError(ctx.error)
42
+ ) {
38
43
  fireEvent('errorSet', null);
39
44
  }
40
45
 
@@ -74,7 +79,11 @@ export const validateExternalInputs = (ctx: Context): boolean | undefined => {
74
79
 
75
80
  if (!isValidInputsState && err) {
76
81
  fireEvent('errorSet', err);
77
- } else {
82
+ } else if (
83
+ ctx.error &&
84
+ !isQuoteError(ctx.error) &&
85
+ !isTransferError(ctx.error)
86
+ ) {
78
87
  fireEvent('errorSet', null);
79
88
  }
80
89
 
@@ -112,7 +121,11 @@ export const validateInternalInputs = (ctx: Context): boolean | undefined => {
112
121
 
113
122
  if (!isValidInputsState && err) {
114
123
  fireEvent('errorSet', err);
115
- } else {
124
+ } else if (
125
+ ctx.error &&
126
+ !isQuoteError(ctx.error) &&
127
+ !isTransferError(ctx.error)
128
+ ) {
116
129
  fireEvent('errorSet', null);
117
130
  }
118
131
 
@@ -18,6 +18,14 @@ export const getMainTokenByChain = ({
18
18
  );
19
19
  }
20
20
 
21
+ if (walletSupportedChains.includes('sol')) {
22
+ return (
23
+ tokens.find(
24
+ (t) => !t.isIntent && t.name === 'Solana' && t.blockchain === 'sol',
25
+ ) ?? tokens[0]
26
+ );
27
+ }
28
+
21
29
  return (
22
30
  tokens.find(
23
31
  (t) => !t.isIntent && t.name === 'ETH' && t.blockchain === 'eth',