@unifold/ui-react 0.1.59 → 0.1.60
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/index.js +206 -136
- package/dist/index.mjs +206 -136
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1580,7 +1580,7 @@ var import_react3 = require("react");
|
|
|
1580
1580
|
var import_core6 = require("@unifold/core");
|
|
1581
1581
|
var DEPOSIT_CONFIRM_DELAY_MS = 5e3;
|
|
1582
1582
|
var POLL_INTERVAL_MS = 2500;
|
|
1583
|
-
var POLL_ENDPOINT_INTERVAL_MS =
|
|
1583
|
+
var POLL_ENDPOINT_INTERVAL_MS = 5e3;
|
|
1584
1584
|
var CUTOFF_BUFFER_MS = 6e4;
|
|
1585
1585
|
function useDepositPolling({
|
|
1586
1586
|
userId,
|
|
@@ -5324,6 +5324,56 @@ var React24 = __toESM(require("react"));
|
|
|
5324
5324
|
var import_lucide_react17 = require("lucide-react");
|
|
5325
5325
|
var import_core14 = require("@unifold/core");
|
|
5326
5326
|
|
|
5327
|
+
// src/lib/eip6963-store.ts
|
|
5328
|
+
var import_mipd = require("mipd");
|
|
5329
|
+
var _store = null;
|
|
5330
|
+
function getEip6963Store() {
|
|
5331
|
+
if (typeof window === "undefined") return null;
|
|
5332
|
+
if (!_store) {
|
|
5333
|
+
_store = (0, import_mipd.createStore)();
|
|
5334
|
+
}
|
|
5335
|
+
return _store;
|
|
5336
|
+
}
|
|
5337
|
+
var RDNS_TO_WALLET_ID = {
|
|
5338
|
+
"io.metamask": "metamask",
|
|
5339
|
+
"io.metamask.flask": "metamask",
|
|
5340
|
+
"io.metamask.mmi": "metamask",
|
|
5341
|
+
"app.phantom": "phantom",
|
|
5342
|
+
"com.coinbase.wallet": "coinbase",
|
|
5343
|
+
"com.okex.wallet": "okx",
|
|
5344
|
+
"io.rabby": "rabby",
|
|
5345
|
+
"com.trustwallet.app": "trust",
|
|
5346
|
+
"me.rainbow": "rainbow"
|
|
5347
|
+
};
|
|
5348
|
+
function rdnsToWalletId(rdns) {
|
|
5349
|
+
if (RDNS_TO_WALLET_ID[rdns]) return RDNS_TO_WALLET_ID[rdns];
|
|
5350
|
+
if (rdns.includes("metamask")) return "metamask";
|
|
5351
|
+
if (rdns.includes("phantom")) return "phantom";
|
|
5352
|
+
if (rdns.includes("coinbase")) return "coinbase";
|
|
5353
|
+
if (rdns.includes("okx") || rdns.includes("okex")) return "okx";
|
|
5354
|
+
if (rdns.includes("rabby")) return "rabby";
|
|
5355
|
+
if (rdns.includes("trust")) return "trust";
|
|
5356
|
+
if (rdns.includes("rainbow")) return "rainbow";
|
|
5357
|
+
return "unknown";
|
|
5358
|
+
}
|
|
5359
|
+
function getEip6963Providers() {
|
|
5360
|
+
const store = getEip6963Store();
|
|
5361
|
+
if (!store) return [];
|
|
5362
|
+
return store.getProviders().map((detail) => ({
|
|
5363
|
+
walletId: rdnsToWalletId(detail.info.rdns),
|
|
5364
|
+
provider: detail.provider,
|
|
5365
|
+
info: detail.info
|
|
5366
|
+
}));
|
|
5367
|
+
}
|
|
5368
|
+
function findProviderByWalletId(walletId) {
|
|
5369
|
+
return getEip6963Providers().find((p) => p.walletId === walletId);
|
|
5370
|
+
}
|
|
5371
|
+
function collectAllEip6963EthProviders() {
|
|
5372
|
+
const store = getEip6963Store();
|
|
5373
|
+
if (!store) return [];
|
|
5374
|
+
return store.getProviders().map((d) => d.provider);
|
|
5375
|
+
}
|
|
5376
|
+
|
|
5327
5377
|
// src/components/deposits/browser-wallets/disconnectInjectedBrowserWallet.ts
|
|
5328
5378
|
var SOLANA_DISCONNECT_TYPES = [
|
|
5329
5379
|
"phantom-solana",
|
|
@@ -5364,8 +5414,9 @@ function collectEthereumProvidersForDisconnect(win) {
|
|
|
5364
5414
|
out.push(p);
|
|
5365
5415
|
}
|
|
5366
5416
|
};
|
|
5367
|
-
const
|
|
5368
|
-
|
|
5417
|
+
for (const p of collectAllEip6963EthProviders()) {
|
|
5418
|
+
add(p);
|
|
5419
|
+
}
|
|
5369
5420
|
add(win.ethereum);
|
|
5370
5421
|
add(
|
|
5371
5422
|
win.phantom?.ethereum
|
|
@@ -7425,30 +7476,13 @@ function BrowserWalletButton({
|
|
|
7425
7476
|
}, []);
|
|
7426
7477
|
const [eip6963ProviderCount, setEip6963ProviderCount] = React24.useState(0);
|
|
7427
7478
|
React24.useEffect(() => {
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
if (!detail?.info || !detail?.provider) return;
|
|
7436
|
-
const exists = anyWin.__eip6963Providers.some(
|
|
7437
|
-
(p) => p.info.uuid === detail.info.uuid
|
|
7438
|
-
);
|
|
7439
|
-
if (!exists) {
|
|
7440
|
-
anyWin.__eip6963Providers.push(detail);
|
|
7441
|
-
setEip6963ProviderCount(anyWin.__eip6963Providers.length);
|
|
7442
|
-
}
|
|
7443
|
-
};
|
|
7444
|
-
window.addEventListener("eip6963:announceProvider", handleAnnouncement);
|
|
7445
|
-
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
7446
|
-
return () => {
|
|
7447
|
-
window.removeEventListener(
|
|
7448
|
-
"eip6963:announceProvider",
|
|
7449
|
-
handleAnnouncement
|
|
7450
|
-
);
|
|
7451
|
-
};
|
|
7479
|
+
const store = getEip6963Store();
|
|
7480
|
+
if (!store) return;
|
|
7481
|
+
setEip6963ProviderCount(store.getProviders().length);
|
|
7482
|
+
const unsubscribe = store.subscribe((providers) => {
|
|
7483
|
+
setEip6963ProviderCount(providers.length);
|
|
7484
|
+
});
|
|
7485
|
+
return unsubscribe;
|
|
7452
7486
|
}, []);
|
|
7453
7487
|
React24.useEffect(() => {
|
|
7454
7488
|
if (!wallet || !publishableKey) {
|
|
@@ -7507,7 +7541,7 @@ function BrowserWalletButton({
|
|
|
7507
7541
|
return;
|
|
7508
7542
|
}
|
|
7509
7543
|
if (!chainType || chainType === "solana") {
|
|
7510
|
-
const
|
|
7544
|
+
const anyWin = win;
|
|
7511
7545
|
const trySilentSolana = async (provider, type, name, icon) => {
|
|
7512
7546
|
if (!provider) return false;
|
|
7513
7547
|
if (provider.isConnected && provider.publicKey) {
|
|
@@ -7546,21 +7580,21 @@ function BrowserWalletButton({
|
|
|
7546
7580
|
))
|
|
7547
7581
|
return;
|
|
7548
7582
|
if (await trySilentSolana(
|
|
7549
|
-
|
|
7583
|
+
anyWin.solflare,
|
|
7550
7584
|
"solflare",
|
|
7551
7585
|
"Solflare",
|
|
7552
7586
|
"solflare"
|
|
7553
7587
|
))
|
|
7554
7588
|
return;
|
|
7555
7589
|
if (await trySilentSolana(
|
|
7556
|
-
|
|
7590
|
+
anyWin.backpack,
|
|
7557
7591
|
"backpack",
|
|
7558
7592
|
"Backpack",
|
|
7559
7593
|
"backpack"
|
|
7560
7594
|
))
|
|
7561
7595
|
return;
|
|
7562
7596
|
if (await trySilentSolana(
|
|
7563
|
-
|
|
7597
|
+
anyWin.glow,
|
|
7564
7598
|
"glow",
|
|
7565
7599
|
"Glow",
|
|
7566
7600
|
"glow"
|
|
@@ -7568,19 +7602,14 @@ function BrowserWalletButton({
|
|
|
7568
7602
|
return;
|
|
7569
7603
|
}
|
|
7570
7604
|
if (!chainType || chainType === "ethereum") {
|
|
7571
|
-
const
|
|
7605
|
+
const anyWin = win;
|
|
7572
7606
|
const allProviders = [];
|
|
7573
|
-
const
|
|
7574
|
-
for (const {
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
else if (info.rdns.includes("okx")) walletId = "okx";
|
|
7580
|
-
else if (info.rdns.includes("rabby")) walletId = "rabby";
|
|
7581
|
-
else if (info.rdns.includes("trust")) walletId = "trust";
|
|
7582
|
-
else if (info.rdns.includes("rainbow")) walletId = "rainbow";
|
|
7583
|
-
allProviders.push({ provider, walletId });
|
|
7607
|
+
const eip6963 = getEip6963Providers();
|
|
7608
|
+
for (const { provider, walletId } of eip6963) {
|
|
7609
|
+
allProviders.push({
|
|
7610
|
+
provider,
|
|
7611
|
+
walletId: walletId === "unknown" ? "default" : walletId
|
|
7612
|
+
});
|
|
7584
7613
|
}
|
|
7585
7614
|
if (allProviders.length === 0) {
|
|
7586
7615
|
if (win.phantom?.ethereum) {
|
|
@@ -7589,15 +7618,15 @@ function BrowserWalletButton({
|
|
|
7589
7618
|
walletId: "phantom"
|
|
7590
7619
|
});
|
|
7591
7620
|
}
|
|
7592
|
-
if (
|
|
7621
|
+
if (anyWin.okxwallet) {
|
|
7593
7622
|
allProviders.push({
|
|
7594
|
-
provider:
|
|
7623
|
+
provider: anyWin.okxwallet,
|
|
7595
7624
|
walletId: "okx"
|
|
7596
7625
|
});
|
|
7597
7626
|
}
|
|
7598
|
-
if (
|
|
7627
|
+
if (anyWin.coinbaseWalletExtension) {
|
|
7599
7628
|
allProviders.push({
|
|
7600
|
-
provider:
|
|
7629
|
+
provider: anyWin.coinbaseWalletExtension,
|
|
7601
7630
|
walletId: "coinbase"
|
|
7602
7631
|
});
|
|
7603
7632
|
}
|
|
@@ -7621,7 +7650,7 @@ function BrowserWalletButton({
|
|
|
7621
7650
|
});
|
|
7622
7651
|
if (!accounts || accounts.length === 0) continue;
|
|
7623
7652
|
const address = accounts[0];
|
|
7624
|
-
const resolved = identifyEthWallet(provider,
|
|
7653
|
+
const resolved = identifyEthWallet(provider, anyWin, walletId);
|
|
7625
7654
|
if (mounted) {
|
|
7626
7655
|
setWallet({ ...resolved, address });
|
|
7627
7656
|
setIsLoading(false);
|
|
@@ -7663,15 +7692,11 @@ function BrowserWalletButton({
|
|
|
7663
7692
|
solanaProvider.on("disconnect", handleDisconnect);
|
|
7664
7693
|
solanaProvider.on("accountChanged", handleAccountsChanged);
|
|
7665
7694
|
}
|
|
7666
|
-
const anyWin = window;
|
|
7667
7695
|
const ethProviders = [];
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
if (provider && !ethProviders.includes(provider)) {
|
|
7673
|
-
ethProviders.push(provider);
|
|
7674
|
-
}
|
|
7696
|
+
for (const { provider } of getEip6963Providers()) {
|
|
7697
|
+
const p = provider;
|
|
7698
|
+
if (p && !ethProviders.includes(p)) {
|
|
7699
|
+
ethProviders.push(p);
|
|
7675
7700
|
}
|
|
7676
7701
|
}
|
|
7677
7702
|
if (window.ethereum && !ethProviders.includes(window.ethereum)) {
|
|
@@ -7773,7 +7798,7 @@ function BrowserWalletButton({
|
|
|
7773
7798
|
if (isLoading) {
|
|
7774
7799
|
return null;
|
|
7775
7800
|
}
|
|
7776
|
-
const hasWalletExtension = (!chainType || chainType === "solana") && (window.phantom?.solana?.isPhantom || window.solana?.isPhantom)
|
|
7801
|
+
const hasWalletExtension = (!chainType || chainType === "ethereum") && getEip6963Providers().length > 0 || (!chainType || chainType === "solana") && (window.phantom?.solana?.isPhantom || window.solana?.isPhantom) || (!chainType || chainType === "ethereum") && (window.phantom?.ethereum || window.ethereum);
|
|
7777
7802
|
if (!onConnectClick && !wallet && !hasWalletExtension) {
|
|
7778
7803
|
return null;
|
|
7779
7804
|
}
|
|
@@ -13456,15 +13481,10 @@ var WALLET_DEFINITIONS = [
|
|
|
13456
13481
|
{ id: "backpack", name: "Backpack", networks: ["solana"], installUrl: "https://backpack.app/" },
|
|
13457
13482
|
{ id: "glow", name: "Glow", networks: ["solana"], installUrl: "https://glow.app/" }
|
|
13458
13483
|
];
|
|
13459
|
-
function
|
|
13484
|
+
function getSolanaProviders() {
|
|
13460
13485
|
if (typeof window === "undefined") return {};
|
|
13461
13486
|
const win = window;
|
|
13462
13487
|
return {
|
|
13463
|
-
ethereum: win.ethereum,
|
|
13464
|
-
phantomEthereum: win.phantom?.ethereum,
|
|
13465
|
-
coinbaseEthereum: win.coinbaseWalletExtension,
|
|
13466
|
-
trustEthereum: win.trustwallet?.ethereum,
|
|
13467
|
-
okxEthereum: win.okxwallet,
|
|
13468
13488
|
phantomSolana: win.phantom?.solana,
|
|
13469
13489
|
solflare: win.solflare,
|
|
13470
13490
|
backpack: win.backpack,
|
|
@@ -13472,37 +13492,71 @@ function getWalletProviders() {
|
|
|
13472
13492
|
coinbaseSolana: win.coinbaseSolana || win.coinbaseWalletExtension?.solana
|
|
13473
13493
|
};
|
|
13474
13494
|
}
|
|
13495
|
+
function getLegacyEvmProviders() {
|
|
13496
|
+
if (typeof window === "undefined") return {};
|
|
13497
|
+
const win = window;
|
|
13498
|
+
return {
|
|
13499
|
+
ethereum: win.ethereum,
|
|
13500
|
+
phantomEthereum: win.phantom?.ethereum,
|
|
13501
|
+
coinbaseEthereum: win.coinbaseWalletExtension,
|
|
13502
|
+
trustEthereum: win.trustwallet?.ethereum,
|
|
13503
|
+
okxEthereum: win.okxwallet
|
|
13504
|
+
};
|
|
13505
|
+
}
|
|
13475
13506
|
function detectAvailableWallets(filterChainType) {
|
|
13476
|
-
const
|
|
13507
|
+
const solProviders = getSolanaProviders();
|
|
13508
|
+
const legacyEvm = getLegacyEvmProviders();
|
|
13509
|
+
const eip6963List = getEip6963Providers();
|
|
13477
13510
|
const win = typeof window !== "undefined" ? window : null;
|
|
13511
|
+
const hasEip6963 = (walletId) => eip6963List.some((d) => {
|
|
13512
|
+
const rdns = d.info?.rdns || "";
|
|
13513
|
+
switch (walletId) {
|
|
13514
|
+
case "metamask":
|
|
13515
|
+
return rdns.includes("metamask");
|
|
13516
|
+
case "phantom":
|
|
13517
|
+
return rdns.includes("phantom");
|
|
13518
|
+
case "coinbase":
|
|
13519
|
+
return rdns.includes("coinbase");
|
|
13520
|
+
case "trust":
|
|
13521
|
+
return rdns.includes("trust");
|
|
13522
|
+
case "rainbow":
|
|
13523
|
+
return rdns.includes("rainbow");
|
|
13524
|
+
case "rabby":
|
|
13525
|
+
return rdns.includes("rabby");
|
|
13526
|
+
case "okx":
|
|
13527
|
+
return rdns.includes("okx") || rdns.includes("okex");
|
|
13528
|
+
default:
|
|
13529
|
+
return false;
|
|
13530
|
+
}
|
|
13531
|
+
});
|
|
13478
13532
|
return WALLET_DEFINITIONS.filter((w) => !filterChainType || w.networks.includes(filterChainType)).map((wallet) => {
|
|
13479
13533
|
let isInstalled = false;
|
|
13480
13534
|
const detectedNetworks = [];
|
|
13481
13535
|
switch (wallet.id) {
|
|
13482
13536
|
case "metamask":
|
|
13483
|
-
isInstalled = !!(
|
|
13537
|
+
isInstalled = hasEip6963("metamask") || !!(legacyEvm.ethereum?.isMetaMask && !legacyEvm.ethereum?.isPhantom && !legacyEvm.ethereum?.isRabby && !legacyEvm.ethereum?.isOkxWallet);
|
|
13484
13538
|
if (isInstalled) detectedNetworks.push("ethereum");
|
|
13485
13539
|
break;
|
|
13486
13540
|
case "phantom":
|
|
13487
|
-
if (
|
|
13541
|
+
if (solProviders.phantomSolana?.isPhantom) {
|
|
13488
13542
|
isInstalled = true;
|
|
13489
13543
|
detectedNetworks.push("solana");
|
|
13490
13544
|
}
|
|
13491
|
-
if (
|
|
13545
|
+
if (hasEip6963("phantom") || legacyEvm.phantomEthereum?.isPhantom) {
|
|
13492
13546
|
isInstalled = true;
|
|
13493
13547
|
detectedNetworks.push("ethereum");
|
|
13494
13548
|
}
|
|
13495
13549
|
break;
|
|
13496
13550
|
case "coinbase":
|
|
13497
|
-
if (
|
|
13551
|
+
if (hasEip6963("coinbase") || legacyEvm.coinbaseEthereum || legacyEvm.ethereum?.isCoinbaseWallet) {
|
|
13498
13552
|
isInstalled = true;
|
|
13499
13553
|
detectedNetworks.push("ethereum");
|
|
13500
13554
|
}
|
|
13501
|
-
if (
|
|
13555
|
+
if (solProviders.coinbaseSolana || win?.coinbaseWalletExtension?.solana) detectedNetworks.push("solana");
|
|
13502
13556
|
if (isInstalled && wallet.networks.includes("solana") && !detectedNetworks.includes("solana")) detectedNetworks.push("solana");
|
|
13503
13557
|
break;
|
|
13504
13558
|
case "trust":
|
|
13505
|
-
if (
|
|
13559
|
+
if (hasEip6963("trust") || legacyEvm.trustEthereum || legacyEvm.ethereum?.isTrust || win?.trustwallet) {
|
|
13506
13560
|
isInstalled = true;
|
|
13507
13561
|
detectedNetworks.push("ethereum");
|
|
13508
13562
|
}
|
|
@@ -13510,27 +13564,27 @@ function detectAvailableWallets(filterChainType) {
|
|
|
13510
13564
|
if (isInstalled && wallet.networks.includes("solana") && !detectedNetworks.includes("solana")) detectedNetworks.push("solana");
|
|
13511
13565
|
break;
|
|
13512
13566
|
case "rainbow":
|
|
13513
|
-
isInstalled = !!
|
|
13567
|
+
isInstalled = hasEip6963("rainbow") || !!legacyEvm.ethereum?.isRainbow;
|
|
13514
13568
|
if (isInstalled) detectedNetworks.push("ethereum");
|
|
13515
13569
|
break;
|
|
13516
13570
|
case "rabby":
|
|
13517
|
-
isInstalled = !!
|
|
13571
|
+
isInstalled = hasEip6963("rabby") || !!legacyEvm.ethereum?.isRabby;
|
|
13518
13572
|
if (isInstalled) detectedNetworks.push("ethereum");
|
|
13519
13573
|
break;
|
|
13520
13574
|
case "okx":
|
|
13521
|
-
isInstalled = !!(
|
|
13575
|
+
isInstalled = hasEip6963("okx") || !!(legacyEvm.okxEthereum || legacyEvm.ethereum?.isOkxWallet);
|
|
13522
13576
|
if (isInstalled) detectedNetworks.push("ethereum");
|
|
13523
13577
|
break;
|
|
13524
13578
|
case "solflare":
|
|
13525
|
-
isInstalled = !!
|
|
13579
|
+
isInstalled = !!solProviders.solflare?.isSolflare;
|
|
13526
13580
|
if (isInstalled) detectedNetworks.push("solana");
|
|
13527
13581
|
break;
|
|
13528
13582
|
case "backpack":
|
|
13529
|
-
isInstalled = !!(
|
|
13583
|
+
isInstalled = !!(solProviders.backpack?.isBackpack || win?.backpack);
|
|
13530
13584
|
if (isInstalled) detectedNetworks.push("solana");
|
|
13531
13585
|
break;
|
|
13532
13586
|
case "glow":
|
|
13533
|
-
isInstalled = !!(
|
|
13587
|
+
isInstalled = !!(solProviders.glow?.isGlow || win?.glow);
|
|
13534
13588
|
if (isInstalled) detectedNetworks.push("solana");
|
|
13535
13589
|
break;
|
|
13536
13590
|
}
|
|
@@ -13585,7 +13639,16 @@ function WalletConnect({
|
|
|
13585
13639
|
const [connectingNetwork, setConnectingNetwork] = React29.useState(null);
|
|
13586
13640
|
const [walletError, setWalletError] = React29.useState(null);
|
|
13587
13641
|
const [isWalletConnecting, setIsWalletConnecting] = React29.useState(false);
|
|
13588
|
-
const
|
|
13642
|
+
const [eip6963ProviderCount, setEip6963ProviderCount] = React29.useState(0);
|
|
13643
|
+
React29.useEffect(() => {
|
|
13644
|
+
const store = getEip6963Store();
|
|
13645
|
+
if (!store) return;
|
|
13646
|
+
setEip6963ProviderCount(store.getProviders().length);
|
|
13647
|
+
return store.subscribe((providers) => {
|
|
13648
|
+
setEip6963ProviderCount(providers.length);
|
|
13649
|
+
});
|
|
13650
|
+
}, []);
|
|
13651
|
+
const availableWallets = React29.useMemo(() => detectAvailableWallets(), [eip6963ProviderCount]);
|
|
13589
13652
|
const [balances, setBalances] = React29.useState([]);
|
|
13590
13653
|
const [isLoading, setIsLoading] = React29.useState(false);
|
|
13591
13654
|
const [selectedBalance, setSelectedBalance] = React29.useState(null);
|
|
@@ -13644,59 +13707,72 @@ function WalletConnect({
|
|
|
13644
13707
|
setWalletError(null);
|
|
13645
13708
|
setIsWalletConnecting(true);
|
|
13646
13709
|
try {
|
|
13647
|
-
const providers = getWalletProviders();
|
|
13648
13710
|
const win = typeof window !== "undefined" ? window : null;
|
|
13649
13711
|
let connectedInfo;
|
|
13650
13712
|
if (network === "ethereum") {
|
|
13651
|
-
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13658
|
-
|
|
13659
|
-
|
|
13660
|
-
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13665
|
-
|
|
13666
|
-
|
|
13667
|
-
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
|
|
13672
|
-
|
|
13673
|
-
|
|
13674
|
-
|
|
13675
|
-
|
|
13713
|
+
const eip6963Match = findProviderByWalletId(wallet.id);
|
|
13714
|
+
let provider = eip6963Match?.provider;
|
|
13715
|
+
if (!provider) {
|
|
13716
|
+
const legacyEvm = getLegacyEvmProviders();
|
|
13717
|
+
switch (wallet.id) {
|
|
13718
|
+
case "metamask":
|
|
13719
|
+
if (legacyEvm.ethereum?.isMetaMask && !legacyEvm.ethereum?.isPhantom) provider = legacyEvm.ethereum;
|
|
13720
|
+
break;
|
|
13721
|
+
case "phantom":
|
|
13722
|
+
provider = legacyEvm.phantomEthereum;
|
|
13723
|
+
break;
|
|
13724
|
+
case "coinbase":
|
|
13725
|
+
provider = legacyEvm.coinbaseEthereum || (legacyEvm.ethereum?.isCoinbaseWallet ? legacyEvm.ethereum : void 0);
|
|
13726
|
+
break;
|
|
13727
|
+
case "trust":
|
|
13728
|
+
provider = legacyEvm.trustEthereum || (legacyEvm.ethereum?.isTrust ? legacyEvm.ethereum : void 0);
|
|
13729
|
+
break;
|
|
13730
|
+
case "rainbow":
|
|
13731
|
+
if (legacyEvm.ethereum?.isRainbow) provider = legacyEvm.ethereum;
|
|
13732
|
+
break;
|
|
13733
|
+
case "rabby":
|
|
13734
|
+
if (legacyEvm.ethereum?.isRabby) provider = legacyEvm.ethereum;
|
|
13735
|
+
break;
|
|
13736
|
+
case "okx":
|
|
13737
|
+
provider = legacyEvm.okxEthereum || (legacyEvm.ethereum?.isOkxWallet ? legacyEvm.ethereum : void 0);
|
|
13738
|
+
break;
|
|
13739
|
+
default:
|
|
13740
|
+
provider = legacyEvm.ethereum;
|
|
13741
|
+
}
|
|
13676
13742
|
}
|
|
13677
13743
|
if (!provider) throw new Error(`${wallet.name} wallet not found. Please install it.`);
|
|
13678
13744
|
const accounts = await provider.request({ method: "eth_requestAccounts" });
|
|
13679
13745
|
if (!accounts?.length) throw new Error("No accounts returned from wallet");
|
|
13680
13746
|
setUserDisconnectedWallet(false);
|
|
13681
|
-
const
|
|
13747
|
+
const walletIdToType = {
|
|
13748
|
+
phantom: "phantom-ethereum",
|
|
13749
|
+
coinbase: "coinbase",
|
|
13750
|
+
trust: "trust",
|
|
13751
|
+
rainbow: "rainbow",
|
|
13752
|
+
rabby: "rabby",
|
|
13753
|
+
okx: "okx",
|
|
13754
|
+
metamask: "metamask"
|
|
13755
|
+
};
|
|
13756
|
+
const walletType = walletIdToType[wallet.id] || "metamask";
|
|
13682
13757
|
connectedInfo = { type: walletType, name: wallet.name, address: accounts[0], icon: wallet.id };
|
|
13683
13758
|
} else {
|
|
13759
|
+
const solProviders = getSolanaProviders();
|
|
13684
13760
|
let provider;
|
|
13685
13761
|
switch (wallet.id) {
|
|
13686
13762
|
case "phantom":
|
|
13687
|
-
provider =
|
|
13763
|
+
provider = solProviders.phantomSolana;
|
|
13688
13764
|
break;
|
|
13689
13765
|
case "solflare":
|
|
13690
|
-
provider =
|
|
13766
|
+
provider = solProviders.solflare;
|
|
13691
13767
|
break;
|
|
13692
13768
|
case "backpack":
|
|
13693
|
-
provider =
|
|
13769
|
+
provider = solProviders.backpack || win?.backpack;
|
|
13694
13770
|
break;
|
|
13695
13771
|
case "glow":
|
|
13696
|
-
provider =
|
|
13772
|
+
provider = solProviders.glow || win?.glow;
|
|
13697
13773
|
break;
|
|
13698
13774
|
case "coinbase":
|
|
13699
|
-
provider =
|
|
13775
|
+
provider = solProviders.coinbaseSolana || win?.coinbaseWalletExtension?.solana;
|
|
13700
13776
|
break;
|
|
13701
13777
|
case "trust":
|
|
13702
13778
|
provider = win?.trustwallet?.solana;
|
|
@@ -13942,10 +14018,15 @@ function WalletConnect({
|
|
|
13942
14018
|
};
|
|
13943
14019
|
const sendEthereumTransaction = async (token, amountStr) => {
|
|
13944
14020
|
if (!recipientAddress || !/^0x[a-fA-F0-9]{40}$/.test(recipientAddress)) throw new Error(`Invalid recipient address.`);
|
|
13945
|
-
|
|
13946
|
-
|
|
13947
|
-
|
|
13948
|
-
|
|
14021
|
+
const walletIdMap = { "phantom-ethereum": "phantom", coinbase: "coinbase", trust: "trust", okx: "okx", rainbow: "rainbow", rabby: "rabby", metamask: "metamask" };
|
|
14022
|
+
const lookupId = walletIdMap[walletInfo.type] || walletInfo.type;
|
|
14023
|
+
const eip6963Match = findProviderByWalletId(lookupId);
|
|
14024
|
+
let provider = eip6963Match?.provider;
|
|
14025
|
+
if (!provider) {
|
|
14026
|
+
if (walletInfo.type === "phantom-ethereum") provider = window.phantom?.ethereum;
|
|
14027
|
+
else if (walletInfo.type === "coinbase") provider = window.coinbaseWalletExtension || window.ethereum;
|
|
14028
|
+
else provider = window.ethereum;
|
|
14029
|
+
}
|
|
13949
14030
|
if (!provider) throw new Error("Ethereum wallet not found");
|
|
13950
14031
|
const currentChainIdHex = await provider.request({ method: "eth_chainId", params: [] });
|
|
13951
14032
|
if (parseInt(currentChainIdHex, 16).toString() !== token.chain_id) {
|
|
@@ -15819,7 +15900,7 @@ function useExecutions(userId, publishableKey, options) {
|
|
|
15819
15900
|
var import_react22 = require("react");
|
|
15820
15901
|
var import_core35 = require("@unifold/core");
|
|
15821
15902
|
var POLL_INTERVAL_MS3 = 2500;
|
|
15822
|
-
var POLL_ENDPOINT_INTERVAL_MS2 =
|
|
15903
|
+
var POLL_ENDPOINT_INTERVAL_MS2 = 5e3;
|
|
15823
15904
|
var CUTOFF_BUFFER_MS2 = 6e4;
|
|
15824
15905
|
function useWithdrawPolling({
|
|
15825
15906
|
userId,
|
|
@@ -16324,29 +16405,18 @@ async function detectBrowserWallet(chainType, senderAddress) {
|
|
|
16324
16405
|
evmProviders.push({ provider: p, name });
|
|
16325
16406
|
}
|
|
16326
16407
|
};
|
|
16327
|
-
|
|
16328
|
-
|
|
16329
|
-
|
|
16330
|
-
|
|
16331
|
-
|
|
16332
|
-
|
|
16333
|
-
|
|
16334
|
-
|
|
16408
|
+
const eip6963 = getEip6963Providers();
|
|
16409
|
+
const walletIdToName = {
|
|
16410
|
+
metamask: "MetaMask",
|
|
16411
|
+
phantom: "Phantom",
|
|
16412
|
+
coinbase: "Coinbase",
|
|
16413
|
+
rabby: "Rabby",
|
|
16414
|
+
rainbow: "Rainbow",
|
|
16415
|
+
okx: "OKX Wallet",
|
|
16416
|
+
trust: "Trust Wallet"
|
|
16335
16417
|
};
|
|
16336
|
-
|
|
16337
|
-
|
|
16338
|
-
win.removeEventListener("eip6963:announceProvider", handleAnnouncement);
|
|
16339
|
-
for (const detail of anyWin.__eip6963Providers) {
|
|
16340
|
-
const rdns = detail.info?.rdns || "";
|
|
16341
|
-
let name = detail.info?.name || "Wallet";
|
|
16342
|
-
if (rdns.includes("metamask")) name = "MetaMask";
|
|
16343
|
-
else if (rdns.includes("phantom")) name = "Phantom";
|
|
16344
|
-
else if (rdns.includes("coinbase")) name = "Coinbase";
|
|
16345
|
-
else if (rdns.includes("rabby")) name = "Rabby";
|
|
16346
|
-
else if (rdns.includes("rainbow")) name = "Rainbow";
|
|
16347
|
-
else if (rdns.includes("okx")) name = "OKX Wallet";
|
|
16348
|
-
else if (rdns.includes("trust")) name = "Trust Wallet";
|
|
16349
|
-
add(detail.provider, name);
|
|
16418
|
+
for (const { provider, walletId, info } of eip6963) {
|
|
16419
|
+
add(provider, walletIdToName[walletId] || info.name || "Wallet");
|
|
16350
16420
|
}
|
|
16351
16421
|
if (evmProviders.length === 0) {
|
|
16352
16422
|
add(anyWin.phantom?.ethereum, "Phantom");
|
package/dist/index.mjs
CHANGED
|
@@ -1491,7 +1491,7 @@ import {
|
|
|
1491
1491
|
} from "@unifold/core";
|
|
1492
1492
|
var DEPOSIT_CONFIRM_DELAY_MS = 5e3;
|
|
1493
1493
|
var POLL_INTERVAL_MS = 2500;
|
|
1494
|
-
var POLL_ENDPOINT_INTERVAL_MS =
|
|
1494
|
+
var POLL_ENDPOINT_INTERVAL_MS = 5e3;
|
|
1495
1495
|
var CUTOFF_BUFFER_MS = 6e4;
|
|
1496
1496
|
function useDepositPolling({
|
|
1497
1497
|
userId,
|
|
@@ -5253,6 +5253,56 @@ import * as React24 from "react";
|
|
|
5253
5253
|
import { Wallet, ChevronRight as ChevronRight10, Loader2 as Loader23 } from "lucide-react";
|
|
5254
5254
|
import { getAddressBalances } from "@unifold/core";
|
|
5255
5255
|
|
|
5256
|
+
// src/lib/eip6963-store.ts
|
|
5257
|
+
import { createStore } from "mipd";
|
|
5258
|
+
var _store = null;
|
|
5259
|
+
function getEip6963Store() {
|
|
5260
|
+
if (typeof window === "undefined") return null;
|
|
5261
|
+
if (!_store) {
|
|
5262
|
+
_store = createStore();
|
|
5263
|
+
}
|
|
5264
|
+
return _store;
|
|
5265
|
+
}
|
|
5266
|
+
var RDNS_TO_WALLET_ID = {
|
|
5267
|
+
"io.metamask": "metamask",
|
|
5268
|
+
"io.metamask.flask": "metamask",
|
|
5269
|
+
"io.metamask.mmi": "metamask",
|
|
5270
|
+
"app.phantom": "phantom",
|
|
5271
|
+
"com.coinbase.wallet": "coinbase",
|
|
5272
|
+
"com.okex.wallet": "okx",
|
|
5273
|
+
"io.rabby": "rabby",
|
|
5274
|
+
"com.trustwallet.app": "trust",
|
|
5275
|
+
"me.rainbow": "rainbow"
|
|
5276
|
+
};
|
|
5277
|
+
function rdnsToWalletId(rdns) {
|
|
5278
|
+
if (RDNS_TO_WALLET_ID[rdns]) return RDNS_TO_WALLET_ID[rdns];
|
|
5279
|
+
if (rdns.includes("metamask")) return "metamask";
|
|
5280
|
+
if (rdns.includes("phantom")) return "phantom";
|
|
5281
|
+
if (rdns.includes("coinbase")) return "coinbase";
|
|
5282
|
+
if (rdns.includes("okx") || rdns.includes("okex")) return "okx";
|
|
5283
|
+
if (rdns.includes("rabby")) return "rabby";
|
|
5284
|
+
if (rdns.includes("trust")) return "trust";
|
|
5285
|
+
if (rdns.includes("rainbow")) return "rainbow";
|
|
5286
|
+
return "unknown";
|
|
5287
|
+
}
|
|
5288
|
+
function getEip6963Providers() {
|
|
5289
|
+
const store = getEip6963Store();
|
|
5290
|
+
if (!store) return [];
|
|
5291
|
+
return store.getProviders().map((detail) => ({
|
|
5292
|
+
walletId: rdnsToWalletId(detail.info.rdns),
|
|
5293
|
+
provider: detail.provider,
|
|
5294
|
+
info: detail.info
|
|
5295
|
+
}));
|
|
5296
|
+
}
|
|
5297
|
+
function findProviderByWalletId(walletId) {
|
|
5298
|
+
return getEip6963Providers().find((p) => p.walletId === walletId);
|
|
5299
|
+
}
|
|
5300
|
+
function collectAllEip6963EthProviders() {
|
|
5301
|
+
const store = getEip6963Store();
|
|
5302
|
+
if (!store) return [];
|
|
5303
|
+
return store.getProviders().map((d) => d.provider);
|
|
5304
|
+
}
|
|
5305
|
+
|
|
5256
5306
|
// src/components/deposits/browser-wallets/disconnectInjectedBrowserWallet.ts
|
|
5257
5307
|
var SOLANA_DISCONNECT_TYPES = [
|
|
5258
5308
|
"phantom-solana",
|
|
@@ -5293,8 +5343,9 @@ function collectEthereumProvidersForDisconnect(win) {
|
|
|
5293
5343
|
out.push(p);
|
|
5294
5344
|
}
|
|
5295
5345
|
};
|
|
5296
|
-
const
|
|
5297
|
-
|
|
5346
|
+
for (const p of collectAllEip6963EthProviders()) {
|
|
5347
|
+
add(p);
|
|
5348
|
+
}
|
|
5298
5349
|
add(win.ethereum);
|
|
5299
5350
|
add(
|
|
5300
5351
|
win.phantom?.ethereum
|
|
@@ -7354,30 +7405,13 @@ function BrowserWalletButton({
|
|
|
7354
7405
|
}, []);
|
|
7355
7406
|
const [eip6963ProviderCount, setEip6963ProviderCount] = React24.useState(0);
|
|
7356
7407
|
React24.useEffect(() => {
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
if (!detail?.info || !detail?.provider) return;
|
|
7365
|
-
const exists = anyWin.__eip6963Providers.some(
|
|
7366
|
-
(p) => p.info.uuid === detail.info.uuid
|
|
7367
|
-
);
|
|
7368
|
-
if (!exists) {
|
|
7369
|
-
anyWin.__eip6963Providers.push(detail);
|
|
7370
|
-
setEip6963ProviderCount(anyWin.__eip6963Providers.length);
|
|
7371
|
-
}
|
|
7372
|
-
};
|
|
7373
|
-
window.addEventListener("eip6963:announceProvider", handleAnnouncement);
|
|
7374
|
-
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
7375
|
-
return () => {
|
|
7376
|
-
window.removeEventListener(
|
|
7377
|
-
"eip6963:announceProvider",
|
|
7378
|
-
handleAnnouncement
|
|
7379
|
-
);
|
|
7380
|
-
};
|
|
7408
|
+
const store = getEip6963Store();
|
|
7409
|
+
if (!store) return;
|
|
7410
|
+
setEip6963ProviderCount(store.getProviders().length);
|
|
7411
|
+
const unsubscribe = store.subscribe((providers) => {
|
|
7412
|
+
setEip6963ProviderCount(providers.length);
|
|
7413
|
+
});
|
|
7414
|
+
return unsubscribe;
|
|
7381
7415
|
}, []);
|
|
7382
7416
|
React24.useEffect(() => {
|
|
7383
7417
|
if (!wallet || !publishableKey) {
|
|
@@ -7436,7 +7470,7 @@ function BrowserWalletButton({
|
|
|
7436
7470
|
return;
|
|
7437
7471
|
}
|
|
7438
7472
|
if (!chainType || chainType === "solana") {
|
|
7439
|
-
const
|
|
7473
|
+
const anyWin = win;
|
|
7440
7474
|
const trySilentSolana = async (provider, type, name, icon) => {
|
|
7441
7475
|
if (!provider) return false;
|
|
7442
7476
|
if (provider.isConnected && provider.publicKey) {
|
|
@@ -7475,21 +7509,21 @@ function BrowserWalletButton({
|
|
|
7475
7509
|
))
|
|
7476
7510
|
return;
|
|
7477
7511
|
if (await trySilentSolana(
|
|
7478
|
-
|
|
7512
|
+
anyWin.solflare,
|
|
7479
7513
|
"solflare",
|
|
7480
7514
|
"Solflare",
|
|
7481
7515
|
"solflare"
|
|
7482
7516
|
))
|
|
7483
7517
|
return;
|
|
7484
7518
|
if (await trySilentSolana(
|
|
7485
|
-
|
|
7519
|
+
anyWin.backpack,
|
|
7486
7520
|
"backpack",
|
|
7487
7521
|
"Backpack",
|
|
7488
7522
|
"backpack"
|
|
7489
7523
|
))
|
|
7490
7524
|
return;
|
|
7491
7525
|
if (await trySilentSolana(
|
|
7492
|
-
|
|
7526
|
+
anyWin.glow,
|
|
7493
7527
|
"glow",
|
|
7494
7528
|
"Glow",
|
|
7495
7529
|
"glow"
|
|
@@ -7497,19 +7531,14 @@ function BrowserWalletButton({
|
|
|
7497
7531
|
return;
|
|
7498
7532
|
}
|
|
7499
7533
|
if (!chainType || chainType === "ethereum") {
|
|
7500
|
-
const
|
|
7534
|
+
const anyWin = win;
|
|
7501
7535
|
const allProviders = [];
|
|
7502
|
-
const
|
|
7503
|
-
for (const {
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
else if (info.rdns.includes("okx")) walletId = "okx";
|
|
7509
|
-
else if (info.rdns.includes("rabby")) walletId = "rabby";
|
|
7510
|
-
else if (info.rdns.includes("trust")) walletId = "trust";
|
|
7511
|
-
else if (info.rdns.includes("rainbow")) walletId = "rainbow";
|
|
7512
|
-
allProviders.push({ provider, walletId });
|
|
7536
|
+
const eip6963 = getEip6963Providers();
|
|
7537
|
+
for (const { provider, walletId } of eip6963) {
|
|
7538
|
+
allProviders.push({
|
|
7539
|
+
provider,
|
|
7540
|
+
walletId: walletId === "unknown" ? "default" : walletId
|
|
7541
|
+
});
|
|
7513
7542
|
}
|
|
7514
7543
|
if (allProviders.length === 0) {
|
|
7515
7544
|
if (win.phantom?.ethereum) {
|
|
@@ -7518,15 +7547,15 @@ function BrowserWalletButton({
|
|
|
7518
7547
|
walletId: "phantom"
|
|
7519
7548
|
});
|
|
7520
7549
|
}
|
|
7521
|
-
if (
|
|
7550
|
+
if (anyWin.okxwallet) {
|
|
7522
7551
|
allProviders.push({
|
|
7523
|
-
provider:
|
|
7552
|
+
provider: anyWin.okxwallet,
|
|
7524
7553
|
walletId: "okx"
|
|
7525
7554
|
});
|
|
7526
7555
|
}
|
|
7527
|
-
if (
|
|
7556
|
+
if (anyWin.coinbaseWalletExtension) {
|
|
7528
7557
|
allProviders.push({
|
|
7529
|
-
provider:
|
|
7558
|
+
provider: anyWin.coinbaseWalletExtension,
|
|
7530
7559
|
walletId: "coinbase"
|
|
7531
7560
|
});
|
|
7532
7561
|
}
|
|
@@ -7550,7 +7579,7 @@ function BrowserWalletButton({
|
|
|
7550
7579
|
});
|
|
7551
7580
|
if (!accounts || accounts.length === 0) continue;
|
|
7552
7581
|
const address = accounts[0];
|
|
7553
|
-
const resolved = identifyEthWallet(provider,
|
|
7582
|
+
const resolved = identifyEthWallet(provider, anyWin, walletId);
|
|
7554
7583
|
if (mounted) {
|
|
7555
7584
|
setWallet({ ...resolved, address });
|
|
7556
7585
|
setIsLoading(false);
|
|
@@ -7592,15 +7621,11 @@ function BrowserWalletButton({
|
|
|
7592
7621
|
solanaProvider.on("disconnect", handleDisconnect);
|
|
7593
7622
|
solanaProvider.on("accountChanged", handleAccountsChanged);
|
|
7594
7623
|
}
|
|
7595
|
-
const anyWin = window;
|
|
7596
7624
|
const ethProviders = [];
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
7601
|
-
if (provider && !ethProviders.includes(provider)) {
|
|
7602
|
-
ethProviders.push(provider);
|
|
7603
|
-
}
|
|
7625
|
+
for (const { provider } of getEip6963Providers()) {
|
|
7626
|
+
const p = provider;
|
|
7627
|
+
if (p && !ethProviders.includes(p)) {
|
|
7628
|
+
ethProviders.push(p);
|
|
7604
7629
|
}
|
|
7605
7630
|
}
|
|
7606
7631
|
if (window.ethereum && !ethProviders.includes(window.ethereum)) {
|
|
@@ -7702,7 +7727,7 @@ function BrowserWalletButton({
|
|
|
7702
7727
|
if (isLoading) {
|
|
7703
7728
|
return null;
|
|
7704
7729
|
}
|
|
7705
|
-
const hasWalletExtension = (!chainType || chainType === "solana") && (window.phantom?.solana?.isPhantom || window.solana?.isPhantom)
|
|
7730
|
+
const hasWalletExtension = (!chainType || chainType === "ethereum") && getEip6963Providers().length > 0 || (!chainType || chainType === "solana") && (window.phantom?.solana?.isPhantom || window.solana?.isPhantom) || (!chainType || chainType === "ethereum") && (window.phantom?.ethereum || window.ethereum);
|
|
7706
7731
|
if (!onConnectClick && !wallet && !hasWalletExtension) {
|
|
7707
7732
|
return null;
|
|
7708
7733
|
}
|
|
@@ -13458,15 +13483,10 @@ var WALLET_DEFINITIONS = [
|
|
|
13458
13483
|
{ id: "backpack", name: "Backpack", networks: ["solana"], installUrl: "https://backpack.app/" },
|
|
13459
13484
|
{ id: "glow", name: "Glow", networks: ["solana"], installUrl: "https://glow.app/" }
|
|
13460
13485
|
];
|
|
13461
|
-
function
|
|
13486
|
+
function getSolanaProviders() {
|
|
13462
13487
|
if (typeof window === "undefined") return {};
|
|
13463
13488
|
const win = window;
|
|
13464
13489
|
return {
|
|
13465
|
-
ethereum: win.ethereum,
|
|
13466
|
-
phantomEthereum: win.phantom?.ethereum,
|
|
13467
|
-
coinbaseEthereum: win.coinbaseWalletExtension,
|
|
13468
|
-
trustEthereum: win.trustwallet?.ethereum,
|
|
13469
|
-
okxEthereum: win.okxwallet,
|
|
13470
13490
|
phantomSolana: win.phantom?.solana,
|
|
13471
13491
|
solflare: win.solflare,
|
|
13472
13492
|
backpack: win.backpack,
|
|
@@ -13474,37 +13494,71 @@ function getWalletProviders() {
|
|
|
13474
13494
|
coinbaseSolana: win.coinbaseSolana || win.coinbaseWalletExtension?.solana
|
|
13475
13495
|
};
|
|
13476
13496
|
}
|
|
13497
|
+
function getLegacyEvmProviders() {
|
|
13498
|
+
if (typeof window === "undefined") return {};
|
|
13499
|
+
const win = window;
|
|
13500
|
+
return {
|
|
13501
|
+
ethereum: win.ethereum,
|
|
13502
|
+
phantomEthereum: win.phantom?.ethereum,
|
|
13503
|
+
coinbaseEthereum: win.coinbaseWalletExtension,
|
|
13504
|
+
trustEthereum: win.trustwallet?.ethereum,
|
|
13505
|
+
okxEthereum: win.okxwallet
|
|
13506
|
+
};
|
|
13507
|
+
}
|
|
13477
13508
|
function detectAvailableWallets(filterChainType) {
|
|
13478
|
-
const
|
|
13509
|
+
const solProviders = getSolanaProviders();
|
|
13510
|
+
const legacyEvm = getLegacyEvmProviders();
|
|
13511
|
+
const eip6963List = getEip6963Providers();
|
|
13479
13512
|
const win = typeof window !== "undefined" ? window : null;
|
|
13513
|
+
const hasEip6963 = (walletId) => eip6963List.some((d) => {
|
|
13514
|
+
const rdns = d.info?.rdns || "";
|
|
13515
|
+
switch (walletId) {
|
|
13516
|
+
case "metamask":
|
|
13517
|
+
return rdns.includes("metamask");
|
|
13518
|
+
case "phantom":
|
|
13519
|
+
return rdns.includes("phantom");
|
|
13520
|
+
case "coinbase":
|
|
13521
|
+
return rdns.includes("coinbase");
|
|
13522
|
+
case "trust":
|
|
13523
|
+
return rdns.includes("trust");
|
|
13524
|
+
case "rainbow":
|
|
13525
|
+
return rdns.includes("rainbow");
|
|
13526
|
+
case "rabby":
|
|
13527
|
+
return rdns.includes("rabby");
|
|
13528
|
+
case "okx":
|
|
13529
|
+
return rdns.includes("okx") || rdns.includes("okex");
|
|
13530
|
+
default:
|
|
13531
|
+
return false;
|
|
13532
|
+
}
|
|
13533
|
+
});
|
|
13480
13534
|
return WALLET_DEFINITIONS.filter((w) => !filterChainType || w.networks.includes(filterChainType)).map((wallet) => {
|
|
13481
13535
|
let isInstalled = false;
|
|
13482
13536
|
const detectedNetworks = [];
|
|
13483
13537
|
switch (wallet.id) {
|
|
13484
13538
|
case "metamask":
|
|
13485
|
-
isInstalled = !!(
|
|
13539
|
+
isInstalled = hasEip6963("metamask") || !!(legacyEvm.ethereum?.isMetaMask && !legacyEvm.ethereum?.isPhantom && !legacyEvm.ethereum?.isRabby && !legacyEvm.ethereum?.isOkxWallet);
|
|
13486
13540
|
if (isInstalled) detectedNetworks.push("ethereum");
|
|
13487
13541
|
break;
|
|
13488
13542
|
case "phantom":
|
|
13489
|
-
if (
|
|
13543
|
+
if (solProviders.phantomSolana?.isPhantom) {
|
|
13490
13544
|
isInstalled = true;
|
|
13491
13545
|
detectedNetworks.push("solana");
|
|
13492
13546
|
}
|
|
13493
|
-
if (
|
|
13547
|
+
if (hasEip6963("phantom") || legacyEvm.phantomEthereum?.isPhantom) {
|
|
13494
13548
|
isInstalled = true;
|
|
13495
13549
|
detectedNetworks.push("ethereum");
|
|
13496
13550
|
}
|
|
13497
13551
|
break;
|
|
13498
13552
|
case "coinbase":
|
|
13499
|
-
if (
|
|
13553
|
+
if (hasEip6963("coinbase") || legacyEvm.coinbaseEthereum || legacyEvm.ethereum?.isCoinbaseWallet) {
|
|
13500
13554
|
isInstalled = true;
|
|
13501
13555
|
detectedNetworks.push("ethereum");
|
|
13502
13556
|
}
|
|
13503
|
-
if (
|
|
13557
|
+
if (solProviders.coinbaseSolana || win?.coinbaseWalletExtension?.solana) detectedNetworks.push("solana");
|
|
13504
13558
|
if (isInstalled && wallet.networks.includes("solana") && !detectedNetworks.includes("solana")) detectedNetworks.push("solana");
|
|
13505
13559
|
break;
|
|
13506
13560
|
case "trust":
|
|
13507
|
-
if (
|
|
13561
|
+
if (hasEip6963("trust") || legacyEvm.trustEthereum || legacyEvm.ethereum?.isTrust || win?.trustwallet) {
|
|
13508
13562
|
isInstalled = true;
|
|
13509
13563
|
detectedNetworks.push("ethereum");
|
|
13510
13564
|
}
|
|
@@ -13512,27 +13566,27 @@ function detectAvailableWallets(filterChainType) {
|
|
|
13512
13566
|
if (isInstalled && wallet.networks.includes("solana") && !detectedNetworks.includes("solana")) detectedNetworks.push("solana");
|
|
13513
13567
|
break;
|
|
13514
13568
|
case "rainbow":
|
|
13515
|
-
isInstalled = !!
|
|
13569
|
+
isInstalled = hasEip6963("rainbow") || !!legacyEvm.ethereum?.isRainbow;
|
|
13516
13570
|
if (isInstalled) detectedNetworks.push("ethereum");
|
|
13517
13571
|
break;
|
|
13518
13572
|
case "rabby":
|
|
13519
|
-
isInstalled = !!
|
|
13573
|
+
isInstalled = hasEip6963("rabby") || !!legacyEvm.ethereum?.isRabby;
|
|
13520
13574
|
if (isInstalled) detectedNetworks.push("ethereum");
|
|
13521
13575
|
break;
|
|
13522
13576
|
case "okx":
|
|
13523
|
-
isInstalled = !!(
|
|
13577
|
+
isInstalled = hasEip6963("okx") || !!(legacyEvm.okxEthereum || legacyEvm.ethereum?.isOkxWallet);
|
|
13524
13578
|
if (isInstalled) detectedNetworks.push("ethereum");
|
|
13525
13579
|
break;
|
|
13526
13580
|
case "solflare":
|
|
13527
|
-
isInstalled = !!
|
|
13581
|
+
isInstalled = !!solProviders.solflare?.isSolflare;
|
|
13528
13582
|
if (isInstalled) detectedNetworks.push("solana");
|
|
13529
13583
|
break;
|
|
13530
13584
|
case "backpack":
|
|
13531
|
-
isInstalled = !!(
|
|
13585
|
+
isInstalled = !!(solProviders.backpack?.isBackpack || win?.backpack);
|
|
13532
13586
|
if (isInstalled) detectedNetworks.push("solana");
|
|
13533
13587
|
break;
|
|
13534
13588
|
case "glow":
|
|
13535
|
-
isInstalled = !!(
|
|
13589
|
+
isInstalled = !!(solProviders.glow?.isGlow || win?.glow);
|
|
13536
13590
|
if (isInstalled) detectedNetworks.push("solana");
|
|
13537
13591
|
break;
|
|
13538
13592
|
}
|
|
@@ -13587,7 +13641,16 @@ function WalletConnect({
|
|
|
13587
13641
|
const [connectingNetwork, setConnectingNetwork] = React29.useState(null);
|
|
13588
13642
|
const [walletError, setWalletError] = React29.useState(null);
|
|
13589
13643
|
const [isWalletConnecting, setIsWalletConnecting] = React29.useState(false);
|
|
13590
|
-
const
|
|
13644
|
+
const [eip6963ProviderCount, setEip6963ProviderCount] = React29.useState(0);
|
|
13645
|
+
React29.useEffect(() => {
|
|
13646
|
+
const store = getEip6963Store();
|
|
13647
|
+
if (!store) return;
|
|
13648
|
+
setEip6963ProviderCount(store.getProviders().length);
|
|
13649
|
+
return store.subscribe((providers) => {
|
|
13650
|
+
setEip6963ProviderCount(providers.length);
|
|
13651
|
+
});
|
|
13652
|
+
}, []);
|
|
13653
|
+
const availableWallets = React29.useMemo(() => detectAvailableWallets(), [eip6963ProviderCount]);
|
|
13591
13654
|
const [balances, setBalances] = React29.useState([]);
|
|
13592
13655
|
const [isLoading, setIsLoading] = React29.useState(false);
|
|
13593
13656
|
const [selectedBalance, setSelectedBalance] = React29.useState(null);
|
|
@@ -13646,59 +13709,72 @@ function WalletConnect({
|
|
|
13646
13709
|
setWalletError(null);
|
|
13647
13710
|
setIsWalletConnecting(true);
|
|
13648
13711
|
try {
|
|
13649
|
-
const providers = getWalletProviders();
|
|
13650
13712
|
const win = typeof window !== "undefined" ? window : null;
|
|
13651
13713
|
let connectedInfo;
|
|
13652
13714
|
if (network === "ethereum") {
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13658
|
-
|
|
13659
|
-
|
|
13660
|
-
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13665
|
-
|
|
13666
|
-
|
|
13667
|
-
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
|
|
13672
|
-
|
|
13673
|
-
|
|
13674
|
-
|
|
13675
|
-
|
|
13676
|
-
|
|
13677
|
-
|
|
13715
|
+
const eip6963Match = findProviderByWalletId(wallet.id);
|
|
13716
|
+
let provider = eip6963Match?.provider;
|
|
13717
|
+
if (!provider) {
|
|
13718
|
+
const legacyEvm = getLegacyEvmProviders();
|
|
13719
|
+
switch (wallet.id) {
|
|
13720
|
+
case "metamask":
|
|
13721
|
+
if (legacyEvm.ethereum?.isMetaMask && !legacyEvm.ethereum?.isPhantom) provider = legacyEvm.ethereum;
|
|
13722
|
+
break;
|
|
13723
|
+
case "phantom":
|
|
13724
|
+
provider = legacyEvm.phantomEthereum;
|
|
13725
|
+
break;
|
|
13726
|
+
case "coinbase":
|
|
13727
|
+
provider = legacyEvm.coinbaseEthereum || (legacyEvm.ethereum?.isCoinbaseWallet ? legacyEvm.ethereum : void 0);
|
|
13728
|
+
break;
|
|
13729
|
+
case "trust":
|
|
13730
|
+
provider = legacyEvm.trustEthereum || (legacyEvm.ethereum?.isTrust ? legacyEvm.ethereum : void 0);
|
|
13731
|
+
break;
|
|
13732
|
+
case "rainbow":
|
|
13733
|
+
if (legacyEvm.ethereum?.isRainbow) provider = legacyEvm.ethereum;
|
|
13734
|
+
break;
|
|
13735
|
+
case "rabby":
|
|
13736
|
+
if (legacyEvm.ethereum?.isRabby) provider = legacyEvm.ethereum;
|
|
13737
|
+
break;
|
|
13738
|
+
case "okx":
|
|
13739
|
+
provider = legacyEvm.okxEthereum || (legacyEvm.ethereum?.isOkxWallet ? legacyEvm.ethereum : void 0);
|
|
13740
|
+
break;
|
|
13741
|
+
default:
|
|
13742
|
+
provider = legacyEvm.ethereum;
|
|
13743
|
+
}
|
|
13678
13744
|
}
|
|
13679
13745
|
if (!provider) throw new Error(`${wallet.name} wallet not found. Please install it.`);
|
|
13680
13746
|
const accounts = await provider.request({ method: "eth_requestAccounts" });
|
|
13681
13747
|
if (!accounts?.length) throw new Error("No accounts returned from wallet");
|
|
13682
13748
|
setUserDisconnectedWallet(false);
|
|
13683
|
-
const
|
|
13749
|
+
const walletIdToType = {
|
|
13750
|
+
phantom: "phantom-ethereum",
|
|
13751
|
+
coinbase: "coinbase",
|
|
13752
|
+
trust: "trust",
|
|
13753
|
+
rainbow: "rainbow",
|
|
13754
|
+
rabby: "rabby",
|
|
13755
|
+
okx: "okx",
|
|
13756
|
+
metamask: "metamask"
|
|
13757
|
+
};
|
|
13758
|
+
const walletType = walletIdToType[wallet.id] || "metamask";
|
|
13684
13759
|
connectedInfo = { type: walletType, name: wallet.name, address: accounts[0], icon: wallet.id };
|
|
13685
13760
|
} else {
|
|
13761
|
+
const solProviders = getSolanaProviders();
|
|
13686
13762
|
let provider;
|
|
13687
13763
|
switch (wallet.id) {
|
|
13688
13764
|
case "phantom":
|
|
13689
|
-
provider =
|
|
13765
|
+
provider = solProviders.phantomSolana;
|
|
13690
13766
|
break;
|
|
13691
13767
|
case "solflare":
|
|
13692
|
-
provider =
|
|
13768
|
+
provider = solProviders.solflare;
|
|
13693
13769
|
break;
|
|
13694
13770
|
case "backpack":
|
|
13695
|
-
provider =
|
|
13771
|
+
provider = solProviders.backpack || win?.backpack;
|
|
13696
13772
|
break;
|
|
13697
13773
|
case "glow":
|
|
13698
|
-
provider =
|
|
13774
|
+
provider = solProviders.glow || win?.glow;
|
|
13699
13775
|
break;
|
|
13700
13776
|
case "coinbase":
|
|
13701
|
-
provider =
|
|
13777
|
+
provider = solProviders.coinbaseSolana || win?.coinbaseWalletExtension?.solana;
|
|
13702
13778
|
break;
|
|
13703
13779
|
case "trust":
|
|
13704
13780
|
provider = win?.trustwallet?.solana;
|
|
@@ -13944,10 +14020,15 @@ function WalletConnect({
|
|
|
13944
14020
|
};
|
|
13945
14021
|
const sendEthereumTransaction = async (token, amountStr) => {
|
|
13946
14022
|
if (!recipientAddress || !/^0x[a-fA-F0-9]{40}$/.test(recipientAddress)) throw new Error(`Invalid recipient address.`);
|
|
13947
|
-
|
|
13948
|
-
|
|
13949
|
-
|
|
13950
|
-
|
|
14023
|
+
const walletIdMap = { "phantom-ethereum": "phantom", coinbase: "coinbase", trust: "trust", okx: "okx", rainbow: "rainbow", rabby: "rabby", metamask: "metamask" };
|
|
14024
|
+
const lookupId = walletIdMap[walletInfo.type] || walletInfo.type;
|
|
14025
|
+
const eip6963Match = findProviderByWalletId(lookupId);
|
|
14026
|
+
let provider = eip6963Match?.provider;
|
|
14027
|
+
if (!provider) {
|
|
14028
|
+
if (walletInfo.type === "phantom-ethereum") provider = window.phantom?.ethereum;
|
|
14029
|
+
else if (walletInfo.type === "coinbase") provider = window.coinbaseWalletExtension || window.ethereum;
|
|
14030
|
+
else provider = window.ethereum;
|
|
14031
|
+
}
|
|
13951
14032
|
if (!provider) throw new Error("Ethereum wallet not found");
|
|
13952
14033
|
const currentChainIdHex = await provider.request({ method: "eth_chainId", params: [] });
|
|
13953
14034
|
if (parseInt(currentChainIdHex, 16).toString() !== token.chain_id) {
|
|
@@ -15841,7 +15922,7 @@ import {
|
|
|
15841
15922
|
ActionType as ActionType5
|
|
15842
15923
|
} from "@unifold/core";
|
|
15843
15924
|
var POLL_INTERVAL_MS3 = 2500;
|
|
15844
|
-
var POLL_ENDPOINT_INTERVAL_MS2 =
|
|
15925
|
+
var POLL_ENDPOINT_INTERVAL_MS2 = 5e3;
|
|
15845
15926
|
var CUTOFF_BUFFER_MS2 = 6e4;
|
|
15846
15927
|
function useWithdrawPolling({
|
|
15847
15928
|
userId,
|
|
@@ -16364,29 +16445,18 @@ async function detectBrowserWallet(chainType, senderAddress) {
|
|
|
16364
16445
|
evmProviders.push({ provider: p, name });
|
|
16365
16446
|
}
|
|
16366
16447
|
};
|
|
16367
|
-
|
|
16368
|
-
|
|
16369
|
-
|
|
16370
|
-
|
|
16371
|
-
|
|
16372
|
-
|
|
16373
|
-
|
|
16374
|
-
|
|
16448
|
+
const eip6963 = getEip6963Providers();
|
|
16449
|
+
const walletIdToName = {
|
|
16450
|
+
metamask: "MetaMask",
|
|
16451
|
+
phantom: "Phantom",
|
|
16452
|
+
coinbase: "Coinbase",
|
|
16453
|
+
rabby: "Rabby",
|
|
16454
|
+
rainbow: "Rainbow",
|
|
16455
|
+
okx: "OKX Wallet",
|
|
16456
|
+
trust: "Trust Wallet"
|
|
16375
16457
|
};
|
|
16376
|
-
|
|
16377
|
-
|
|
16378
|
-
win.removeEventListener("eip6963:announceProvider", handleAnnouncement);
|
|
16379
|
-
for (const detail of anyWin.__eip6963Providers) {
|
|
16380
|
-
const rdns = detail.info?.rdns || "";
|
|
16381
|
-
let name = detail.info?.name || "Wallet";
|
|
16382
|
-
if (rdns.includes("metamask")) name = "MetaMask";
|
|
16383
|
-
else if (rdns.includes("phantom")) name = "Phantom";
|
|
16384
|
-
else if (rdns.includes("coinbase")) name = "Coinbase";
|
|
16385
|
-
else if (rdns.includes("rabby")) name = "Rabby";
|
|
16386
|
-
else if (rdns.includes("rainbow")) name = "Rainbow";
|
|
16387
|
-
else if (rdns.includes("okx")) name = "OKX Wallet";
|
|
16388
|
-
else if (rdns.includes("trust")) name = "Trust Wallet";
|
|
16389
|
-
add(detail.provider, name);
|
|
16458
|
+
for (const { provider, walletId, info } of eip6963) {
|
|
16459
|
+
add(provider, walletIdToName[walletId] || info.name || "Wallet");
|
|
16390
16460
|
}
|
|
16391
16461
|
if (evmProviders.length === 0) {
|
|
16392
16462
|
add(anyWin.phantom?.ethereum, "Phantom");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unifold/ui-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
4
4
|
"description": "Unifold UI React - Deposit and onramp components for React applications",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -33,9 +33,10 @@
|
|
|
33
33
|
"clsx": "^2.0.0",
|
|
34
34
|
"fuse.js": "^7.4.0",
|
|
35
35
|
"lucide-react": "^0.454.0",
|
|
36
|
+
"mipd": "^0.0.7",
|
|
36
37
|
"qr-code-styling": "^1.6.0-rc.1",
|
|
37
38
|
"tailwind-merge": "^2.0.0",
|
|
38
|
-
"@unifold/core": "0.1.
|
|
39
|
+
"@unifold/core": "0.1.60"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@solana/web3.js": "^1.87.0",
|