@aurora-is-near/intents-connect-wallet 7.20.0
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/README.md +134 -0
- package/connect/appkit/package.json +8 -0
- package/connect/near/package.json +8 -0
- package/connect/package.json +8 -0
- package/connect/stellar/package.json +8 -0
- package/dist/chunks/decodePublicKey-Dou2zIUa.js +10 -0
- package/dist/chunks/decodePublicKey-Dou2zIUa.js.map +1 -0
- package/dist/chunks/ids-BGp-e2lw.js +9 -0
- package/dist/chunks/ids-BGp-e2lw.js.map +1 -0
- package/dist/chunks/makeTransfer-2QUNX70G.js +124 -0
- package/dist/chunks/makeTransfer-2QUNX70G.js.map +1 -0
- package/dist/chunks/makeTransfer-CNFnKatI.js +59 -0
- package/dist/chunks/makeTransfer-CNFnKatI.js.map +1 -0
- package/dist/connect/WalletIcon.d.ts +3 -0
- package/dist/connect/WalletOptionCard.d.ts +9 -0
- package/dist/connect/WalletSelectorModal.d.ts +22 -0
- package/dist/connect/appkit/appkit.d.ts +44 -0
- package/dist/connect/appkit/index.d.ts +12 -0
- package/dist/connect/appkit/index.js +261 -0
- package/dist/connect/appkit/index.js.map +1 -0
- package/dist/connect/appkit/useAppKitConnector.d.ts +8 -0
- package/dist/connect/appkit/useAppKitProviders.d.ts +6 -0
- package/dist/connect/appkit/useAppKitWallet.d.ts +11 -0
- package/dist/connect/appkit/useIntentsConnectWallet.d.ts +33 -0
- package/dist/connect/icons/CloseIcon.d.ts +1 -0
- package/dist/connect/icons/CoinBaseIcon.d.ts +1 -0
- package/dist/connect/icons/FreighterIcon.d.ts +1 -0
- package/dist/connect/icons/HotWalletIcon.d.ts +1 -0
- package/dist/connect/icons/MetaMaskIcon.d.ts +1 -0
- package/dist/connect/icons/MeteorIcon.d.ts +1 -0
- package/dist/connect/icons/MyNearWalletIcon.d.ts +1 -0
- package/dist/connect/icons/NearIcon.d.ts +1 -0
- package/dist/connect/icons/PhantomIcon.d.ts +1 -0
- package/dist/connect/icons/StellarIcon.d.ts +1 -0
- package/dist/connect/icons/TrustIcon.d.ts +1 -0
- package/dist/connect/icons/WalletConnectIcon.d.ts +1 -0
- package/dist/connect/icons/XbullIcon.d.ts +1 -0
- package/dist/connect/ids.d.ts +13 -0
- package/dist/connect/index.d.ts +16 -0
- package/dist/connect/index.js +900 -0
- package/dist/connect/index.js.map +1 -0
- package/dist/connect/near/index.d.ts +7 -0
- package/dist/connect/near/index.js +67 -0
- package/dist/connect/near/index.js.map +1 -0
- package/dist/connect/near/useNearConnector.d.ts +8 -0
- package/dist/connect/near/useNearWallet.d.ts +12 -0
- package/dist/connect/presets.d.ts +12 -0
- package/dist/connect/stellar/index.d.ts +8 -0
- package/dist/connect/stellar/index.js +92 -0
- package/dist/connect/stellar/index.js.map +1 -0
- package/dist/connect/stellar/useStellarConnector.d.ts +14 -0
- package/dist/connect/stellar/useStellarWallet.d.ts +15 -0
- package/dist/connect/types.d.ts +46 -0
- package/dist/connect/useWalletSelector.d.ts +27 -0
- package/dist/evm/index.d.ts +11 -0
- package/dist/evm/index.js +11 -0
- package/dist/evm/index.js.map +1 -0
- package/dist/evm/makeTransfer.d.ts +12 -0
- package/dist/evm/makeVirtualChainTransfer.d.ts +9 -0
- package/dist/evm/types.d.ts +4 -0
- package/dist/evm/utils.d.ts +2 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/near/config.d.ts +5 -0
- package/dist/near/index.d.ts +11 -0
- package/dist/near/index.js +142 -0
- package/dist/near/index.js.map +1 -0
- package/dist/near/makeTransfer.d.ts +24 -0
- package/dist/near/types.d.ts +53 -0
- package/dist/near/viewCall.d.ts +18 -0
- package/dist/solana/index.d.ts +9 -0
- package/dist/solana/index.js +7 -0
- package/dist/solana/index.js.map +1 -0
- package/dist/solana/makeTransfer.d.ts +9 -0
- package/dist/solana/types.d.ts +15 -0
- package/dist/stellar/constants.d.ts +4 -0
- package/dist/stellar/createMemo.d.ts +8 -0
- package/dist/stellar/decodePublicKey.d.ts +9 -0
- package/dist/stellar/index.d.ts +12 -0
- package/dist/stellar/index.js +126 -0
- package/dist/stellar/index.js.map +1 -0
- package/dist/stellar/makeTransfer.d.ts +9 -0
- package/dist/stellar/types.d.ts +6 -0
- package/evm/package.json +8 -0
- package/near/package.json +8 -0
- package/package.json +119 -0
- package/solana/package.json +8 -0
- package/src/connect/WalletIcon.tsx +25 -0
- package/src/connect/WalletOptionCard.tsx +66 -0
- package/src/connect/WalletSelectorModal.tsx +118 -0
- package/src/connect/appkit/appkit.tsx +271 -0
- package/src/connect/appkit/index.ts +23 -0
- package/src/connect/appkit/useAppKitConnector.ts +62 -0
- package/src/connect/appkit/useAppKitProviders.ts +18 -0
- package/src/connect/appkit/useAppKitWallet.ts +71 -0
- package/src/connect/appkit/useIntentsConnectWallet.ts +99 -0
- package/src/connect/icons/CloseIcon.tsx +16 -0
- package/src/connect/icons/CoinBaseIcon.tsx +23 -0
- package/src/connect/icons/FreighterIcon.tsx +126 -0
- package/src/connect/icons/HotWalletIcon.tsx +30 -0
- package/src/connect/icons/MetaMaskIcon.tsx +44 -0
- package/src/connect/icons/MeteorIcon.tsx +27 -0
- package/src/connect/icons/MyNearWalletIcon.tsx +27 -0
- package/src/connect/icons/NearIcon.tsx +13 -0
- package/src/connect/icons/PhantomIcon.tsx +23 -0
- package/src/connect/icons/StellarIcon.tsx +11 -0
- package/src/connect/icons/TrustIcon.tsx +38 -0
- package/src/connect/icons/WalletConnectIcon.tsx +30 -0
- package/src/connect/icons/XbullIcon.tsx +81 -0
- package/src/connect/ids.ts +14 -0
- package/src/connect/index.ts +31 -0
- package/src/connect/near/index.ts +10 -0
- package/src/connect/near/useNearConnector.ts +39 -0
- package/src/connect/near/useNearWallet.ts +117 -0
- package/src/connect/presets.ts +63 -0
- package/src/connect/stellar/index.ts +11 -0
- package/src/connect/stellar/useStellarConnector.ts +46 -0
- package/src/connect/stellar/useStellarWallet.ts +92 -0
- package/src/connect/types.ts +52 -0
- package/src/connect/useWalletSelector.ts +89 -0
- package/src/evm/index.ts +15 -0
- package/src/evm/makeTransfer.test.ts +209 -0
- package/src/evm/makeTransfer.ts +190 -0
- package/src/evm/makeVirtualChainTransfer.ts +74 -0
- package/src/evm/types.ts +5 -0
- package/src/evm/utils.ts +10 -0
- package/src/index.ts +18 -0
- package/src/near/config.ts +11 -0
- package/src/near/index.ts +29 -0
- package/src/near/makeTransfer.test.ts +256 -0
- package/src/near/makeTransfer.ts +136 -0
- package/src/near/types.ts +52 -0
- package/src/near/viewCall.ts +118 -0
- package/src/solana/index.ts +13 -0
- package/src/solana/makeTransfer.ts +126 -0
- package/src/solana/types.ts +16 -0
- package/src/stellar/constants.ts +14 -0
- package/src/stellar/createMemo.ts +43 -0
- package/src/stellar/decodePublicKey.ts +17 -0
- package/src/stellar/index.ts +16 -0
- package/src/stellar/makeTransfer.ts +235 -0
- package/src/stellar/types.ts +7 -0
- package/stellar/package.json +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# @aurora-is-near/intents-connect-wallet
|
|
2
|
+
|
|
3
|
+
Chain wallets for [`@aurora-is-near/intents-connect`](../intents-connect):
|
|
4
|
+
deposit transfers and wallet connection, **one subpath per chain**.
|
|
5
|
+
|
|
6
|
+
Ported from `intents-swap-widget-evm/-solana/-stellar`, the widget's
|
|
7
|
+
`useMakeNEARFtTransferCall` hook, and `intents-swap-widget-standalone` — with no
|
|
8
|
+
dependency on the widget.
|
|
9
|
+
|
|
10
|
+
## Why subpaths
|
|
11
|
+
|
|
12
|
+
Every chain SDK is an **optional peer dependency**, reachable only through its
|
|
13
|
+
own subpath. That matters more than it sounds: `@creit.tech/stellar-wallets-kit`
|
|
14
|
+
alone installs a ~160M closure (it bundles its own WalletConnect, Reown and viem
|
|
15
|
+
copies), so an EVM-only integration must not be made to install it.
|
|
16
|
+
|
|
17
|
+
| Subpath | Purpose | Optional peers |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| `.` | shared transfer types, no deps | — |
|
|
20
|
+
| `./evm` | EVM deposit transfer | `viem` |
|
|
21
|
+
| `./solana` | Solana deposit transfer | `@solana/web3.js`, `@solana/spl-token` |
|
|
22
|
+
| `./stellar` | Stellar transfer + `decodePublicKey` | `@stellar/stellar-sdk` |
|
|
23
|
+
| `./near` | NEAR deposit transfer | — (plain `fetch`) |
|
|
24
|
+
| `./connect` | modal, presets, coordinator | `react`, `@headlessui/react` |
|
|
25
|
+
| `./connect/appkit` | EVM + Solana connectors | `@reown/*`, `@solana/wallet-adapter-*`, `viem` |
|
|
26
|
+
| `./connect/near` | NEAR connector | `@hot-labs/near-connect` |
|
|
27
|
+
| `./connect/stellar` | Stellar connector | `@creit.tech/stellar-wallets-kit`, `@stellar/stellar-sdk` |
|
|
28
|
+
|
|
29
|
+
Install only what you use — e.g. EVM with our modal:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add @aurora-is-near/intents-connect @aurora-is-near/intents-connect-wallet \
|
|
33
|
+
viem react @headlessui/react @reown/appkit @reown/appkit-adapter-ethers
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Transfers
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { evm } from '@aurora-is-near/intents-connect-wallet/evm';
|
|
40
|
+
|
|
41
|
+
createExecutionRunner({
|
|
42
|
+
api,
|
|
43
|
+
wallet,
|
|
44
|
+
plugins: { evm },
|
|
45
|
+
pluginOptions: { provider: window.ethereum },
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Connection
|
|
50
|
+
|
|
51
|
+
`./connect` is **chain-agnostic**: the coordinator takes connectors as arguments
|
|
52
|
+
rather than importing them, and the modal renders whatever options it is handed.
|
|
53
|
+
The widget's `useWalletSelector` imported all three chains directly, which is why
|
|
54
|
+
it could never be split.
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import {
|
|
58
|
+
WalletSelectorModal,
|
|
59
|
+
useWalletSelector,
|
|
60
|
+
EVM_SOLANA_WALLET_OPTION,
|
|
61
|
+
NEAR_WALLET_OPTION,
|
|
62
|
+
} from '@aurora-is-near/intents-connect-wallet/connect';
|
|
63
|
+
import {
|
|
64
|
+
AppKitProvider,
|
|
65
|
+
useAppKitConnector,
|
|
66
|
+
} from '@aurora-is-near/intents-connect-wallet/connect/appkit';
|
|
67
|
+
import { useNearConnector } from '@aurora-is-near/intents-connect-wallet/connect/near';
|
|
68
|
+
|
|
69
|
+
function Wallets({ children }) {
|
|
70
|
+
const evmSolana = useAppKitConnector();
|
|
71
|
+
const near = useNearConnector();
|
|
72
|
+
const selector = useWalletSelector([evmSolana, near]);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<>
|
|
76
|
+
<IntentsConnectProvider api={api} wallet={toWalletConnector(selector)}>
|
|
77
|
+
{children}
|
|
78
|
+
</IntentsConnectProvider>
|
|
79
|
+
<WalletSelectorModal
|
|
80
|
+
open={selector.isOpen}
|
|
81
|
+
onClose={selector.close}
|
|
82
|
+
options={[EVM_SOLANA_WALLET_OPTION, NEAR_WALLET_OPTION]}
|
|
83
|
+
onSelect={selector.select}
|
|
84
|
+
/>
|
|
85
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Wrap the tree in `<AppKitProvider>` when using `./connect/appkit`.
|
|
91
|
+
|
|
92
|
+
Each connector carries the runner-facing members (`signingStandard`,
|
|
93
|
+
`getPublicKey`, `getChainId`, `decodePublicKey`, `getProviders`), so the
|
|
94
|
+
adapter to `intents-connect`'s `WalletConnector` is a thin projection of
|
|
95
|
+
`selector.connected`:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const toWalletConnector = (selector: WalletSelectorState) => {
|
|
99
|
+
const { connected } = selector;
|
|
100
|
+
|
|
101
|
+
if (!connected?.signingStandard) return null;
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
id: connected.id,
|
|
105
|
+
name: connected.id,
|
|
106
|
+
chains: [],
|
|
107
|
+
signingStandard: connected.signingStandard,
|
|
108
|
+
connect: async () => connected.connect(),
|
|
109
|
+
disconnect: async () => connected.disconnect(),
|
|
110
|
+
getAddress: () => connected.address,
|
|
111
|
+
getPublicKey: connected.getPublicKey,
|
|
112
|
+
getChainId: connected.getChainId,
|
|
113
|
+
decodePublicKey: connected.decodePublicKey,
|
|
114
|
+
getProviders: () => connected.getProviders?.() ?? {},
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Connections are **mutually exclusive**: an execution is bound to one origin
|
|
120
|
+
wallet, since both the signing standard and the intermediary address follow from
|
|
121
|
+
it. `select()` disconnects the others first.
|
|
122
|
+
|
|
123
|
+
## Deviations from the widget
|
|
124
|
+
|
|
125
|
+
- **AppKit takes config instead of widget constants.** `Theme` collapsed to
|
|
126
|
+
`themeMode`, and `CHAIN_IDS_MAP`/`DEFAULT_RPCS` became an optional
|
|
127
|
+
`rpcOverrides` map that falls back to each chain's public RPC from viem.
|
|
128
|
+
`projectId` is now a prop — it defaults to Aurora's, but register your own.
|
|
129
|
+
- **`ethers` is gone.** It was imported for one type, which `intents-connect`
|
|
130
|
+
already provides.
|
|
131
|
+
- **Solana's RPC is configurable.** The widget hardcoded an Alchemy URL built
|
|
132
|
+
from an `alchemyApiKey`; pass `rpcUrl` or a `connection` instead.
|
|
133
|
+
- **NEAR uses `ft_transfer`, not `ft_transfer_call`,** and does not swallow user
|
|
134
|
+
rejection. See the notes in `src/near/makeTransfer.ts`.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"//": "Resolution stub for moduleResolution: node, which ignores the exports map.",
|
|
3
|
+
"name": "@aurora-is-near/intents-connect-wallet-connect-appkit-subpath",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "../../dist/connect/appkit/index.js",
|
|
6
|
+
"module": "../../dist/connect/appkit/index.js",
|
|
7
|
+
"types": "../../dist/connect/appkit/index.d.ts"
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"//": "Resolution stub for moduleResolution: node, which ignores the exports map.",
|
|
3
|
+
"name": "@aurora-is-near/intents-connect-wallet-connect-near-subpath",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "../../dist/connect/near/index.js",
|
|
6
|
+
"module": "../../dist/connect/near/index.js",
|
|
7
|
+
"types": "../../dist/connect/near/index.d.ts"
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"//": "Resolution stub for moduleResolution: node, which ignores the exports map.",
|
|
3
|
+
"name": "@aurora-is-near/intents-connect-wallet-connect-subpath",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "../dist/connect/index.js",
|
|
6
|
+
"module": "../dist/connect/index.js",
|
|
7
|
+
"types": "../dist/connect/index.d.ts"
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"//": "Resolution stub for moduleResolution: node, which ignores the exports map.",
|
|
3
|
+
"name": "@aurora-is-near/intents-connect-wallet-connect-stellar-subpath",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "../../dist/connect/stellar/index.js",
|
|
6
|
+
"module": "../../dist/connect/stellar/index.js",
|
|
7
|
+
"types": "../../dist/connect/stellar/index.d.ts"
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StrKey as r } from "@stellar/stellar-sdk";
|
|
2
|
+
const c = (e) => {
|
|
3
|
+
if (!e.publicKey)
|
|
4
|
+
throw new Error("No public key found in Stellar provider.");
|
|
5
|
+
return r.decodeEd25519PublicKey(e.publicKey);
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
c as d
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=decodePublicKey-Dou2zIUa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodePublicKey-Dou2zIUa.js","sources":["../../src/stellar/decodePublicKey.ts"],"sourcesContent":["import { StrKey } from '@stellar/stellar-sdk';\nimport type { StellarProvider } from '@aurora-is-near/intents-connect';\n\n/**\n * StrKey `G…` → the 32 raw bytes the `sep53` signer needs for its `publicKey`.\n *\n * Injected into the signer from here so `@stellar/stellar-sdk` stays out of the\n * headless core. A `G…` address is NOT raw base58, so it cannot be encoded\n * directly.\n */\nexport const decodePublicKey = (provider: StellarProvider): Uint8Array => {\n if (!provider.publicKey) {\n throw new Error('No public key found in Stellar provider.');\n }\n\n return StrKey.decodeEd25519PublicKey(provider.publicKey);\n};\n"],"names":["decodePublicKey","provider","StrKey"],"mappings":";AAUO,MAAMA,IAAkB,CAACC,MAA0C;AACxE,MAAI,CAACA,EAAS;AACZ,UAAM,IAAI,MAAM,0CAA0C;AAG5D,SAAOC,EAAO,uBAAuBD,EAAS,SAAS;AACzD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids-BGp-e2lw.js","sources":["../../src/connect/ids.ts"],"sourcesContent":["/**\n * Connector ids, shared by the modal presets and the connector hooks.\n *\n * Deliberately its own module with no imports: `presets.ts` pulls in every\n * wallet SVG (~228KB), and a connector subpath reading an id from there would\n * drag all of it in for a string constant.\n */\nexport const CONNECTOR_IDS = {\n evmSolana: 'evm-solana',\n near: 'near',\n stellar: 'stellar',\n} as const;\n\nexport type ConnectorId = (typeof CONNECTOR_IDS)[keyof typeof CONNECTOR_IDS];\n"],"names":["CONNECTOR_IDS"],"mappings":"AAOO,MAAMA,IAAgB;AAAA,EAC3B,WAAW;AAAA,EACX,MAAM;AAAA,EACN,SAAS;AACX;"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { stringToHex as m, encodeFunctionData as h, createWalletClient as f, custom as p, erc20Abi as E } from "viem";
|
|
2
|
+
import * as v from "viem/chains";
|
|
3
|
+
import { resolveTransferAmount as u } from "@aurora-is-near/intents-connect";
|
|
4
|
+
const c = (e) => /^0x[a-fA-F0-9]{40}$/.test(e), y = /* @__PURE__ */ new Set(["aurora"]), A = (e) => y.has(e), k = [
|
|
5
|
+
{
|
|
6
|
+
type: "function",
|
|
7
|
+
name: "withdrawToNear",
|
|
8
|
+
stateMutability: "nonpayable",
|
|
9
|
+
inputs: [
|
|
10
|
+
{ name: "recipient", type: "bytes" },
|
|
11
|
+
{ name: "amount", type: "uint256" }
|
|
12
|
+
],
|
|
13
|
+
outputs: []
|
|
14
|
+
}
|
|
15
|
+
], C = async (e, { walletClient: t, from: n, chain: i }) => {
|
|
16
|
+
if (e.isNativeEvmTokenTransfer)
|
|
17
|
+
throw new Error(
|
|
18
|
+
"Native ETH withdrawals from virtual chains are not supported."
|
|
19
|
+
);
|
|
20
|
+
if (!e.tokenAddress || !c(e.tokenAddress))
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Invalid virtual chain token address: ${e.tokenAddress}`
|
|
23
|
+
);
|
|
24
|
+
const o = m(
|
|
25
|
+
`intents.near:${JSON.stringify({ receiver_id: e.address })}`
|
|
26
|
+
), r = h({
|
|
27
|
+
abi: k,
|
|
28
|
+
functionName: "withdrawToNear",
|
|
29
|
+
args: [o, u(e)]
|
|
30
|
+
});
|
|
31
|
+
return { hash: await t.sendTransaction({
|
|
32
|
+
account: n,
|
|
33
|
+
to: e.tokenAddress,
|
|
34
|
+
data: r,
|
|
35
|
+
gas: 100000n,
|
|
36
|
+
gasPrice: 0n,
|
|
37
|
+
chain: i
|
|
38
|
+
}) };
|
|
39
|
+
}, l = (e) => Object.values(v).find(
|
|
40
|
+
(t) => !!t && typeof t == "object" && "id" in t && typeof t.id == "number" && t.id === e
|
|
41
|
+
), T = async (e, t) => {
|
|
42
|
+
const n = l(e);
|
|
43
|
+
if (!n)
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Chain ${e} is not available in your wallet and is unknown to the viem registry — add it to the wallet manually`
|
|
46
|
+
);
|
|
47
|
+
await t.request({
|
|
48
|
+
method: "wallet_addEthereumChain",
|
|
49
|
+
params: [
|
|
50
|
+
{
|
|
51
|
+
chainId: `0x${e.toString(16)}`,
|
|
52
|
+
chainName: n.name,
|
|
53
|
+
nativeCurrency: n.nativeCurrency,
|
|
54
|
+
rpcUrls: [...n.rpcUrls.default.http],
|
|
55
|
+
blockExplorerUrls: n.blockExplorers ? [n.blockExplorers.default.url] : void 0
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
}, I = async (e, t) => {
|
|
60
|
+
const n = await t.request({ method: "eth_chainId" });
|
|
61
|
+
if (parseInt(n, 16) === e)
|
|
62
|
+
return;
|
|
63
|
+
const o = () => t.request({
|
|
64
|
+
method: "wallet_switchEthereumChain",
|
|
65
|
+
params: [{ chainId: `0x${e.toString(16)}` }]
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
await o();
|
|
69
|
+
} catch (r) {
|
|
70
|
+
if ((r && typeof r == "object" && "code" in r ? r.code : void 0) === 4902) {
|
|
71
|
+
await T(e, t), await o();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Please switch to the correct network (Chain ID: ${e}) in your wallet`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}, _ = async (e, t) => {
|
|
79
|
+
const n = t?.provider, i = typeof n == "function" ? await n() : n, o = A(e.chain);
|
|
80
|
+
if (!o && !c(e.address))
|
|
81
|
+
throw new Error(`Invalid EVM address: ${e.address}`);
|
|
82
|
+
if (!e.evmChainId)
|
|
83
|
+
throw new Error("EVM chain ID is required for EVM transfers.");
|
|
84
|
+
if (!i)
|
|
85
|
+
throw new Error("No injected Ethereum wallet found.");
|
|
86
|
+
await I(e.evmChainId, i);
|
|
87
|
+
const r = f({
|
|
88
|
+
transport: p(i)
|
|
89
|
+
});
|
|
90
|
+
let [a] = await r.getAddresses();
|
|
91
|
+
if (a || ([a] = await r.requestAddresses()), !a)
|
|
92
|
+
throw new Error("No EVM account found in the injected wallet.");
|
|
93
|
+
const s = l(e.evmChainId) ?? null;
|
|
94
|
+
if (o)
|
|
95
|
+
return C(e, { walletClient: r, from: a, chain: s });
|
|
96
|
+
const d = u(e);
|
|
97
|
+
if (e.isNativeEvmTokenTransfer)
|
|
98
|
+
return { hash: await r.sendTransaction({
|
|
99
|
+
account: a,
|
|
100
|
+
to: e.address,
|
|
101
|
+
value: d,
|
|
102
|
+
chain: s
|
|
103
|
+
}) };
|
|
104
|
+
if (!e.tokenAddress || !c(e.tokenAddress))
|
|
105
|
+
throw new Error(`Invalid EVM token address: ${e.tokenAddress}`);
|
|
106
|
+
const w = h({
|
|
107
|
+
abi: E,
|
|
108
|
+
functionName: "transfer",
|
|
109
|
+
args: [e.address, d]
|
|
110
|
+
});
|
|
111
|
+
return { hash: await r.sendTransaction({
|
|
112
|
+
account: a,
|
|
113
|
+
to: e.tokenAddress,
|
|
114
|
+
data: w,
|
|
115
|
+
chain: s
|
|
116
|
+
}) };
|
|
117
|
+
};
|
|
118
|
+
export {
|
|
119
|
+
C as a,
|
|
120
|
+
A as b,
|
|
121
|
+
c as i,
|
|
122
|
+
_ as m
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=makeTransfer-2QUNX70G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeTransfer-2QUNX70G.js","sources":["../../src/evm/utils.ts","../../src/evm/makeVirtualChainTransfer.ts","../../src/evm/makeTransfer.ts"],"sourcesContent":["export const isEvmAddress = (a: string): boolean =>\n /^0x[a-fA-F0-9]{40}$/.test(a);\n\n// NEAR virtual chains route transfers through the exitToNear precompile instead\n// of a standard ERC-20 transfer. Aurora Mainnet is the only one today but\n// additional VCs could slot in here.\nconst VIRTUAL_CHAINS: ReadonlySet<string> = new Set(['aurora']);\n\nexport const isVirtualChain = (chain: string): boolean =>\n VIRTUAL_CHAINS.has(chain);\n","import {\n type Chain,\n encodeFunctionData,\n stringToHex,\n type WalletClient,\n} from 'viem';\nimport {\n type MakeTransferArgs,\n resolveTransferAmount,\n type TransferResult,\n} from '@aurora-is-near/intents-connect';\n\nimport { isEvmAddress } from '@/evm/utils';\n\n// NEAR virtual chains (e.g. Aurora) expose `withdrawToNear()` on their ERC-20\n// wrappers to invoke the exitToNear precompile. The bytes payload encodes\n// `intents.near:<json msg>` where the JSON has the Intents receiver_id, so the\n// asset lands inside NEAR Intents after the bridge call.\nconst VIRTUAL_CHAIN_ERC20_WITHDRAW_ABI = [\n {\n type: 'function',\n name: 'withdrawToNear',\n stateMutability: 'nonpayable',\n inputs: [\n { name: 'recipient', type: 'bytes' },\n { name: 'amount', type: 'uint256' },\n ],\n outputs: [],\n },\n] as const;\n\ntype Context = {\n walletClient: WalletClient;\n from: `0x${string}`;\n chain: Chain | null;\n};\n\nexport const makeVirtualChainTransfer = async (\n args: MakeTransferArgs,\n { walletClient, from, chain }: Context,\n): Promise<Pick<TransferResult, 'hash'>> => {\n if (args.isNativeEvmTokenTransfer) {\n throw new Error(\n 'Native ETH withdrawals from virtual chains are not supported.',\n );\n }\n\n if (!args.tokenAddress || !isEvmAddress(args.tokenAddress)) {\n throw new Error(\n `Invalid virtual chain token address: ${args.tokenAddress}`,\n );\n }\n\n const payload = stringToHex(\n `intents.near:${JSON.stringify({ receiver_id: args.address })}`,\n );\n\n const data = encodeFunctionData({\n abi: VIRTUAL_CHAIN_ERC20_WITHDRAW_ABI,\n functionName: 'withdrawToNear',\n args: [payload, resolveTransferAmount(args)],\n });\n\n const hash = await walletClient.sendTransaction({\n account: from,\n to: args.tokenAddress as `0x${string}`,\n data,\n gas: 100000n,\n gasPrice: 0n,\n chain,\n });\n\n return { hash };\n};\n","import {\n type Chain,\n createWalletClient,\n custom,\n encodeFunctionData,\n erc20Abi,\n} from 'viem';\nimport * as viemChains from 'viem/chains';\nimport {\n type Eip1193Provider,\n type MakeTransfer,\n type MakeTransferArgs,\n resolveTransferAmount,\n type TransferResult,\n} from '@aurora-is-near/intents-connect';\n\nimport { makeVirtualChainTransfer } from '@/evm/makeVirtualChainTransfer';\nimport type { EvmTransferOptions } from '@/evm/types';\nimport { isEvmAddress, isVirtualChain } from '@/evm/utils';\n\nconst findViemChain = (id: number): Chain | undefined =>\n (Object.values(viemChains) as unknown[]).find(\n (c): c is Chain =>\n !!c &&\n typeof c === 'object' &&\n 'id' in c &&\n typeof (c as { id: unknown }).id === 'number' &&\n (c as Chain).id === id,\n );\n\n/**\n * 4902 = the wallet has never had this chain added. Recoverable: offer the\n * chain via `wallet_addEthereumChain` (the wallet prompts the user to add —\n * and usually to switch to — it) using viem's registry metadata.\n */\nconst addEthereumChain = async (\n targetChainId: number,\n provider: Eip1193Provider,\n): Promise<void> => {\n const chain = findViemChain(targetChainId);\n\n if (!chain) {\n throw new Error(\n `Chain ${targetChainId} is not available in your wallet and is unknown to the viem registry — add it to the wallet manually`,\n );\n }\n\n await provider.request({\n method: 'wallet_addEthereumChain',\n params: [\n {\n chainId: `0x${targetChainId.toString(16)}`,\n chainName: chain.name,\n nativeCurrency: chain.nativeCurrency,\n rpcUrls: [...chain.rpcUrls.default.http],\n blockExplorerUrls: chain.blockExplorers\n ? [chain.blockExplorers.default.url]\n : undefined,\n },\n ],\n });\n};\n\nconst switchEthereumChain = async (\n targetChainId: number,\n provider: Eip1193Provider,\n): Promise<void> => {\n const currentChainIdHex = await provider.request({ method: 'eth_chainId' });\n const currentChainId = parseInt(currentChainIdHex as string, 16);\n\n if (currentChainId === targetChainId) {\n return;\n }\n\n const requestSwitch = () =>\n provider.request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: `0x${targetChainId.toString(16)}` }],\n });\n\n try {\n await requestSwitch();\n } catch (error: unknown) {\n const code =\n error && typeof error === 'object' && 'code' in error\n ? (error as { code: unknown }).code\n : undefined;\n\n if (code === 4902) {\n await addEthereumChain(targetChainId, provider);\n\n // Adding usually switches as well, but that is wallet-specific — the\n // explicit switch below is a no-op where it already happened.\n await requestSwitch();\n\n return;\n }\n\n throw new Error(\n `Please switch to the correct network (Chain ID: ${targetChainId}) in your wallet`,\n );\n }\n};\n\n/**\n * Sends the origin-chain deposit for an EVM origin.\n *\n * Ported from `@aurora-is-near/intents-swap-widget-evm`, with three deltas:\n * types come from `intents-connect` instead of the widget, the amount is read\n * through `resolveTransferAmount` so both `amountAtomic` (what the runner sets)\n * and the widget's `amount` field work, and a 4902 chain switch is recovered by\n * offering the chain via `wallet_addEthereumChain` rather than giving up.\n */\nexport const makeTransfer: MakeTransfer<EvmTransferOptions> = async (\n args: MakeTransferArgs,\n options: EvmTransferOptions,\n): Promise<Pick<TransferResult, 'hash'>> => {\n const provider = options?.provider;\n const resolved = typeof provider === 'function' ? await provider() : provider;\n const isVirtualChainSource = isVirtualChain(args.chain);\n\n // When the source is a NEAR virtual chain (e.g. Aurora), the 1Click deposit\n // address is a NEAR account (intents.near sub-account) rather than an EVM\n // address.\n if (!isVirtualChainSource && !isEvmAddress(args.address)) {\n throw new Error(`Invalid EVM address: ${args.address}`);\n }\n\n if (!args.evmChainId) {\n throw new Error('EVM chain ID is required for EVM transfers.');\n }\n\n if (!resolved) {\n throw new Error('No injected Ethereum wallet found.');\n }\n\n await switchEthereumChain(args.evmChainId, resolved);\n\n const walletClient = createWalletClient({\n transport: custom(resolved as Parameters<typeof custom>[0]),\n });\n\n let [from] = await walletClient.getAddresses();\n\n if (!from) {\n [from] = await walletClient.requestAddresses();\n }\n\n if (!from) {\n throw new Error('No EVM account found in the injected wallet.');\n }\n\n const chain = findViemChain(args.evmChainId) ?? null;\n\n if (isVirtualChainSource) {\n return makeVirtualChainTransfer(args, { walletClient, from, chain });\n }\n\n const amount = resolveTransferAmount(args);\n\n if (args.isNativeEvmTokenTransfer) {\n const hash = await walletClient.sendTransaction({\n account: from,\n to: args.address as `0x${string}`,\n value: amount,\n chain,\n });\n\n return { hash };\n }\n\n if (!args.tokenAddress || !isEvmAddress(args.tokenAddress)) {\n throw new Error(`Invalid EVM token address: ${args.tokenAddress}`);\n }\n\n const data = encodeFunctionData({\n abi: erc20Abi,\n functionName: 'transfer',\n args: [args.address as `0x${string}`, amount],\n });\n\n const hash = await walletClient.sendTransaction({\n account: from,\n to: args.tokenAddress as `0x${string}`,\n data,\n chain,\n });\n\n return { hash };\n};\n"],"names":["isEvmAddress","a","VIRTUAL_CHAINS","isVirtualChain","chain","VIRTUAL_CHAIN_ERC20_WITHDRAW_ABI","makeVirtualChainTransfer","args","walletClient","from","payload","stringToHex","data","encodeFunctionData","resolveTransferAmount","findViemChain","id","viemChains","c","addEthereumChain","targetChainId","provider","switchEthereumChain","currentChainIdHex","requestSwitch","error","makeTransfer","options","resolved","isVirtualChainSource","createWalletClient","custom","amount","hash","erc20Abi"],"mappings":"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"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Connection as h, PublicKey as d, Transaction as u, SystemProgram as p } from "@solana/web3.js";
|
|
2
|
+
import { getAssociatedTokenAddress as f, createAssociatedTokenAccountIdempotentInstruction as A, createTransferCheckedInstruction as T } from "@solana/spl-token";
|
|
3
|
+
import { resolveTransferAmount as y } from "@aurora-is-near/intents-connect";
|
|
4
|
+
const b = "https://solana-rpc.publicnode.com", P = ({
|
|
5
|
+
connection: n,
|
|
6
|
+
rpcUrl: e
|
|
7
|
+
}) => n ?? new h(e ?? b), l = async (n, e, { provider: t }, o) => {
|
|
8
|
+
const { blockhash: r } = await n.getLatestBlockhash();
|
|
9
|
+
e.recentBlockhash = r, e.feePayer = o;
|
|
10
|
+
const a = await t.signTransaction(e);
|
|
11
|
+
return { hash: await n.sendRawTransaction(a.serialize(), {
|
|
12
|
+
skipPreflight: !1,
|
|
13
|
+
maxRetries: 3
|
|
14
|
+
}) };
|
|
15
|
+
}, I = async (n, e) => {
|
|
16
|
+
if (!e?.provider)
|
|
17
|
+
throw new Error(
|
|
18
|
+
"Solana transfer requires pluginOptions.provider (a SolanaProvider)"
|
|
19
|
+
);
|
|
20
|
+
const t = P(e);
|
|
21
|
+
if (!e.provider.publicKey)
|
|
22
|
+
throw new Error("No public key found in Solana provider.");
|
|
23
|
+
const o = new d(e.provider.publicKey.toString()), r = new d(n.address), a = y(n);
|
|
24
|
+
if (!n.tokenAddress) {
|
|
25
|
+
const k = new u().add(
|
|
26
|
+
p.transfer({ fromPubkey: o, toPubkey: r, lamports: a })
|
|
27
|
+
);
|
|
28
|
+
return l(t, k, e, o);
|
|
29
|
+
}
|
|
30
|
+
const s = new d(n.tokenAddress), m = await f(
|
|
31
|
+
s,
|
|
32
|
+
o
|
|
33
|
+
), c = await f(
|
|
34
|
+
s,
|
|
35
|
+
r,
|
|
36
|
+
!0
|
|
37
|
+
), w = await t.getAccountInfo(c), i = new u();
|
|
38
|
+
return w || i.add(
|
|
39
|
+
A(
|
|
40
|
+
o,
|
|
41
|
+
c,
|
|
42
|
+
r,
|
|
43
|
+
s
|
|
44
|
+
)
|
|
45
|
+
), i.add(
|
|
46
|
+
T(
|
|
47
|
+
m,
|
|
48
|
+
s,
|
|
49
|
+
c,
|
|
50
|
+
o,
|
|
51
|
+
a,
|
|
52
|
+
n.decimals
|
|
53
|
+
)
|
|
54
|
+
), l(t, i, e, o);
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
I as m
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=makeTransfer-CNFnKatI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeTransfer-CNFnKatI.js","sources":["../../src/solana/makeTransfer.ts"],"sourcesContent":["import {\n Connection,\n PublicKey,\n SystemProgram,\n Transaction,\n} from '@solana/web3.js';\nimport {\n createAssociatedTokenAccountIdempotentInstruction,\n createTransferCheckedInstruction,\n getAssociatedTokenAddress,\n} from '@solana/spl-token';\nimport {\n type MakeTransfer,\n type MakeTransferArgs,\n resolveTransferAmount,\n type TransferResult,\n} from '@aurora-is-near/intents-connect';\n\nimport type { SolanaTransferOptions } from '@/solana/types';\n\nconst DEFAULT_RPC_URL = 'https://solana-rpc.publicnode.com';\n\nconst resolveConnection = ({\n connection,\n rpcUrl,\n}: SolanaTransferOptions): Connection =>\n connection ?? new Connection(rpcUrl ?? DEFAULT_RPC_URL);\n\nconst sendSigned = async (\n connection: Connection,\n transaction: Transaction,\n { provider }: SolanaTransferOptions,\n feePayer: PublicKey,\n): Promise<Pick<TransferResult, 'hash'>> => {\n const { blockhash } = await connection.getLatestBlockhash();\n\n transaction.recentBlockhash = blockhash;\n transaction.feePayer = feePayer;\n\n const signedTx = await provider.signTransaction(transaction);\n const hash = await connection.sendRawTransaction(signedTx.serialize(), {\n skipPreflight: false,\n maxRetries: 3,\n });\n\n return { hash };\n};\n\n/**\n * Sends the origin-chain deposit for a Solana origin.\n *\n * Ported from `@aurora-is-near/intents-swap-widget-solana`. Transfer mechanics\n * are unchanged; the RPC endpoint is configurable rather than Alchemy-only.\n */\nexport const makeTransfer: MakeTransfer<SolanaTransferOptions> = async (\n args: MakeTransferArgs,\n options: SolanaTransferOptions,\n): Promise<Pick<TransferResult, 'hash'>> => {\n if (!options?.provider) {\n throw new Error(\n 'Solana transfer requires pluginOptions.provider (a SolanaProvider)',\n );\n }\n\n const connection = resolveConnection(options);\n\n if (!options.provider.publicKey) {\n throw new Error('No public key found in Solana provider.');\n }\n\n // Normalized rather than cast: the SolanaProvider contract only promises a\n // `{ toString(): string }`, not a web3.js PublicKey with `.toBuffer()`.\n const fromPubkey = new PublicKey(options.provider.publicKey.toString());\n\n const toPubkey = new PublicKey(args.address);\n const amount = resolveTransferAmount(args);\n\n if (!args.tokenAddress) {\n const transaction = new Transaction().add(\n SystemProgram.transfer({ fromPubkey, toPubkey, lamports: amount }),\n );\n\n return sendSigned(connection, transaction, options, fromPubkey);\n }\n\n const mintPubkey = new PublicKey(args.tokenAddress);\n const fromTokenAccount = await getAssociatedTokenAddress(\n mintPubkey,\n fromPubkey,\n );\n\n // allowOwnerOffCurve: the 1Click deposit address may be a PDA.\n const toTokenAccount = await getAssociatedTokenAddress(\n mintPubkey,\n toPubkey,\n true,\n );\n\n const toAccountInfo = await connection.getAccountInfo(toTokenAccount);\n const transaction = new Transaction();\n\n if (!toAccountInfo) {\n // Idempotent: a concurrently created ATA must not fail the signed tx.\n transaction.add(\n createAssociatedTokenAccountIdempotentInstruction(\n fromPubkey,\n toTokenAccount,\n toPubkey,\n mintPubkey,\n ),\n );\n }\n\n transaction.add(\n createTransferCheckedInstruction(\n fromTokenAccount,\n mintPubkey,\n toTokenAccount,\n fromPubkey,\n amount,\n args.decimals,\n ),\n );\n\n return sendSigned(connection, transaction, options, fromPubkey);\n};\n"],"names":["DEFAULT_RPC_URL","resolveConnection","connection","rpcUrl","Connection","sendSigned","transaction","provider","feePayer","blockhash","signedTx","makeTransfer","args","options","fromPubkey","PublicKey","toPubkey","amount","resolveTransferAmount","Transaction","SystemProgram","mintPubkey","fromTokenAccount","getAssociatedTokenAddress","toTokenAccount","toAccountInfo","createAssociatedTokenAccountIdempotentInstruction","createTransferCheckedInstruction"],"mappings":";;;AAoBA,MAAMA,IAAkB,qCAElBC,IAAoB,CAAC;AAAA,EACzB,YAAAC;AAAA,EACA,QAAAC;AACF,MACED,KAAc,IAAIE,EAAWD,KAAUH,CAAe,GAElDK,IAAa,OACjBH,GACAI,GACA,EAAE,UAAAC,EAAA,GACFC,MAC0C;AAC1C,QAAM,EAAE,WAAAC,EAAA,IAAc,MAAMP,EAAW,mBAAA;AAEvC,EAAAI,EAAY,kBAAkBG,GAC9BH,EAAY,WAAWE;AAEvB,QAAME,IAAW,MAAMH,EAAS,gBAAgBD,CAAW;AAM3D,SAAO,EAAE,MALI,MAAMJ,EAAW,mBAAmBQ,EAAS,aAAa;AAAA,IACrE,eAAe;AAAA,IACf,YAAY;AAAA,EAAA,CACb,EAEQ;AACX,GAQaC,IAAoD,OAC/DC,GACAC,MAC0C;AAC1C,MAAI,CAACA,GAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAIJ,QAAMX,IAAaD,EAAkBY,CAAO;AAE5C,MAAI,CAACA,EAAQ,SAAS;AACpB,UAAM,IAAI,MAAM,yCAAyC;AAK3D,QAAMC,IAAa,IAAIC,EAAUF,EAAQ,SAAS,UAAU,UAAU,GAEhEG,IAAW,IAAID,EAAUH,EAAK,OAAO,GACrCK,IAASC,EAAsBN,CAAI;AAEzC,MAAI,CAACA,EAAK,cAAc;AACtB,UAAMN,IAAc,IAAIa,EAAA,EAAc;AAAA,MACpCC,EAAc,SAAS,EAAE,YAAAN,GAAY,UAAAE,GAAU,UAAUC,GAAQ;AAAA,IAAA;AAGnE,WAAOZ,EAAWH,GAAYI,GAAaO,GAASC,CAAU;AAAA,EAChE;AAEA,QAAMO,IAAa,IAAIN,EAAUH,EAAK,YAAY,GAC5CU,IAAmB,MAAMC;AAAA,IAC7BF;AAAA,IACAP;AAAA,EAAA,GAIIU,IAAiB,MAAMD;AAAA,IAC3BF;AAAA,IACAL;AAAA,IACA;AAAA,EAAA,GAGIS,IAAgB,MAAMvB,EAAW,eAAesB,CAAc,GAC9DlB,IAAc,IAAIa,EAAA;AAExB,SAAKM,KAEHnB,EAAY;AAAA,IACVoB;AAAA,MACEZ;AAAA,MACAU;AAAA,MACAR;AAAA,MACAK;AAAA,IAAA;AAAA,EACF,GAIJf,EAAY;AAAA,IACVqB;AAAA,MACEL;AAAA,MACAD;AAAA,MACAG;AAAA,MACAV;AAAA,MACAG;AAAA,MACAL,EAAK;AAAA,IAAA;AAAA,EACP,GAGKP,EAAWH,GAAYI,GAAaO,GAASC,CAAU;AAChE;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WalletIconSpec } from './types';
|
|
2
|
+
type WalletOptionCardProps = {
|
|
3
|
+
onClick: () => void;
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
icons: WalletIconSpec[];
|
|
7
|
+
};
|
|
8
|
+
export declare const WalletOptionCard: ({ onClick, title, description, icons, }: WalletOptionCardProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WalletOption } from './types';
|
|
2
|
+
export type WalletSelectorModalProps = {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
/**
|
|
6
|
+
* Rows to render, in order. Ready-made ones are exported as
|
|
7
|
+
* `EVM_SOLANA_WALLET_OPTION`, `NEAR_WALLET_OPTION` and
|
|
8
|
+
* `STELLAR_WALLET_OPTION` — pass only those whose connector you installed.
|
|
9
|
+
*/
|
|
10
|
+
options: readonly WalletOption[];
|
|
11
|
+
/** Receives the selected option's `id`; wire it to `useWalletSelector.select`. */
|
|
12
|
+
onSelect: (id: string) => void;
|
|
13
|
+
title?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Chain-agnostic connect modal.
|
|
17
|
+
*
|
|
18
|
+
* The widget's version hardcoded the three rows and their `onSelect*` callbacks,
|
|
19
|
+
* which is why it could not be reused without pulling every chain SDK. This one
|
|
20
|
+
* renders whatever options it is handed.
|
|
21
|
+
*/
|
|
22
|
+
export declare const WalletSelectorModal: ({ open, onClose, options, onSelect, title, }: WalletSelectorModalProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AppKit } from '@reown/appkit/react';
|
|
3
|
+
/** Reown's own theme mode. The widget passed its whole Theme and read only this. */
|
|
4
|
+
export type AppKitThemeMode = 'light' | 'dark';
|
|
5
|
+
export type AppKitConfig = {
|
|
6
|
+
appName?: string;
|
|
7
|
+
themeMode?: AppKitThemeMode;
|
|
8
|
+
/**
|
|
9
|
+
* WalletConnect Cloud project id.
|
|
10
|
+
*
|
|
11
|
+
* Defaults to Aurora's so this stays drop-in, but production integrations
|
|
12
|
+
* should register their own — the id identifies the dapp to WalletConnect.
|
|
13
|
+
*/
|
|
14
|
+
projectId?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Per-chain-id RPC overrides.
|
|
17
|
+
*
|
|
18
|
+
* Reown puts its Blockchain API first for supported EVM chains and the Ethers
|
|
19
|
+
* adapter does not fall back when that endpoint is unavailable. Defaults to
|
|
20
|
+
* `DEFAULT_RPC_OVERRIDES` (publicnode); anything not overridden falls back
|
|
21
|
+
* to the chain's public RPC as defined by viem.
|
|
22
|
+
*/
|
|
23
|
+
rpcOverrides?: Readonly<Record<number, string>>;
|
|
24
|
+
};
|
|
25
|
+
type AppKitProviderProps = AppKitConfig & {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
};
|
|
28
|
+
type AppKitContextType = {
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
appKit: AppKit | null;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Default per-chain RPC overrides (publicnode).
|
|
34
|
+
*
|
|
35
|
+
* Reown routes supported EVM chains through its own Blockchain API first, and
|
|
36
|
+
* that endpoint rate-limits under real balance/read traffic (observed as an
|
|
37
|
+
* eth.merkle.io request flood) — the Ethers adapter does not fall back when it
|
|
38
|
+
* refuses. Applied unless the caller passes their own `rpcOverrides`.
|
|
39
|
+
*/
|
|
40
|
+
export declare const DEFAULT_RPC_OVERRIDES: Readonly<Record<number, string>>;
|
|
41
|
+
export declare const initAppKit: ({ appName, themeMode, projectId, rpcOverrides, }?: AppKitConfig) => AppKit;
|
|
42
|
+
export declare const AppKitContext: import('react').Context<AppKitContextType | undefined>;
|
|
43
|
+
export declare const AppKitProvider: ({ children, ...config }: AppKitProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVM + Solana connection via Reown AppKit.
|
|
3
|
+
*
|
|
4
|
+
* Optional peers: `@reown/appkit`, `@reown/appkit-adapter-ethers`,
|
|
5
|
+
* `@reown/appkit-adapter-solana`, `@solana/wallet-adapter-phantom`,
|
|
6
|
+
* `@solana/wallet-adapter-solflare`, `viem`.
|
|
7
|
+
*/
|
|
8
|
+
export { AppKitProvider, AppKitContext, DEFAULT_RPC_OVERRIDES, initAppKit, type AppKitConfig, type AppKitThemeMode, } from './appkit';
|
|
9
|
+
export { useAppKitWallet } from './useAppKitWallet';
|
|
10
|
+
export { useAppKitProviders } from './useAppKitProviders';
|
|
11
|
+
export { useAppKitConnector } from './useAppKitConnector';
|
|
12
|
+
export { useIntentsConnectWallet, type IntentsConnectWalletFamily, type UseIntentsConnectWalletOptions, } from './useIntentsConnectWallet';
|