@agg-build/hooks 1.0.2 → 1.2.11
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 +1 -1
- package/dist/{chunk-V6VNA7MX.mjs → chunk-553OI6M2.mjs} +565 -89
- package/dist/{chunk-NOYHQUW2.mjs → chunk-CWEJLBYY.mjs} +66 -11
- package/dist/{chunk-EB64HHYM.mjs → chunk-JWPZNCGY.mjs} +1 -1
- package/dist/deposit.d.mts +8 -2
- package/dist/deposit.d.ts +8 -2
- package/dist/deposit.js +215 -76
- package/dist/deposit.mjs +119 -66
- package/dist/index.d.mts +712 -42
- package/dist/index.d.ts +712 -42
- package/dist/index.js +1405 -357
- package/dist/index.mjs +681 -163
- package/dist/{use-sync-balances-B1_8tBKw.d.ts → use-sync-balances-CeD8qZWP.d.mts} +5 -2
- package/dist/{use-sync-balances-B1_8tBKw.d.mts → use-sync-balances-CeD8qZWP.d.ts} +5 -2
- package/dist/withdraw.d.mts +27 -3
- package/dist/withdraw.d.ts +27 -3
- package/dist/withdraw.js +178 -26
- package/dist/withdraw.mjs +4 -2
- package/package.json +2 -2
package/dist/deposit.js
CHANGED
|
@@ -91,23 +91,10 @@ function normalizeWalletError(error, supportedChains) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// src/deposit/use-wallet-token-balance.ts
|
|
94
|
-
var
|
|
94
|
+
var import_web3 = require("@solana/web3.js");
|
|
95
95
|
var import_react_query = require("@tanstack/react-query");
|
|
96
96
|
var import_viem = require("viem");
|
|
97
97
|
var import_wagmi = require("wagmi");
|
|
98
|
-
var import_wallet_adapter_react = require("@solana/wallet-adapter-react");
|
|
99
|
-
var import_web3 = require("@solana/web3.js");
|
|
100
|
-
|
|
101
|
-
// ../common/src/utils/auth.ts
|
|
102
|
-
function getWalletAddressFromUserProfile(user) {
|
|
103
|
-
var _a, _b, _c, _d, _e;
|
|
104
|
-
const oauthWallet = (_b = (_a = user == null ? void 0 : user.accounts) == null ? void 0 : _a.find(
|
|
105
|
-
(a) => a.type === "oauth" /* oauth */ && String(a.provider).toLowerCase() === "wallet"
|
|
106
|
-
)) != null ? _b : null;
|
|
107
|
-
if (oauthWallet == null ? void 0 : oauthWallet.providerAccountId) return oauthWallet.providerAccountId;
|
|
108
|
-
const siweAccount = (_d = (_c = user == null ? void 0 : user.accounts) == null ? void 0 : _c.find((a) => a.type === "siwe" /* siwe */)) != null ? _d : null;
|
|
109
|
-
return (_e = siweAccount == null ? void 0 : siweAccount.providerAccountId) != null ? _e : void 0;
|
|
110
|
-
}
|
|
111
98
|
|
|
112
99
|
// src/core/providers/contexts.ts
|
|
113
100
|
var import_react = require("react");
|
|
@@ -276,6 +263,12 @@ var enUsLabels = {
|
|
|
276
263
|
max: "Max",
|
|
277
264
|
tokenLabel: "Receive token",
|
|
278
265
|
networkLabel: "Receive network",
|
|
266
|
+
estimatedFees: "Est. fees",
|
|
267
|
+
networkReserve: "Network reserve",
|
|
268
|
+
networkReserveTooltipAria: "Network reserve details",
|
|
269
|
+
networkReserveTooltipLineOne: "This reserve helps cover network and bridge costs.",
|
|
270
|
+
networkReserveTooltipLineTwo: "Any unused amount stays in your balance.",
|
|
271
|
+
youReceive: "You'll receive",
|
|
279
272
|
confirm: "Confirm withdrawal",
|
|
280
273
|
successTitle: "Withdrawal submitted",
|
|
281
274
|
successDescription: (tokenSymbol) => `Your ${tokenSymbol} withdrawal is being processed and will arrive shortly.`,
|
|
@@ -284,12 +277,16 @@ var enUsLabels = {
|
|
|
284
277
|
// terminal status — otherwise a finished withdrawal would keep showing
|
|
285
278
|
// "submitted / processing" forever and force the user to hard-refresh.
|
|
286
279
|
successTitleCompleted: "Withdrawal complete",
|
|
287
|
-
successDescriptionCompleted: (tokenSymbol) => `Your ${tokenSymbol}
|
|
280
|
+
successDescriptionCompleted: (tokenSymbol) => `Your ${tokenSymbol} has been successfully sent to your wallet.`,
|
|
288
281
|
successTitlePartial: "Withdrawal partially completed",
|
|
289
|
-
successDescriptionPartial: (
|
|
282
|
+
successDescriptionPartial: () => "Part of your withdrawal was completed successfully, but the remaining funds failed to transfer and were returned to your balance.",
|
|
290
283
|
successTitleFailed: "Withdrawal failed",
|
|
291
|
-
successDescriptionFailed: (
|
|
284
|
+
successDescriptionFailed: () => "We couldn't complete your withdrawal. Your funds were returned to your balance.",
|
|
285
|
+
retry: "Try Again",
|
|
286
|
+
close: "Close",
|
|
287
|
+
loadingDescription: "This may take a few minutes. You can safely close this window and check the status later in your activity.",
|
|
292
288
|
summary: {
|
|
289
|
+
requestedWithdrawal: "Requested withdrawal",
|
|
293
290
|
// The response is `pricingStatus: "unquoted"` — we don't know net
|
|
294
291
|
// output until on-chain settlement. Calling this "Amount received"
|
|
295
292
|
// would imply receipt before the lifecycle has confirmed. Keep it
|
|
@@ -307,6 +304,12 @@ var enUsLabels = {
|
|
|
307
304
|
completed: "Withdrawal complete.",
|
|
308
305
|
partial: "Withdrawal partially completed \u2014 see details below.",
|
|
309
306
|
failed: "Withdrawal failed.",
|
|
307
|
+
loadingSteps: {
|
|
308
|
+
preparing: "Preparing funds",
|
|
309
|
+
bridging: "Bridging between networks",
|
|
310
|
+
sending: "Sending to your wallet",
|
|
311
|
+
confirming: "Waiting for network confirmation"
|
|
312
|
+
},
|
|
310
313
|
steps: {
|
|
311
314
|
bridge: (sourceChainName, destChainName) => `Bridging from ${sourceChainName} to ${destChainName}`,
|
|
312
315
|
transfer: (destChainName) => `Transferring on ${destChainName}`
|
|
@@ -362,24 +365,66 @@ var enUsLabels = {
|
|
|
362
365
|
externalWallet: "Deposit from external wallet",
|
|
363
366
|
card: "Deposit with card"
|
|
364
367
|
},
|
|
368
|
+
depositStatusTitles: {
|
|
369
|
+
connectedWallet: {
|
|
370
|
+
pending: "Processing deposit from connected wallet",
|
|
371
|
+
completed: "Successful deposit from connected wallet",
|
|
372
|
+
failed: "Failed deposit from connected wallet",
|
|
373
|
+
canceled: "Canceled deposit from connected wallet"
|
|
374
|
+
},
|
|
375
|
+
externalWallet: {
|
|
376
|
+
pending: "Processing deposit from external wallet",
|
|
377
|
+
completed: "Successful deposit from external wallet",
|
|
378
|
+
failed: "Failed deposit from external wallet",
|
|
379
|
+
canceled: "Canceled deposit from external wallet"
|
|
380
|
+
},
|
|
381
|
+
card: {
|
|
382
|
+
pending: "Processing deposit with card",
|
|
383
|
+
completed: "Successful deposit with card",
|
|
384
|
+
failed: "Failed deposit with card",
|
|
385
|
+
canceled: "Canceled deposit with card"
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
withdrawalStatusTitles: {
|
|
389
|
+
pending: "Processing withdrawal",
|
|
390
|
+
completed: "Successful withdrawal",
|
|
391
|
+
failed: "Failed withdrawal",
|
|
392
|
+
canceled: "Canceled withdrawal"
|
|
393
|
+
},
|
|
365
394
|
// Activity-row title for any withdrawal regardless of lifecycle
|
|
366
|
-
// state
|
|
367
|
-
//
|
|
368
|
-
//
|
|
395
|
+
// state — render the asset rather than implying success. The
|
|
396
|
+
// ActivityRow renders a separate status chip when the row is
|
|
397
|
+
// failed. Retained for partner overrides that still want a
|
|
398
|
+
// status-agnostic title.
|
|
369
399
|
withdrawalTitle: (tokenSymbol) => `Withdraw ${tokenSymbol}`
|
|
370
400
|
},
|
|
371
401
|
positions: {
|
|
402
|
+
activeFilter: "Active",
|
|
403
|
+
closedFilter: "Closed",
|
|
404
|
+
marketHeader: "Market",
|
|
372
405
|
totalTradedHeader: "Total traded",
|
|
406
|
+
currentValueHeader: "Current value",
|
|
407
|
+
statusHeader: "Status",
|
|
408
|
+
resolutionHeader: "Resolution",
|
|
409
|
+
payoutHeader: "Payout",
|
|
410
|
+
resultHeader: "Result",
|
|
373
411
|
amountWonHeader: "Amount won",
|
|
374
412
|
claimHeader: "Claim",
|
|
375
413
|
claim: "Claim",
|
|
376
414
|
claimed: "Claimed",
|
|
377
415
|
pending: "Pending",
|
|
416
|
+
open: "Open",
|
|
378
417
|
won: "Won",
|
|
379
418
|
lost: "Lost",
|
|
419
|
+
sold: "Sold",
|
|
380
420
|
resolved: "Resolved",
|
|
381
421
|
marketClosed: "Market closed",
|
|
382
|
-
closed: "Closed"
|
|
422
|
+
closed: "Closed",
|
|
423
|
+
searchPlaceholder: "Search...",
|
|
424
|
+
noResults: "No results",
|
|
425
|
+
avgPrefix: "avg",
|
|
426
|
+
nowPrefix: "now",
|
|
427
|
+
finalPrefix: "final"
|
|
383
428
|
}
|
|
384
429
|
},
|
|
385
430
|
eventList: {
|
|
@@ -517,7 +562,7 @@ var enUsLabels = {
|
|
|
517
562
|
settlementEmpty: "No settlement details available.",
|
|
518
563
|
disclaimer: "By trading, you agree to the Terms of Use of each exchange.",
|
|
519
564
|
geoBlockTermsLink: "Terms of Use",
|
|
520
|
-
geoBlockGenericMessage: "
|
|
565
|
+
geoBlockGenericMessage: "None of the venues for this market are available in your region. See ",
|
|
521
566
|
geoBlockVenueMessage: (venueLabel) => `Trading on ${venueLabel} is not available in your region. See `,
|
|
522
567
|
geoBlockMessageSuffix: " for more information.",
|
|
523
568
|
geoBlockModalAriaLabel: "Geo-restricted location",
|
|
@@ -571,6 +616,7 @@ var enUsLabels = {
|
|
|
571
616
|
noMarketSelected: "Select a market to place an order.",
|
|
572
617
|
noOrderbooks: "No live orderbooks are available for this market right now.",
|
|
573
618
|
quoteUnavailable: "Quote temporarily unavailable. Please try again.",
|
|
619
|
+
quoteBalanceMismatch: "Quote balance mismatch. Try a different amount.",
|
|
574
620
|
selectedVenueUnavailable: "The venue you selected is no longer available on this route. Review the updated options and try again.",
|
|
575
621
|
engineUnavailable: "The routing engine is temporarily unavailable. Please try again in a moment.",
|
|
576
622
|
insufficientInputAmount: "Trade amount is too small to cover bridging and execution costs. Increase your spend or deposit funds on the destination chain.",
|
|
@@ -597,10 +643,18 @@ var enUsLabels = {
|
|
|
597
643
|
splitOrderDescription: "We split your order for the best price:",
|
|
598
644
|
viewAllRoutes: (count) => `View all (${count})`,
|
|
599
645
|
venueUnavailableInRegion: "Unavailable in your region",
|
|
646
|
+
platformFee: "0% platform fees",
|
|
647
|
+
estimatedFees: "Estimated fees",
|
|
648
|
+
estimatedFeesTooltipAria: "Estimated fees breakdown",
|
|
649
|
+
feeBreakdownVenueFees: "Venue fees",
|
|
650
|
+
feeBreakdownBridgeFees: "Bridge fees",
|
|
651
|
+
feeBreakdownExecutionGas: "Execution gas",
|
|
652
|
+
feeBreakdownTotalFees: "Total fees",
|
|
600
653
|
toWin: (tab) => tab === "buy" ? "To win" : "Payout",
|
|
601
654
|
buyingOutcome: (label) => `Buying ${label}`,
|
|
602
655
|
sellingOutcome: (label) => `Selling ${label}`,
|
|
603
656
|
findingBestRoute: "Finding the best route...",
|
|
657
|
+
checkingBalance: "Checking balance",
|
|
604
658
|
submittingOrderProgress: "Submitting order...",
|
|
605
659
|
orderSubmittedProgress: (orderId) => `Order #${orderId.replace(/^#/, "")} submitted`,
|
|
606
660
|
executingOnVenue: (venueLabel) => `Executing on ${venueLabel}...`,
|
|
@@ -839,6 +893,7 @@ var defaultAggUiSearchConfig = {
|
|
|
839
893
|
var defaultAggUiConfig = {
|
|
840
894
|
enableLogs: false,
|
|
841
895
|
enableWebsocketsLogs: false,
|
|
896
|
+
enableDebug: false,
|
|
842
897
|
general: {
|
|
843
898
|
locale: DEFAULT_LOCALE,
|
|
844
899
|
theme: "light",
|
|
@@ -848,6 +903,7 @@ var defaultAggUiConfig = {
|
|
|
848
903
|
features: {
|
|
849
904
|
enableAnimations: true,
|
|
850
905
|
enableLiveUpdates: true,
|
|
906
|
+
showFeesBreakdown: false,
|
|
851
907
|
enableGradients: false
|
|
852
908
|
},
|
|
853
909
|
market: {
|
|
@@ -912,6 +968,33 @@ var invalidateBalanceQueries = (queryClient, options) => {
|
|
|
912
968
|
refetchType
|
|
913
969
|
});
|
|
914
970
|
};
|
|
971
|
+
var invalidatePositionQueries = (queryClient, options) => {
|
|
972
|
+
var _a;
|
|
973
|
+
queryClient.invalidateQueries({
|
|
974
|
+
queryKey: executionKeys.positionsPrefix(),
|
|
975
|
+
refetchType: (_a = options == null ? void 0 : options.refetchType) != null ? _a : "active"
|
|
976
|
+
});
|
|
977
|
+
};
|
|
978
|
+
var userActivityQueryKeys = {
|
|
979
|
+
all: () => ["user-activity"]
|
|
980
|
+
};
|
|
981
|
+
var invalidateUserActivityQueries = (queryClient, options) => {
|
|
982
|
+
var _a;
|
|
983
|
+
const strategy = (_a = options == null ? void 0 : options.strategy) != null ? _a : "remove";
|
|
984
|
+
if (strategy === "remove") {
|
|
985
|
+
queryClient.removeQueries({ queryKey: userActivityQueryKeys.all() });
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
queryClient.invalidateQueries({
|
|
989
|
+
queryKey: userActivityQueryKeys.all(),
|
|
990
|
+
refetchType: "all"
|
|
991
|
+
});
|
|
992
|
+
};
|
|
993
|
+
var invalidateUserMoneyState = (queryClient, options) => {
|
|
994
|
+
invalidateBalanceQueries(queryClient, { refetchType: options == null ? void 0 : options.refetchType });
|
|
995
|
+
invalidatePositionQueries(queryClient, { refetchType: options == null ? void 0 : options.refetchType });
|
|
996
|
+
invalidateUserActivityQueries(queryClient, { strategy: options == null ? void 0 : options.activityStrategy });
|
|
997
|
+
};
|
|
915
998
|
|
|
916
999
|
// src/core/providers/hooks.ts
|
|
917
1000
|
var import_react2 = require("react");
|
|
@@ -945,6 +1028,35 @@ var useAggBalanceState = useAggBalanceContext;
|
|
|
945
1028
|
// src/deposit/constants.ts
|
|
946
1029
|
var DEFAULT_SOLANA_RPC_ENDPOINT = "https://solana-rpc.publicnode.com";
|
|
947
1030
|
var SVM_CHAIN_IDS = /* @__PURE__ */ new Set([792703809]);
|
|
1031
|
+
var MULTI_CHAIN_SOLANA_WALLET_NAMES = /* @__PURE__ */ new Set(["Phantom"]);
|
|
1032
|
+
|
|
1033
|
+
// src/deposit/use-svm-address.ts
|
|
1034
|
+
var import_react3 = require("react");
|
|
1035
|
+
var import_wallet_adapter_react = require("@solana/wallet-adapter-react");
|
|
1036
|
+
function getPhantomProvider() {
|
|
1037
|
+
var _a, _b;
|
|
1038
|
+
if (typeof window === "undefined") return void 0;
|
|
1039
|
+
const w = window;
|
|
1040
|
+
return (_b = (_a = w.phantom) == null ? void 0 : _a.solana) != null ? _b : w.solana;
|
|
1041
|
+
}
|
|
1042
|
+
function useSvmAddress() {
|
|
1043
|
+
var _a;
|
|
1044
|
+
const { publicKey: adapterPublicKey } = (0, import_wallet_adapter_react.useWallet)();
|
|
1045
|
+
const [phantomAddress, setPhantomAddress] = (0, import_react3.useState)(void 0);
|
|
1046
|
+
(0, import_react3.useEffect)(() => {
|
|
1047
|
+
var _a2;
|
|
1048
|
+
const provider = getPhantomProvider();
|
|
1049
|
+
if (!provider) return;
|
|
1050
|
+
const existing = (_a2 = provider.publicKey) == null ? void 0 : _a2.toBase58();
|
|
1051
|
+
if (existing) {
|
|
1052
|
+
setPhantomAddress(existing);
|
|
1053
|
+
return;
|
|
1054
|
+
}
|
|
1055
|
+
provider.connect({ onlyIfTrusted: true }).then((res) => setPhantomAddress(res.publicKey.toString())).catch(() => {
|
|
1056
|
+
});
|
|
1057
|
+
}, []);
|
|
1058
|
+
return (_a = adapterPublicKey == null ? void 0 : adapterPublicKey.toBase58()) != null ? _a : phantomAddress;
|
|
1059
|
+
}
|
|
948
1060
|
|
|
949
1061
|
// src/deposit/use-wallet-token-balance.ts
|
|
950
1062
|
var ERC20_BALANCE_OF_ABI = [
|
|
@@ -956,11 +1068,46 @@ var ERC20_BALANCE_OF_ABI = [
|
|
|
956
1068
|
outputs: [{ name: "", type: "uint256" }]
|
|
957
1069
|
}
|
|
958
1070
|
];
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1071
|
+
var SVM_BALANCE_RPC_TIMEOUT_MS = 2e3;
|
|
1072
|
+
var SVM_BALANCE_STALE_TIME_MS = 3e4;
|
|
1073
|
+
var SvmBalanceTimeoutError = class extends Error {
|
|
1074
|
+
constructor() {
|
|
1075
|
+
super("Solana balance request timed out");
|
|
1076
|
+
this.name = "SvmBalanceTimeoutError";
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
function withTimeout(promise, timeoutMs) {
|
|
1080
|
+
return new Promise((resolve, reject) => {
|
|
1081
|
+
const timer = setTimeout(() => reject(new SvmBalanceTimeoutError()), timeoutMs);
|
|
1082
|
+
promise.then(
|
|
1083
|
+
(value) => {
|
|
1084
|
+
clearTimeout(timer);
|
|
1085
|
+
resolve(value);
|
|
1086
|
+
},
|
|
1087
|
+
(err) => {
|
|
1088
|
+
clearTimeout(timer);
|
|
1089
|
+
reject(err);
|
|
1090
|
+
}
|
|
1091
|
+
);
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
function fetchSvmTokenBalance(rpcUrl, owner, mint) {
|
|
1095
|
+
return __async(this, null, function* () {
|
|
1096
|
+
var _a;
|
|
1097
|
+
const connection = new import_web3.Connection(rpcUrl);
|
|
1098
|
+
const accounts = yield withTimeout(
|
|
1099
|
+
connection.getTokenAccountsByOwner(owner, { mint }),
|
|
1100
|
+
SVM_BALANCE_RPC_TIMEOUT_MS
|
|
1101
|
+
);
|
|
1102
|
+
if (accounts.value.length === 0) return 0;
|
|
1103
|
+
const first = accounts.value[0];
|
|
1104
|
+
if (!first) return 0;
|
|
1105
|
+
const balance = yield withTimeout(
|
|
1106
|
+
connection.getTokenAccountBalance(first.pubkey),
|
|
1107
|
+
SVM_BALANCE_RPC_TIMEOUT_MS
|
|
1108
|
+
);
|
|
1109
|
+
return (_a = balance.value.uiAmount) != null ? _a : 0;
|
|
1110
|
+
});
|
|
964
1111
|
}
|
|
965
1112
|
function useWalletTokenBalance({
|
|
966
1113
|
isOpen = true,
|
|
@@ -969,7 +1116,7 @@ function useWalletTokenBalance({
|
|
|
969
1116
|
decimals,
|
|
970
1117
|
svmAddress
|
|
971
1118
|
}) {
|
|
972
|
-
var _a
|
|
1119
|
+
var _a;
|
|
973
1120
|
const { solanaRpcUrl } = useAggUiConfig();
|
|
974
1121
|
const rpcEndpoint = solanaRpcUrl != null ? solanaRpcUrl : DEFAULT_SOLANA_RPC_ENDPOINT;
|
|
975
1122
|
const isSvm = chainId !== void 0 && SVM_CHAIN_IDS.has(chainId);
|
|
@@ -983,45 +1130,27 @@ function useWalletTokenBalance({
|
|
|
983
1130
|
args: evmAddress ? [evmAddress] : void 0,
|
|
984
1131
|
query: { enabled: evmEnabled, staleTime: 0, refetchOnMount: true }
|
|
985
1132
|
});
|
|
986
|
-
const
|
|
987
|
-
const
|
|
988
|
-
(0, import_react3.useEffect)(() => {
|
|
989
|
-
var _a2;
|
|
990
|
-
if (!isSvm) return;
|
|
991
|
-
const provider = getPhantomProvider();
|
|
992
|
-
if (!provider) return;
|
|
993
|
-
const existing = (_a2 = provider.publicKey) == null ? void 0 : _a2.toBase58();
|
|
994
|
-
if (existing) {
|
|
995
|
-
setPhantomAddress(existing);
|
|
996
|
-
return;
|
|
997
|
-
}
|
|
998
|
-
provider.connect({ onlyIfTrusted: true }).then((res) => setPhantomAddress(res.publicKey.toString())).catch(() => {
|
|
999
|
-
});
|
|
1000
|
-
}, [isSvm]);
|
|
1001
|
-
const resolvedSvmAddress = (_b = (_a = adapterPublicKey == null ? void 0 : adapterPublicKey.toBase58()) != null ? _a : phantomAddress) != null ? _b : svmAddress;
|
|
1002
|
-
const connection = (0, import_react3.useMemo)(() => new import_web3.Connection(rpcEndpoint), [rpcEndpoint]);
|
|
1133
|
+
const detectedSvmAddress = useSvmAddress();
|
|
1134
|
+
const resolvedSvmAddress = detectedSvmAddress != null ? detectedSvmAddress : svmAddress;
|
|
1003
1135
|
const svmEnabled = isOpen && isSvm && !!resolvedSvmAddress && !!tokenAddress;
|
|
1004
1136
|
const svmQuery = (0, import_react_query.useQuery)({
|
|
1005
1137
|
queryKey: ["svm-token-balance", resolvedSvmAddress != null ? resolvedSvmAddress : null, tokenAddress != null ? tokenAddress : null, isOpen],
|
|
1006
1138
|
enabled: svmEnabled,
|
|
1007
|
-
staleTime:
|
|
1139
|
+
staleTime: SVM_BALANCE_STALE_TIME_MS,
|
|
1140
|
+
retry: false,
|
|
1141
|
+
refetchOnWindowFocus: "always",
|
|
1142
|
+
refetchOnReconnect: "always",
|
|
1008
1143
|
queryFn: () => __async(null, null, function* () {
|
|
1009
|
-
var _a2;
|
|
1010
1144
|
if (!resolvedSvmAddress || !tokenAddress) return 0;
|
|
1011
1145
|
const owner = new import_web3.PublicKey(resolvedSvmAddress);
|
|
1012
1146
|
const mint = new import_web3.PublicKey(tokenAddress);
|
|
1013
|
-
|
|
1014
|
-
if (accounts.value.length === 0) return 0;
|
|
1015
|
-
const first = accounts.value[0];
|
|
1016
|
-
if (!first) return 0;
|
|
1017
|
-
const balance = yield connection.getTokenAccountBalance(first.pubkey);
|
|
1018
|
-
return (_a2 = balance.value.uiAmount) != null ? _a2 : 0;
|
|
1147
|
+
return yield fetchSvmTokenBalance(rpcEndpoint, owner, mint);
|
|
1019
1148
|
})
|
|
1020
1149
|
});
|
|
1021
1150
|
if (isSvm) {
|
|
1022
1151
|
const awaitingSelection2 = isOpen && !!chainId && !tokenAddress;
|
|
1023
1152
|
return {
|
|
1024
|
-
balance: (
|
|
1153
|
+
balance: (_a = svmQuery.data) != null ? _a : 0,
|
|
1025
1154
|
isLoading: awaitingSelection2 || svmQuery.isLoading || svmQuery.isFetching
|
|
1026
1155
|
};
|
|
1027
1156
|
}
|
|
@@ -1349,7 +1478,7 @@ function useSyncBalances(options) {
|
|
|
1349
1478
|
mutationFn: () => client.syncManagedBalances(),
|
|
1350
1479
|
onSuccess: () => {
|
|
1351
1480
|
var _a;
|
|
1352
|
-
|
|
1481
|
+
invalidateUserMoneyState(queryClient);
|
|
1353
1482
|
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options);
|
|
1354
1483
|
},
|
|
1355
1484
|
onError: options == null ? void 0 : options.onError
|
|
@@ -1379,8 +1508,10 @@ function useRampSession() {
|
|
|
1379
1508
|
}
|
|
1380
1509
|
|
|
1381
1510
|
// src/deposit/use-deposit-flow.ts
|
|
1511
|
+
var DEFAULT_WALLET_CHAIN_ID = 1;
|
|
1512
|
+
var DEFAULT_WALLET_TOKEN_SYMBOL = "USDC";
|
|
1382
1513
|
function useDepositFlow(options) {
|
|
1383
|
-
var _a, _b;
|
|
1514
|
+
var _a, _b, _c;
|
|
1384
1515
|
const { open, onOpenChange } = options;
|
|
1385
1516
|
const { user } = useAggAuthState();
|
|
1386
1517
|
const { walletActions } = useAggUiConfig();
|
|
@@ -1424,8 +1555,16 @@ function useDepositFlow(options) {
|
|
|
1424
1555
|
}, []);
|
|
1425
1556
|
const { chainId: connectedChainId, address: connectedAddress } = (0, import_wagmi4.useAccount)();
|
|
1426
1557
|
const { switchChainAsync } = (0, import_wagmi4.useSwitchChain)();
|
|
1427
|
-
const {
|
|
1428
|
-
const
|
|
1558
|
+
const { wallet: solanaWallet } = (0, import_wallet_adapter_react3.useWallet)();
|
|
1559
|
+
const resolvedSvmAddress = useSvmAddress();
|
|
1560
|
+
const solanaAdapterName = (_b = solanaWallet == null ? void 0 : solanaWallet.adapter) == null ? void 0 : _b.name;
|
|
1561
|
+
const isMultiChainSolanaWallet = Boolean(
|
|
1562
|
+
solanaAdapterName && MULTI_CHAIN_SOLANA_WALLET_NAMES.has(solanaAdapterName)
|
|
1563
|
+
);
|
|
1564
|
+
const hasSolanaCapability = Boolean(resolvedSvmAddress || (solanaWallet == null ? void 0 : solanaWallet.adapter));
|
|
1565
|
+
const hasEvmCapability = Boolean(connectedAddress) || isMultiChainSolanaWallet;
|
|
1566
|
+
const defaultBalanceChainId = hasEvmCapability && (supportedChains == null ? void 0 : supportedChains.some((chain) => chain.chainId === DEFAULT_WALLET_CHAIN_ID)) ? DEFAULT_WALLET_CHAIN_ID : connectedChainId;
|
|
1567
|
+
const balanceChainId = walletModalChainId ? Number(walletModalChainId) : defaultBalanceChainId;
|
|
1429
1568
|
const selectedChainTokens = (0, import_react7.useMemo)(() => {
|
|
1430
1569
|
var _a2;
|
|
1431
1570
|
if (!supportedChains || !balanceChainId) return [];
|
|
@@ -1433,23 +1572,17 @@ function useDepositFlow(options) {
|
|
|
1433
1572
|
return (_a2 = chain == null ? void 0 : chain.tokens) != null ? _a2 : [];
|
|
1434
1573
|
}, [supportedChains, balanceChainId]);
|
|
1435
1574
|
const selectedTokenMeta = (0, import_react7.useMemo)(() => {
|
|
1436
|
-
|
|
1437
|
-
const match = selectedChainTokens.find((t) => t.symbol ===
|
|
1575
|
+
const preferredTokenSymbol = walletModalTokenSymbol != null ? walletModalTokenSymbol : DEFAULT_WALLET_TOKEN_SYMBOL;
|
|
1576
|
+
const match = selectedChainTokens.find((t) => t.symbol === preferredTokenSymbol);
|
|
1438
1577
|
return match ? { address: match.address, decimals: match.decimals } : void 0;
|
|
1439
1578
|
}, [selectedChainTokens, walletModalTokenSymbol]);
|
|
1440
|
-
const authSvmAddress = (0, import_react7.useMemo)(() => {
|
|
1441
|
-
var _a2;
|
|
1442
|
-
const wallets = user == null ? void 0 : user.wallets;
|
|
1443
|
-
return (_a2 = wallets == null ? void 0 : wallets.find((w) => w.chain === "solana" || w.chain === "svm")) == null ? void 0 : _a2.address;
|
|
1444
|
-
}, [user]);
|
|
1445
1579
|
const isSvmBalanceChain = balanceChainId !== void 0 && SVM_CHAIN_IDS.has(balanceChainId);
|
|
1446
1580
|
const walletAddress = (0, import_react7.useMemo)(() => {
|
|
1447
|
-
var _a2, _b2, _c;
|
|
1448
1581
|
if (isSvmBalanceChain) {
|
|
1449
|
-
return
|
|
1582
|
+
return resolvedSvmAddress != null ? resolvedSvmAddress : "";
|
|
1450
1583
|
}
|
|
1451
|
-
return
|
|
1452
|
-
}, [
|
|
1584
|
+
return connectedAddress != null ? connectedAddress : "";
|
|
1585
|
+
}, [connectedAddress, isSvmBalanceChain, resolvedSvmAddress]);
|
|
1453
1586
|
const walletLabel = (0, import_react7.useMemo)(() => {
|
|
1454
1587
|
return walletAddress ? `${walletAddress.slice(0, 6)}...${walletAddress.slice(-4)}` : "\u2014";
|
|
1455
1588
|
}, [walletAddress]);
|
|
@@ -1457,12 +1590,11 @@ function useDepositFlow(options) {
|
|
|
1457
1590
|
isOpen: open,
|
|
1458
1591
|
chainId: balanceChainId,
|
|
1459
1592
|
tokenAddress: selectedTokenMeta == null ? void 0 : selectedTokenMeta.address,
|
|
1460
|
-
decimals: selectedTokenMeta == null ? void 0 : selectedTokenMeta.decimals
|
|
1461
|
-
svmAddress: authSvmAddress
|
|
1593
|
+
decimals: selectedTokenMeta == null ? void 0 : selectedTokenMeta.decimals
|
|
1462
1594
|
});
|
|
1463
1595
|
const { status: observedWalletTransactionStatus, gasFee: walletTransactionGasFee } = useWalletTransactionStatus({
|
|
1464
1596
|
chainId: walletTransaction == null ? void 0 : walletTransaction.chainId,
|
|
1465
|
-
txId: (
|
|
1597
|
+
txId: (_c = walletTransaction == null ? void 0 : walletTransaction.txId) != null ? _c : null
|
|
1466
1598
|
});
|
|
1467
1599
|
const walletTransactionStatus = walletTransactionError ? "error" : walletTransaction ? observedWalletTransactionStatus != null ? observedWalletTransactionStatus : "submitted" : void 0;
|
|
1468
1600
|
const syncedDepositTxIdRef = (0, import_react7.useRef)(null);
|
|
@@ -1490,9 +1622,15 @@ function useDepositFlow(options) {
|
|
|
1490
1622
|
},
|
|
1491
1623
|
[onOpenChange]
|
|
1492
1624
|
);
|
|
1625
|
+
const handleCancelWalletDeposit = (0, import_react7.useCallback)(() => {
|
|
1626
|
+
setWalletTransaction(null);
|
|
1627
|
+
setWalletTransactionError(null);
|
|
1628
|
+
setWalletTransactionErrorTone("error");
|
|
1629
|
+
syncedDepositTxIdRef.current = null;
|
|
1630
|
+
}, []);
|
|
1493
1631
|
const handleConfirmWalletDeposit = (0, import_react7.useCallback)(
|
|
1494
1632
|
(params) => __async(null, null, function* () {
|
|
1495
|
-
var _a2, _b2,
|
|
1633
|
+
var _a2, _b2, _c2;
|
|
1496
1634
|
const { address, amount, chainId, token } = params;
|
|
1497
1635
|
const chain = (_a2 = supportedChains == null ? void 0 : supportedChains.find((c) => c.chainId === chainId)) != null ? _a2 : null;
|
|
1498
1636
|
const tokenMeta = (_b2 = chain == null ? void 0 : chain.tokens.find((t) => t.symbol === token)) != null ? _b2 : null;
|
|
@@ -1508,7 +1646,7 @@ function useDepositFlow(options) {
|
|
|
1508
1646
|
token: {
|
|
1509
1647
|
symbol: token,
|
|
1510
1648
|
address: tokenMeta == null ? void 0 : tokenMeta.address,
|
|
1511
|
-
decimals: (
|
|
1649
|
+
decimals: (_c2 = tokenMeta == null ? void 0 : tokenMeta.decimals) != null ? _c2 : 6
|
|
1512
1650
|
},
|
|
1513
1651
|
to: address,
|
|
1514
1652
|
amount
|
|
@@ -1576,11 +1714,12 @@ function useDepositFlow(options) {
|
|
|
1576
1714
|
onWalletAmountChange: setDepositAmount,
|
|
1577
1715
|
onWalletMax: (0, import_react7.useCallback)(() => setDepositAmount(String(walletBalance)), [walletBalance]),
|
|
1578
1716
|
onConfirmWalletDeposit: handleConfirmWalletDeposit,
|
|
1717
|
+
onCancelWalletDeposit: handleCancelWalletDeposit,
|
|
1579
1718
|
onWalletNetworkChange: setWalletModalChainId,
|
|
1580
1719
|
onWalletTokenChange: setWalletModalTokenSymbol,
|
|
1581
1720
|
initialWalletChainId: connectedChainId ? String(connectedChainId) : void 0,
|
|
1582
|
-
connectedWalletKind:
|
|
1583
|
-
sendCryptoConfig: { minDeposit: "$1",
|
|
1721
|
+
connectedWalletKind: hasEvmCapability && !hasSolanaCapability ? "evm" : hasSolanaCapability && !hasEvmCapability ? "solana" : void 0,
|
|
1722
|
+
sendCryptoConfig: { minDeposit: "$1", eta: "~30s" },
|
|
1584
1723
|
onDoneSendCrypto: (0, import_react7.useCallback)(
|
|
1585
1724
|
() => handleDepositModalOpenChange(false),
|
|
1586
1725
|
[handleDepositModalOpenChange]
|