@fluent.xyz/connect 0.6.1 → 0.6.2-rc.1
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/fluent-connect.css +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +465 -137
- package/dist/index.js.map +1 -1
- package/docs/api.md +1 -1
- package/docs/experimental.md +7 -0
- package/docs/getting-started.md +23 -0
- package/docs/guides/iframe.md +149 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5612,7 +5612,7 @@ function createFluentConnectForWidget(config) {
|
|
|
5612
5612
|
}
|
|
5613
5613
|
|
|
5614
5614
|
// package.json
|
|
5615
|
-
var version = "0.6.1";
|
|
5615
|
+
var version = "0.6.2-rc.1";
|
|
5616
5616
|
|
|
5617
5617
|
// src/core/analytics.ts
|
|
5618
5618
|
var INSTANCE_NAME = "fluent";
|
|
@@ -6334,6 +6334,13 @@ function toastFaucetError(error) {
|
|
|
6334
6334
|
});
|
|
6335
6335
|
}
|
|
6336
6336
|
|
|
6337
|
+
// src/utils/fluentAmountFractionDigits.ts
|
|
6338
|
+
var FLUENT_AMOUNT_FRACTION_DIGITS = 6;
|
|
6339
|
+
var USD_PEGGED_SYMBOLS = /* @__PURE__ */ new Set(["USDnr", "USDC"]);
|
|
6340
|
+
function fluentAmountFractionDigits(symbol) {
|
|
6341
|
+
return USD_PEGGED_SYMBOLS.has(symbol) ? 2 : FLUENT_AMOUNT_FRACTION_DIGITS;
|
|
6342
|
+
}
|
|
6343
|
+
|
|
6337
6344
|
// src/utils/formatExternalWallet.ts
|
|
6338
6345
|
function formatExternalWallet(wallet, status) {
|
|
6339
6346
|
return JSON.stringify(
|
|
@@ -7972,10 +7979,15 @@ var STATUS_LABELS = {
|
|
|
7972
7979
|
var activityTimeFormat = new Intl.DateTimeFormat(void 0, { timeStyle: "short" });
|
|
7973
7980
|
function formatRowAmount(row) {
|
|
7974
7981
|
if (row.amount === void 0 || row.decimals === void 0 || !row.tokenSymbol) return void 0;
|
|
7982
|
+
const digits = Math.min(4, fluentAmountFractionDigits(row.tokenSymbol));
|
|
7975
7983
|
const [whole = "0", fraction = ""] = formatUnits(row.amount, row.decimals).split(".");
|
|
7976
|
-
const trimmed = fraction.slice(0,
|
|
7984
|
+
const trimmed = fraction.slice(0, digits).replace(/0+$/, "");
|
|
7977
7985
|
return `${trimmed ? `${whole}.${trimmed}` : whole} ${row.tokenSymbol}`;
|
|
7978
7986
|
}
|
|
7987
|
+
function formatRowExactAmount(row) {
|
|
7988
|
+
if (row.amount === void 0 || row.decimals === void 0 || !row.tokenSymbol) return void 0;
|
|
7989
|
+
return `${formatUnits(row.amount, row.decimals)} ${row.tokenSymbol}`;
|
|
7990
|
+
}
|
|
7979
7991
|
function HistoryRow({
|
|
7980
7992
|
row,
|
|
7981
7993
|
usd,
|
|
@@ -8010,7 +8022,14 @@ function HistoryRow({
|
|
|
8010
8022
|
] })
|
|
8011
8023
|
] }),
|
|
8012
8024
|
/* @__PURE__ */ jsxs("span", { className: "flex shrink-0 flex-col items-end gap-1", children: [
|
|
8013
|
-
amount ? /* @__PURE__ */ jsx(
|
|
8025
|
+
amount ? /* @__PURE__ */ jsx(
|
|
8026
|
+
"span",
|
|
8027
|
+
{
|
|
8028
|
+
className: `text-sm font-medium leading-4 ${inFlight ? "opacity-70" : ""}`,
|
|
8029
|
+
title: formatRowExactAmount(row),
|
|
8030
|
+
children: amount
|
|
8031
|
+
}
|
|
8032
|
+
) : null,
|
|
8014
8033
|
amount && usd ? /* @__PURE__ */ jsx(
|
|
8015
8034
|
"span",
|
|
8016
8035
|
{
|
|
@@ -8101,7 +8120,7 @@ function BridgeActivityDetail({
|
|
|
8101
8120
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-3 py-3", children: [
|
|
8102
8121
|
/* @__PURE__ */ jsx(ActivityTokenTile, { tokenSymbol: row.tokenSymbol, badge: row.direction }),
|
|
8103
8122
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-0", children: [
|
|
8104
|
-
/* @__PURE__ */ jsx("span", { className: "min-w-0 truncate text-2xl font-medium", children: amount ?? rowTitle(row) }),
|
|
8123
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 truncate text-2xl font-medium", title: formatRowExactAmount(row), children: amount ?? rowTitle(row) }),
|
|
8105
8124
|
amount && usd ? /* @__PURE__ */ jsx(
|
|
8106
8125
|
"span",
|
|
8107
8126
|
{
|
|
@@ -8190,10 +8209,14 @@ function TooltipContent({
|
|
|
8190
8209
|
}
|
|
8191
8210
|
) });
|
|
8192
8211
|
}
|
|
8193
|
-
function formatAmount(value, decimals) {
|
|
8212
|
+
function formatAmount(value, decimals, symbol) {
|
|
8194
8213
|
if (value === void 0) return "\u2014";
|
|
8214
|
+
const digits = symbol ? fluentAmountFractionDigits(symbol) : FLUENT_AMOUNT_FRACTION_DIGITS;
|
|
8195
8215
|
const [whole = "0", fraction = ""] = formatUnits(value, decimals).split(".");
|
|
8196
|
-
const trimmed = fraction.slice(0,
|
|
8216
|
+
const trimmed = fraction.slice(0, digits).replace(/0+$/, "");
|
|
8217
|
+
if (!trimmed && whole === "0" && value > 0n && digits < FLUENT_AMOUNT_FRACTION_DIGITS) {
|
|
8218
|
+
return `<0.${"1".padStart(digits, "0")}`;
|
|
8219
|
+
}
|
|
8197
8220
|
return trimmed ? `${whole}.${trimmed}` : whole;
|
|
8198
8221
|
}
|
|
8199
8222
|
function formatUsd(usd) {
|
|
@@ -8227,7 +8250,8 @@ function SummaryRow({
|
|
|
8227
8250
|
label,
|
|
8228
8251
|
value,
|
|
8229
8252
|
secondary,
|
|
8230
|
-
tooltip
|
|
8253
|
+
tooltip,
|
|
8254
|
+
valueTitle
|
|
8231
8255
|
}) {
|
|
8232
8256
|
return /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-5 text-sm", children: [
|
|
8233
8257
|
/* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1 text-foreground/80", children: [
|
|
@@ -8246,7 +8270,7 @@ function SummaryRow({
|
|
|
8246
8270
|
] }) : null
|
|
8247
8271
|
] }),
|
|
8248
8272
|
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-right", children: [
|
|
8249
|
-
/* @__PURE__ */ jsx("span", { className: "text-foreground", children: value }),
|
|
8273
|
+
/* @__PURE__ */ jsx("span", { className: "text-foreground", title: valueTitle, children: value }),
|
|
8250
8274
|
secondary ? /* @__PURE__ */ jsx("span", { className: "size-0.5 rounded-full bg-foreground/50" }) : null,
|
|
8251
8275
|
secondary ? /* @__PURE__ */ jsx("span", { className: "text-foreground/60", children: secondary }) : null
|
|
8252
8276
|
] })
|
|
@@ -8543,18 +8567,17 @@ function sortFluentTransactionHistory(entries) {
|
|
|
8543
8567
|
(left, right) => right.timestamp - left.timestamp || left.id.localeCompare(right.id)
|
|
8544
8568
|
);
|
|
8545
8569
|
}
|
|
8546
|
-
|
|
8547
|
-
var SMALLEST_SHOWN_AMOUNT = 10 ** -AMOUNT_FRACTION_DIGITS;
|
|
8548
|
-
function isFluentDustAmount(amount) {
|
|
8570
|
+
function isFluentDustAmount(amount, fractionDigits = FLUENT_AMOUNT_FRACTION_DIGITS) {
|
|
8549
8571
|
const numeric = Number(amount);
|
|
8550
|
-
return Number.isFinite(numeric) && numeric > 0 && numeric <
|
|
8572
|
+
return Number.isFinite(numeric) && numeric > 0 && numeric < 10 ** -fractionDigits;
|
|
8551
8573
|
}
|
|
8552
8574
|
function formatFluentTransactionAmount(entry) {
|
|
8553
8575
|
const sign = entry.direction === "sent" ? "\u2212" : "+";
|
|
8554
|
-
|
|
8555
|
-
|
|
8576
|
+
const digits = fluentAmountFractionDigits(entry.symbol);
|
|
8577
|
+
if (isFluentDustAmount(entry.amount, digits)) {
|
|
8578
|
+
return `${sign}<0${FLUENT_DECIMAL_SEPARATOR}${"1".padStart(digits, "0")} ${entry.symbol}`;
|
|
8556
8579
|
}
|
|
8557
|
-
return `${sign}${formatFluentLocaleAmount(entry.amount,
|
|
8580
|
+
return `${sign}${formatFluentLocaleAmount(entry.amount, digits)} ${entry.symbol}`;
|
|
8558
8581
|
}
|
|
8559
8582
|
var HYPERLANE_GRAPHQL_ENDPOINT = "https://api.hyperlane.xyz/v1/graphql";
|
|
8560
8583
|
var HYPERLANE_HISTORY_LIMIT = 25;
|
|
@@ -9026,12 +9049,14 @@ function PendingActivityRow({
|
|
|
9026
9049
|
] })
|
|
9027
9050
|
] }),
|
|
9028
9051
|
/* @__PURE__ */ jsxs("span", { className: "flex shrink-0 flex-col items-end gap-1", children: [
|
|
9029
|
-
/* @__PURE__ */
|
|
9030
|
-
"
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
|
|
9034
|
-
|
|
9052
|
+
/* @__PURE__ */ jsx(
|
|
9053
|
+
"span",
|
|
9054
|
+
{
|
|
9055
|
+
className: "text-sm font-medium leading-4 tabular-nums opacity-70",
|
|
9056
|
+
title: `${transfer.amount} ${transfer.symbol}`,
|
|
9057
|
+
children: formatFluentTransactionAmount({ ...transfer, direction: "sent" })
|
|
9058
|
+
}
|
|
9059
|
+
),
|
|
9035
9060
|
/* @__PURE__ */ jsx(ActivityUsd, { usd })
|
|
9036
9061
|
] })
|
|
9037
9062
|
] }) });
|
|
@@ -9121,6 +9146,7 @@ function ActivityAmount({
|
|
|
9121
9146
|
return /* @__PURE__ */ jsx(
|
|
9122
9147
|
"span",
|
|
9123
9148
|
{
|
|
9149
|
+
title: `${movement.amount} ${movement.symbol}`,
|
|
9124
9150
|
className: cn(
|
|
9125
9151
|
"text-sm leading-4 tabular-nums",
|
|
9126
9152
|
!secondary && "font-medium",
|
|
@@ -9370,7 +9396,7 @@ function FluentActivityDetail({
|
|
|
9370
9396
|
const movements = entry.kind === "movement" ? [entry] : entry.movements;
|
|
9371
9397
|
const swap = splitFluentSwap(movements);
|
|
9372
9398
|
const headed = swap ? swap.received : movements;
|
|
9373
|
-
const heading = headed.length > 0 ? headed.map(formatFluentTransactionAmount).join(", ") : FLUENT_TRANSACTION_OPERATION_LABEL;
|
|
9399
|
+
const heading = headed.length > 0 ? /* @__PURE__ */ jsx("span", { title: headed.map((movement) => `${movement.amount} ${movement.symbol}`).join(", "), children: headed.map(formatFluentTransactionAmount).join(", ") }) : FLUENT_TRANSACTION_OPERATION_LABEL;
|
|
9374
9400
|
const rate = swap?.received.length === 1 && swap.paid.length === 1 ? formatSwapRate(swap.paid[0], swap.received[0]) : void 0;
|
|
9375
9401
|
const openExplorer = explorerOpener(track);
|
|
9376
9402
|
const transactionHash = entry.kind === "operation" ? entry.transactionHash : entry.hash;
|
|
@@ -9526,7 +9552,7 @@ function SwapSideRow({
|
|
|
9526
9552
|
approximate = false
|
|
9527
9553
|
}) {
|
|
9528
9554
|
const usd = formatActivityUsd(movement.amount, priceOf(movement));
|
|
9529
|
-
return /* @__PURE__ */ jsx(DetailRow, { label, children: /* @__PURE__ */ jsxs("span", { className: "tabular-nums", children: [
|
|
9555
|
+
return /* @__PURE__ */ jsx(DetailRow, { label, children: /* @__PURE__ */ jsxs("span", { className: "tabular-nums", title: `${movement.amount} ${movement.symbol}`, children: [
|
|
9530
9556
|
approximate ? "\u2248 " : null,
|
|
9531
9557
|
formatFluentTransactionAmount(movement).slice(1),
|
|
9532
9558
|
usd ? /* @__PURE__ */ jsxs("span", { className: "font-normal text-muted-foreground", children: [
|
|
@@ -9626,7 +9652,7 @@ function DepositSwapActivityDetail({
|
|
|
9626
9652
|
ActivityDetailHeader,
|
|
9627
9653
|
{
|
|
9628
9654
|
symbol: to.symbol,
|
|
9629
|
-
heading: received ? `\u2248 ${formatFluentTransactionAmount(received)}` : `${formatFluentTransactionAmount(paid).slice(1)} \u2192 ${to.symbol}
|
|
9655
|
+
heading: /* @__PURE__ */ jsx("span", { title: `${(received ?? paid).amount} ${(received ?? paid).symbol}`, children: received ? `\u2248 ${formatFluentTransactionAmount(received)}` : `${formatFluentTransactionAmount(paid).slice(1)} \u2192 ${to.symbol}` }),
|
|
9630
9656
|
usd: usd ? `${received ? "\u2248 " : ""}${usd}` : void 0,
|
|
9631
9657
|
subtitle: `Deposit ${from.symbol} \u2192 ${to.symbol}`,
|
|
9632
9658
|
timestamp: startedAt ?? Date.now(),
|
|
@@ -9691,6 +9717,76 @@ function DepositSwapActivityDetail({
|
|
|
9691
9717
|
actionable ? /* @__PURE__ */ jsx(Button, { className: cn("w-full", riseIn("delay-500")), onClick: onOpenSwapPage, children: state.phase === "declined" || state.phase === "error" ? `Swap to ${to.symbol}` : "Open the Swap page" }) : null
|
|
9692
9718
|
] });
|
|
9693
9719
|
}
|
|
9720
|
+
function SentTransferDetail({
|
|
9721
|
+
transfer,
|
|
9722
|
+
account,
|
|
9723
|
+
network,
|
|
9724
|
+
priceOf,
|
|
9725
|
+
track
|
|
9726
|
+
}) {
|
|
9727
|
+
const openExplorer = explorerOpener(track);
|
|
9728
|
+
const movement = { amount: transfer.amount, direction: "sent", symbol: transfer.symbol };
|
|
9729
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-2.5", children: [
|
|
9730
|
+
/* @__PURE__ */ jsx(
|
|
9731
|
+
ActivityDetailHeader,
|
|
9732
|
+
{
|
|
9733
|
+
symbol: transfer.symbol,
|
|
9734
|
+
heading: /* @__PURE__ */ jsx("span", { title: `${transfer.amount} ${transfer.symbol}`, children: formatFluentTransactionAmount(movement) }),
|
|
9735
|
+
usd: formatActivityUsd(
|
|
9736
|
+
transfer.amount,
|
|
9737
|
+
priceOf({ identity: transfer.tokenIdentity, symbol: transfer.symbol })
|
|
9738
|
+
),
|
|
9739
|
+
subtitle: "Sent",
|
|
9740
|
+
timestamp: transfer.startedAt,
|
|
9741
|
+
entrance: true
|
|
9742
|
+
}
|
|
9743
|
+
),
|
|
9744
|
+
/* @__PURE__ */ jsxs(
|
|
9745
|
+
"dl",
|
|
9746
|
+
{
|
|
9747
|
+
className: cn("flex flex-col gap-5 text-sm bg-white/5 p-4 rounded-2xl", riseIn("delay-300")),
|
|
9748
|
+
children: [
|
|
9749
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "Status", children: /* @__PURE__ */ jsx(
|
|
9750
|
+
"span",
|
|
9751
|
+
{
|
|
9752
|
+
className: "inline-flex items-center gap-1.5 animate-in fade-in-0 zoom-in-90 duration-300 ease-out motion-reduce:animate-none",
|
|
9753
|
+
children: transfer.hash ? /* @__PURE__ */ jsx("span", { className: "text-green-400", children: "Confirmed" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
9754
|
+
/* @__PURE__ */ jsx(Spinner, { className: "size-3.5 text-muted-foreground" }),
|
|
9755
|
+
/* @__PURE__ */ jsx("span", { className: "text-foreground/70", children: "Pending" })
|
|
9756
|
+
] })
|
|
9757
|
+
},
|
|
9758
|
+
transfer.hash ? "confirmed" : "pending"
|
|
9759
|
+
) }),
|
|
9760
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "From", children: /* @__PURE__ */ jsx("span", { title: account, children: formatAddress(account) }) }),
|
|
9761
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "To", children: /* @__PURE__ */ jsx(
|
|
9762
|
+
HashMenu,
|
|
9763
|
+
{
|
|
9764
|
+
hash: transfer.to,
|
|
9765
|
+
url: explorerAddress(transfer.to, network),
|
|
9766
|
+
onOpen: (url) => openExplorer(url, "explorer"),
|
|
9767
|
+
label: "Address"
|
|
9768
|
+
}
|
|
9769
|
+
) }),
|
|
9770
|
+
/* @__PURE__ */ jsx(FluentNetworkRow, { network })
|
|
9771
|
+
]
|
|
9772
|
+
}
|
|
9773
|
+
),
|
|
9774
|
+
transfer.hash ? /* @__PURE__ */ jsx(
|
|
9775
|
+
"dl",
|
|
9776
|
+
{
|
|
9777
|
+
className: cn("flex flex-col gap-5 text-sm bg-white/5 p-4 rounded-2xl", riseIn("delay-100")),
|
|
9778
|
+
children: /* @__PURE__ */ jsx(DetailRow, { label: "Transaction ID", children: /* @__PURE__ */ jsx(
|
|
9779
|
+
HashMenu,
|
|
9780
|
+
{
|
|
9781
|
+
hash: transfer.hash,
|
|
9782
|
+
url: explorerTransaction(transfer.hash, network),
|
|
9783
|
+
onOpen: (url) => openExplorer(url, "transaction")
|
|
9784
|
+
}
|
|
9785
|
+
) })
|
|
9786
|
+
}
|
|
9787
|
+
) : null
|
|
9788
|
+
] });
|
|
9789
|
+
}
|
|
9694
9790
|
var FLUENT_RPC_TIMEOUT_MS = 3e4;
|
|
9695
9791
|
var FLUENT_RPC_RETRY_COUNT = 3;
|
|
9696
9792
|
var FLUENT_RPC_RETRY_DELAY_MS = 300;
|
|
@@ -10027,8 +10123,9 @@ function formatEstimatedFee(params) {
|
|
|
10027
10123
|
};
|
|
10028
10124
|
}
|
|
10029
10125
|
return {
|
|
10030
|
-
value: `\u2248 ${formatAmount(inFeeToken, feeToken.decimals)} ${feeToken.symbol}`,
|
|
10031
|
-
secondary: usdOf(inFeeToken, feeToken.decimals, usdPrices[feeToken.identity])
|
|
10126
|
+
value: `\u2248 ${formatAmount(inFeeToken, feeToken.decimals, feeToken.symbol)} ${feeToken.symbol}`,
|
|
10127
|
+
secondary: usdOf(inFeeToken, feeToken.decimals, usdPrices[feeToken.identity]),
|
|
10128
|
+
exact: `${formatUnits(inFeeToken, feeToken.decimals)} ${feeToken.symbol}`
|
|
10032
10129
|
};
|
|
10033
10130
|
}
|
|
10034
10131
|
function SendTokenForm({
|
|
@@ -10081,7 +10178,7 @@ function SendTokenForm({
|
|
|
10081
10178
|
decimals: token.decimals,
|
|
10082
10179
|
balance: rawBalance
|
|
10083
10180
|
}) : null;
|
|
10084
|
-
const balanceNote = token && rawBalance !== null ? `${formatAmount(rawBalance, token.decimals)} ${token.symbol}` : balancesBusy ? "Loading balance..." : "Balance unavailable";
|
|
10181
|
+
const balanceNote = token && rawBalance !== null ? `${formatAmount(rawBalance, token.decimals, token.symbol)} ${token.symbol}` : balancesBusy ? "Loading balance..." : "Balance unavailable";
|
|
10085
10182
|
const amountUsd = token ? formatAmountUsd(amount, usdPrices[token.identity]) : void 0;
|
|
10086
10183
|
const fee = feeToken ? checkFluentTransferFee({
|
|
10087
10184
|
feeToken,
|
|
@@ -10111,9 +10208,15 @@ function SendTokenForm({
|
|
|
10111
10208
|
const feeSponsored = Boolean(feeToken && isFluentNativeToken(feeToken) && sponsorshipAvailable);
|
|
10112
10209
|
const feeBalanceLabel = (candidate) => {
|
|
10113
10210
|
const entry = balanceByIdentity.get(candidate.identity);
|
|
10114
|
-
if (entry?.status === "ready" && entry.raw !== null)
|
|
10211
|
+
if (entry?.status === "ready" && entry.raw !== null) {
|
|
10212
|
+
return formatAmount(entry.raw, candidate.decimals, candidate.symbol);
|
|
10213
|
+
}
|
|
10115
10214
|
return balancesBusy ? "\u2026" : "\u2014";
|
|
10116
10215
|
};
|
|
10216
|
+
const feeBalanceExact = (candidate) => {
|
|
10217
|
+
const entry = balanceByIdentity.get(candidate.identity);
|
|
10218
|
+
return entry?.status === "ready" && entry.raw !== null ? formatUnits(entry.raw, candidate.decimals) : void 0;
|
|
10219
|
+
};
|
|
10117
10220
|
const ready = Boolean(token) && recipientCheck.status === "ok" && amountCheck?.status === "ok" && fee.status !== "blocked" && !sending;
|
|
10118
10221
|
const handleSend = async () => {
|
|
10119
10222
|
if (!token || !feeToken) return;
|
|
@@ -10282,7 +10385,14 @@ function SendTokenForm({
|
|
|
10282
10385
|
/* @__PURE__ */ jsx(SelectContent, { align: "end", alignItemWithTrigger: false, className: "min-w-52", children: gasTokens.map((candidate) => /* @__PURE__ */ jsxs(SelectItem, { value: candidate.identity, children: [
|
|
10283
10386
|
/* @__PURE__ */ jsx(TokenGlyph, { token: candidate, className: "size-5" }),
|
|
10284
10387
|
/* @__PURE__ */ jsx("span", { children: candidate.symbol }),
|
|
10285
|
-
/* @__PURE__ */ jsx(
|
|
10388
|
+
/* @__PURE__ */ jsx(
|
|
10389
|
+
"span",
|
|
10390
|
+
{
|
|
10391
|
+
className: "ml-auto pl-4 text-foreground/60",
|
|
10392
|
+
title: feeBalanceExact(candidate),
|
|
10393
|
+
children: feeBalanceLabel(candidate)
|
|
10394
|
+
}
|
|
10395
|
+
)
|
|
10286
10396
|
] }, candidate.identity)) })
|
|
10287
10397
|
]
|
|
10288
10398
|
}
|
|
@@ -10296,6 +10406,7 @@ function SendTokenForm({
|
|
|
10296
10406
|
{
|
|
10297
10407
|
label: "Est. network fee",
|
|
10298
10408
|
value: estimatedFee.value,
|
|
10409
|
+
valueTitle: estimatedFee.exact,
|
|
10299
10410
|
secondary: estimatedFee.secondary,
|
|
10300
10411
|
tooltip: feeSponsored ? "What the network charges for this transfer. The app may cover it; the review shows the exact amount." : "What the network charges for this transfer, converted to the fee token at today's rate. The review shows the exact amount."
|
|
10301
10412
|
}
|
|
@@ -10785,6 +10896,7 @@ function useFluentUserTokens(options) {
|
|
|
10785
10896
|
}
|
|
10786
10897
|
|
|
10787
10898
|
// src/hooks/useFluentTokenBalances.ts
|
|
10899
|
+
var FLUENT_BALANCE_POLL_INTERVAL_MS = 1e4;
|
|
10788
10900
|
function useFluentTokenBalances(params) {
|
|
10789
10901
|
const { network, chain } = useFluentWidgetNetwork();
|
|
10790
10902
|
const defaultTokens = useMemo(
|
|
@@ -10816,35 +10928,43 @@ function useFluentTokenBalances(params) {
|
|
|
10816
10928
|
const [busy, setBusy] = useState(false);
|
|
10817
10929
|
const [status, setStatus] = useState("Connect a Fluent account");
|
|
10818
10930
|
const inFlight = useRef(null);
|
|
10819
|
-
const refresh = useCallback(
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10931
|
+
const refresh = useCallback(
|
|
10932
|
+
async (options) => {
|
|
10933
|
+
if (options?.quiet && inFlight.current) return;
|
|
10934
|
+
inFlight.current?.abort();
|
|
10935
|
+
const controller = new AbortController();
|
|
10936
|
+
inFlight.current = controller;
|
|
10937
|
+
const { signal } = controller;
|
|
10938
|
+
if (!params.accountAddress) {
|
|
10939
|
+
setBalances([]);
|
|
10940
|
+
setStatus("Connect a Fluent account");
|
|
10941
|
+
return;
|
|
10942
|
+
}
|
|
10943
|
+
if (!options?.quiet) {
|
|
10944
|
+
setBusy(true);
|
|
10945
|
+
setStatus("Checking token balances");
|
|
10946
|
+
}
|
|
10947
|
+
try {
|
|
10948
|
+
const next = await readFluentTokenBalances({
|
|
10949
|
+
client: publicClient,
|
|
10950
|
+
account: params.accountAddress,
|
|
10951
|
+
tokens: displayTokens
|
|
10952
|
+
});
|
|
10953
|
+
if (signal.aborted) return;
|
|
10954
|
+
setBalances(next);
|
|
10955
|
+
setStatus("Balances updated");
|
|
10956
|
+
} catch {
|
|
10957
|
+
if (signal.aborted) return;
|
|
10958
|
+
if (options?.quiet) return;
|
|
10959
|
+
setBalances([]);
|
|
10960
|
+
setStatus("Could not load balances");
|
|
10961
|
+
} finally {
|
|
10962
|
+
if (inFlight.current === controller) inFlight.current = null;
|
|
10963
|
+
if (!signal.aborted && !options?.quiet) setBusy(false);
|
|
10964
|
+
}
|
|
10965
|
+
},
|
|
10966
|
+
[displayTokens, params.accountAddress, publicClient]
|
|
10967
|
+
);
|
|
10848
10968
|
useEffect(() => {
|
|
10849
10969
|
setBalances([]);
|
|
10850
10970
|
setStatus(
|
|
@@ -10855,6 +10975,15 @@ function useFluentTokenBalances(params) {
|
|
|
10855
10975
|
refresh();
|
|
10856
10976
|
return () => inFlight.current?.abort();
|
|
10857
10977
|
}, [refresh, params.revisionCounter]);
|
|
10978
|
+
const { pollIntervalMs } = params;
|
|
10979
|
+
useEffect(() => {
|
|
10980
|
+
if (!pollIntervalMs || !params.accountAddress) return;
|
|
10981
|
+
const timer = setInterval(() => {
|
|
10982
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
10983
|
+
void refresh({ quiet: true });
|
|
10984
|
+
}, pollIntervalMs);
|
|
10985
|
+
return () => clearInterval(timer);
|
|
10986
|
+
}, [pollIntervalMs, params.accountAddress, refresh]);
|
|
10858
10987
|
return {
|
|
10859
10988
|
/** Balances for every display token, in display order. */
|
|
10860
10989
|
balances,
|
|
@@ -10907,6 +11036,9 @@ function formatFluentPortfolioPnlPercent(percent) {
|
|
|
10907
11036
|
|
|
10908
11037
|
// src/core/tokenPrices.ts
|
|
10909
11038
|
var COINGECKO_API = "https://api.coingecko.com/api/v3";
|
|
11039
|
+
var DEFILLAMA_COINS_API = "https://coins.llama.fi";
|
|
11040
|
+
var FLUENT_PRICE_REQUEST_TIMEOUT_MS = 5e3;
|
|
11041
|
+
var DEFILLAMA_FLUENT_MAINNET_CHAIN = "fluent";
|
|
10910
11042
|
var FIXED_USD_PRICES = {
|
|
10911
11043
|
USDnr: 1
|
|
10912
11044
|
};
|
|
@@ -10928,21 +11060,44 @@ function getCoinGeckoMarketChartRangeUrl(coinId, fromUnixSeconds, toUnixSeconds)
|
|
|
10928
11060
|
url.searchParams.set("to", String(toUnixSeconds));
|
|
10929
11061
|
return url.toString();
|
|
10930
11062
|
}
|
|
11063
|
+
function getDefiLlamaCurrentPricesUrl(coinKeys) {
|
|
11064
|
+
return `${DEFILLAMA_COINS_API}/prices/current/${coinKeys.join(",")}`;
|
|
11065
|
+
}
|
|
11066
|
+
function getDefiLlamaHistoricalPricesUrl(coinKeys, unixSeconds) {
|
|
11067
|
+
return `${DEFILLAMA_COINS_API}/prices/historical/${unixSeconds}/${coinKeys.join(",")}`;
|
|
11068
|
+
}
|
|
10931
11069
|
function resolveCoinbaseBaseSymbol(symbol) {
|
|
10932
11070
|
return COINBASE_BASE_BY_SYMBOL[symbol] ?? null;
|
|
10933
11071
|
}
|
|
10934
11072
|
function resolveCoinGeckoCoinId(symbol) {
|
|
10935
11073
|
return COINGECKO_COIN_ID_BY_SYMBOL[symbol] ?? null;
|
|
10936
11074
|
}
|
|
11075
|
+
function resolveDefiLlamaCoinKey(token) {
|
|
11076
|
+
if (!token.native && token.address && token.chainId === fluentMainnet.id) {
|
|
11077
|
+
return `${DEFILLAMA_FLUENT_MAINNET_CHAIN}:${token.address}`;
|
|
11078
|
+
}
|
|
11079
|
+
const coinId = resolveCoinGeckoCoinId(token.symbol);
|
|
11080
|
+
return coinId ? `coingecko:${coinId}` : null;
|
|
11081
|
+
}
|
|
10937
11082
|
function getFixedUsdPrice(symbol) {
|
|
10938
11083
|
return FIXED_USD_PRICES[symbol] ?? null;
|
|
10939
11084
|
}
|
|
11085
|
+
async function fetchWithTimeout(url) {
|
|
11086
|
+
const controller = new AbortController();
|
|
11087
|
+
const timer = setTimeout(() => controller.abort(), FLUENT_PRICE_REQUEST_TIMEOUT_MS);
|
|
11088
|
+
try {
|
|
11089
|
+
return await fetch(url, {
|
|
11090
|
+
headers: {
|
|
11091
|
+
Accept: "application/json"
|
|
11092
|
+
},
|
|
11093
|
+
signal: controller.signal
|
|
11094
|
+
});
|
|
11095
|
+
} finally {
|
|
11096
|
+
clearTimeout(timer);
|
|
11097
|
+
}
|
|
11098
|
+
}
|
|
10940
11099
|
async function fetchJson(url, provider) {
|
|
10941
|
-
const response = await
|
|
10942
|
-
headers: {
|
|
10943
|
-
Accept: "application/json"
|
|
10944
|
-
}
|
|
10945
|
-
});
|
|
11100
|
+
const response = await fetchWithTimeout(url);
|
|
10946
11101
|
if (!response.ok) {
|
|
10947
11102
|
const body = await response.text();
|
|
10948
11103
|
throw new Error(`${provider} request failed: ${response.status} ${body}`);
|
|
@@ -10951,12 +11106,13 @@ async function fetchJson(url, provider) {
|
|
|
10951
11106
|
}
|
|
10952
11107
|
async function fetchCoinbaseSpotUsdPrice(coinbaseSymbol) {
|
|
10953
11108
|
try {
|
|
10954
|
-
const response = await
|
|
11109
|
+
const response = await fetchWithTimeout(getCoinbaseSpotPriceUrl(coinbaseSymbol));
|
|
10955
11110
|
if (!response.ok) return null;
|
|
10956
11111
|
const payload = await response.json();
|
|
10957
11112
|
const amount = Number(payload.data?.amount);
|
|
10958
11113
|
return Number.isFinite(amount) ? amount : null;
|
|
10959
|
-
} catch {
|
|
11114
|
+
} catch (error) {
|
|
11115
|
+
debugWarn("[fluent-connect] Coinbase spot price request failed", coinbaseSymbol, error);
|
|
10960
11116
|
return null;
|
|
10961
11117
|
}
|
|
10962
11118
|
}
|
|
@@ -10985,97 +11141,222 @@ async function fetchCoinGeckoPrice24hAgo(coinId) {
|
|
|
10985
11141
|
}
|
|
10986
11142
|
return price24hAgo;
|
|
10987
11143
|
}
|
|
10988
|
-
async function
|
|
10989
|
-
const
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
|
|
10998
|
-
|
|
10999
|
-
|
|
11000
|
-
|
|
11001
|
-
|
|
11002
|
-
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11144
|
+
async function fetchDefiLlamaUsdPrices(url) {
|
|
11145
|
+
const prices = /* @__PURE__ */ new Map();
|
|
11146
|
+
try {
|
|
11147
|
+
const payload = await fetchJson(url, "DefiLlama");
|
|
11148
|
+
for (const [coinKey, coin] of Object.entries(payload.coins ?? {})) {
|
|
11149
|
+
const price = coin?.price;
|
|
11150
|
+
if (typeof price !== "number" || !Number.isFinite(price)) continue;
|
|
11151
|
+
prices.set(coinKey.toLowerCase(), price);
|
|
11152
|
+
}
|
|
11153
|
+
} catch (error) {
|
|
11154
|
+
debugWarn("[fluent-connect] DefiLlama price request failed", error);
|
|
11155
|
+
}
|
|
11156
|
+
return prices;
|
|
11157
|
+
}
|
|
11158
|
+
function getFluentPriceableTokens(tokens) {
|
|
11159
|
+
return tokens.filter((token) => isFluentDefaultToken(token));
|
|
11160
|
+
}
|
|
11161
|
+
async function fetchFluentTokenUsdPricePoints(tokens) {
|
|
11162
|
+
const subjects = /* @__PURE__ */ new Map();
|
|
11163
|
+
for (const token of getFluentPriceableTokens(tokens)) {
|
|
11164
|
+
subjects.set(fluentTokenIdentity(token), token);
|
|
11165
|
+
}
|
|
11166
|
+
const current = /* @__PURE__ */ new Map();
|
|
11167
|
+
const price24hAgo = /* @__PURE__ */ new Map();
|
|
11168
|
+
const fetched = [];
|
|
11169
|
+
for (const [identity, token] of subjects) {
|
|
11170
|
+
const fixed = getFixedUsdPrice(token.symbol);
|
|
11171
|
+
if (fixed !== null) {
|
|
11172
|
+
current.set(identity, fixed);
|
|
11173
|
+
price24hAgo.set(identity, fixed);
|
|
11174
|
+
} else {
|
|
11175
|
+
fetched.push([identity, token]);
|
|
11176
|
+
}
|
|
11177
|
+
}
|
|
11178
|
+
await Promise.all(
|
|
11179
|
+
fetched.map(async ([identity, token]) => {
|
|
11180
|
+
const coinbaseSymbol = resolveCoinbaseBaseSymbol(token.symbol);
|
|
11181
|
+
const coinGeckoCoinId = resolveCoinGeckoCoinId(token.symbol);
|
|
11182
|
+
const [spot, chart] = await Promise.all([
|
|
11183
|
+
coinbaseSymbol ? fetchCoinbaseSpotUsdPrice(coinbaseSymbol) : null,
|
|
11184
|
+
coinGeckoCoinId ? fetchCoinGeckoPrice24hAgo(coinGeckoCoinId).catch((error) => {
|
|
11185
|
+
debugWarn("[fluent-connect] CoinGecko chart request failed", coinGeckoCoinId, error);
|
|
11186
|
+
return null;
|
|
11187
|
+
}) : null
|
|
11188
|
+
]);
|
|
11189
|
+
if (spot !== null) current.set(identity, spot);
|
|
11190
|
+
if (chart !== null) price24hAgo.set(identity, chart);
|
|
11011
11191
|
})
|
|
11012
11192
|
);
|
|
11193
|
+
const missingCurrent = coinKeysOf(fetched.filter(([identity]) => !current.has(identity)));
|
|
11194
|
+
const missing24hAgo = coinKeysOf(fetched.filter(([identity]) => !price24hAgo.has(identity)));
|
|
11195
|
+
const nowUnixSeconds = Math.floor(Date.now() / 1e3);
|
|
11196
|
+
const [llamaCurrent, llama24hAgo] = await Promise.all([
|
|
11197
|
+
missingCurrent.size > 0 ? fetchDefiLlamaUsdPrices(getDefiLlamaCurrentPricesUrl(uniqueCoinKeys(missingCurrent))) : /* @__PURE__ */ new Map(),
|
|
11198
|
+
missing24hAgo.size > 0 ? fetchDefiLlamaUsdPrices(
|
|
11199
|
+
getDefiLlamaHistoricalPricesUrl(
|
|
11200
|
+
uniqueCoinKeys(missing24hAgo),
|
|
11201
|
+
nowUnixSeconds - 24 * 60 * 60
|
|
11202
|
+
)
|
|
11203
|
+
) : /* @__PURE__ */ new Map()
|
|
11204
|
+
]);
|
|
11205
|
+
applyDefiLlamaPrices(missingCurrent, llamaCurrent, current);
|
|
11206
|
+
applyDefiLlamaPrices(missing24hAgo, llama24hAgo, price24hAgo);
|
|
11207
|
+
const points = {};
|
|
11208
|
+
for (const identity of subjects.keys()) {
|
|
11209
|
+
const currentPrice = current.get(identity);
|
|
11210
|
+
if (currentPrice === void 0) continue;
|
|
11211
|
+
points[identity] = {
|
|
11212
|
+
current: currentPrice,
|
|
11213
|
+
price24hAgo: price24hAgo.get(identity) ?? currentPrice
|
|
11214
|
+
};
|
|
11215
|
+
}
|
|
11216
|
+
return points;
|
|
11217
|
+
}
|
|
11218
|
+
function coinKeysOf(entries) {
|
|
11219
|
+
const keys = /* @__PURE__ */ new Map();
|
|
11220
|
+
for (const [identity, token] of entries) {
|
|
11221
|
+
const coinKey = resolveDefiLlamaCoinKey(token);
|
|
11222
|
+
if (coinKey) keys.set(identity, coinKey);
|
|
11223
|
+
}
|
|
11224
|
+
return keys;
|
|
11225
|
+
}
|
|
11226
|
+
function uniqueCoinKeys(keysByIdentity) {
|
|
11227
|
+
return [...new Set(keysByIdentity.values())];
|
|
11228
|
+
}
|
|
11229
|
+
function applyDefiLlamaPrices(keysByIdentity, pricesByCoinKey, target) {
|
|
11230
|
+
for (const [identity, coinKey] of keysByIdentity) {
|
|
11231
|
+
const price = pricesByCoinKey.get(coinKey.toLowerCase());
|
|
11232
|
+
if (price !== void 0) target.set(identity, price);
|
|
11233
|
+
}
|
|
11234
|
+
}
|
|
11235
|
+
var FLUENT_TOKEN_PRICE_TTL_MS = 5 * 6e4;
|
|
11236
|
+
var priceCache = /* @__PURE__ */ new Map();
|
|
11237
|
+
var priceInFlight = /* @__PURE__ */ new Map();
|
|
11238
|
+
function isFreshPriceEntry(entry, now) {
|
|
11239
|
+
return entry !== void 0 && now - entry.readAt < FLUENT_TOKEN_PRICE_TTL_MS;
|
|
11240
|
+
}
|
|
11241
|
+
function peekFluentTokenUsdPricePoints(tokens, now = Date.now()) {
|
|
11013
11242
|
const prices = {};
|
|
11014
|
-
for (const
|
|
11015
|
-
|
|
11016
|
-
|
|
11243
|
+
for (const token of getFluentPriceableTokens(tokens)) {
|
|
11244
|
+
const identity = fluentTokenIdentity(token);
|
|
11245
|
+
const fixed = getFixedUsdPrice(token.symbol);
|
|
11246
|
+
if (fixed !== null) {
|
|
11247
|
+
prices[identity] = { current: fixed, price24hAgo: fixed };
|
|
11248
|
+
continue;
|
|
11249
|
+
}
|
|
11250
|
+
const entry = priceCache.get(identity);
|
|
11251
|
+
if (isFreshPriceEntry(entry, now) && entry?.point) prices[identity] = entry.point;
|
|
11017
11252
|
}
|
|
11018
11253
|
return prices;
|
|
11019
11254
|
}
|
|
11255
|
+
function getFluentTokenUsdPriceExpiry(tokens) {
|
|
11256
|
+
let expiry = null;
|
|
11257
|
+
for (const token of getFluentPriceableTokens(tokens)) {
|
|
11258
|
+
const entry = priceCache.get(fluentTokenIdentity(token));
|
|
11259
|
+
if (!entry) continue;
|
|
11260
|
+
const at = entry.readAt + FLUENT_TOKEN_PRICE_TTL_MS;
|
|
11261
|
+
if (expiry === null || at < expiry) expiry = at;
|
|
11262
|
+
}
|
|
11263
|
+
return expiry;
|
|
11264
|
+
}
|
|
11265
|
+
async function readFluentTokenUsdPricePoints(tokens, now = Date.now()) {
|
|
11266
|
+
const points = {};
|
|
11267
|
+
const awaited = [];
|
|
11268
|
+
const toAsk = /* @__PURE__ */ new Map();
|
|
11269
|
+
for (const token of getFluentPriceableTokens(tokens)) {
|
|
11270
|
+
const identity = fluentTokenIdentity(token);
|
|
11271
|
+
const fixed = getFixedUsdPrice(token.symbol);
|
|
11272
|
+
if (fixed !== null) {
|
|
11273
|
+
points[identity] = { current: fixed, price24hAgo: fixed };
|
|
11274
|
+
continue;
|
|
11275
|
+
}
|
|
11276
|
+
const cached = priceCache.get(identity);
|
|
11277
|
+
if (isFreshPriceEntry(cached, now)) {
|
|
11278
|
+
if (cached?.point) points[identity] = cached.point;
|
|
11279
|
+
continue;
|
|
11280
|
+
}
|
|
11281
|
+
const inFlight = priceInFlight.get(identity);
|
|
11282
|
+
if (inFlight) {
|
|
11283
|
+
awaited.push([identity, inFlight]);
|
|
11284
|
+
continue;
|
|
11285
|
+
}
|
|
11286
|
+
toAsk.set(identity, token);
|
|
11287
|
+
}
|
|
11288
|
+
if (toAsk.size > 0) {
|
|
11289
|
+
const batch = fetchFluentTokenUsdPricePoints([...toAsk.values()]);
|
|
11290
|
+
for (const identity of toAsk.keys()) {
|
|
11291
|
+
const pending2 = batch.then((fetched) => {
|
|
11292
|
+
const point = fetched[identity] ?? null;
|
|
11293
|
+
priceCache.set(identity, { point, readAt: Date.now() });
|
|
11294
|
+
return point;
|
|
11295
|
+
});
|
|
11296
|
+
priceInFlight.set(identity, pending2);
|
|
11297
|
+
void pending2.finally(() => {
|
|
11298
|
+
if (priceInFlight.get(identity) === pending2) priceInFlight.delete(identity);
|
|
11299
|
+
});
|
|
11300
|
+
awaited.push([identity, pending2]);
|
|
11301
|
+
}
|
|
11302
|
+
}
|
|
11303
|
+
for (const [identity, pending2] of awaited) {
|
|
11304
|
+
const point = await pending2;
|
|
11305
|
+
if (point) points[identity] = point;
|
|
11306
|
+
}
|
|
11307
|
+
return points;
|
|
11308
|
+
}
|
|
11020
11309
|
function splitFluentTokenUsdPricePoints(points) {
|
|
11021
11310
|
const prices = {};
|
|
11022
11311
|
const prices24hAgo = {};
|
|
11023
|
-
for (const [
|
|
11024
|
-
prices[
|
|
11025
|
-
prices24hAgo[
|
|
11312
|
+
for (const [identity, point] of Object.entries(points)) {
|
|
11313
|
+
prices[identity] = point.current;
|
|
11314
|
+
prices24hAgo[identity] = point.price24hAgo;
|
|
11026
11315
|
}
|
|
11027
11316
|
return { prices, prices24hAgo };
|
|
11028
11317
|
}
|
|
11029
|
-
function getFluentPriceableSymbols(tokens) {
|
|
11030
|
-
return tokens.filter(isFluentDefaultToken).map((token) => token.symbol);
|
|
11031
|
-
}
|
|
11032
|
-
function mapFluentPricesToTokenIdentities(tokens, pricesBySymbol) {
|
|
11033
|
-
const byIdentity = {};
|
|
11034
|
-
for (const token of tokens) {
|
|
11035
|
-
if (!isFluentDefaultToken(token)) continue;
|
|
11036
|
-
const price = pricesBySymbol[token.symbol];
|
|
11037
|
-
if (price === void 0) continue;
|
|
11038
|
-
byIdentity[fluentTokenIdentity(token)] = price;
|
|
11039
|
-
}
|
|
11040
|
-
return byIdentity;
|
|
11041
|
-
}
|
|
11042
11318
|
|
|
11043
11319
|
// src/hooks/useFluentTokenUsdPrices.ts
|
|
11044
11320
|
function useFluentTokenUsdPrices(tokens) {
|
|
11045
|
-
const
|
|
11046
|
-
() =>
|
|
11321
|
+
const subjectKey = useMemo(
|
|
11322
|
+
() => getFluentPriceableTokens(tokens).map(fluentTokenIdentity).sort().join(","),
|
|
11047
11323
|
[tokens]
|
|
11048
11324
|
);
|
|
11049
|
-
const [
|
|
11050
|
-
const [
|
|
11051
|
-
const [busy, setBusy] = useState(() => Boolean(symbolKey));
|
|
11325
|
+
const [points, setPoints] = useState({});
|
|
11326
|
+
const [busy, setBusy] = useState(() => Boolean(subjectKey));
|
|
11052
11327
|
useEffect(() => {
|
|
11053
|
-
if (!
|
|
11054
|
-
|
|
11055
|
-
setPricesBySymbolYesterday({});
|
|
11328
|
+
if (!subjectKey) {
|
|
11329
|
+
setPoints({});
|
|
11056
11330
|
setBusy(false);
|
|
11057
11331
|
return;
|
|
11058
11332
|
}
|
|
11333
|
+
const subjects = getFluentPriceableTokens(tokens);
|
|
11059
11334
|
let active = true;
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
11063
|
-
const next = splitFluentTokenUsdPricePoints(points);
|
|
11064
|
-
setPricesBySymbol(next.prices);
|
|
11065
|
-
setPricesBySymbolYesterday(next.prices24hAgo);
|
|
11335
|
+
let timer;
|
|
11336
|
+
const apply = (next) => {
|
|
11337
|
+
setPoints(next);
|
|
11066
11338
|
setBusy(false);
|
|
11067
|
-
}
|
|
11339
|
+
};
|
|
11340
|
+
const load = async () => {
|
|
11341
|
+
const next = await readFluentTokenUsdPricePoints(subjects);
|
|
11342
|
+
if (!active) return;
|
|
11343
|
+
apply(next);
|
|
11344
|
+
const expiry = getFluentTokenUsdPriceExpiry(subjects);
|
|
11345
|
+
if (expiry !== null) timer = setTimeout(load, Math.max(0, expiry - Date.now()));
|
|
11346
|
+
};
|
|
11347
|
+
const cached = peekFluentTokenUsdPricePoints(subjects);
|
|
11348
|
+
const everyCached = subjects.every((token) => fluentTokenIdentity(token) in cached);
|
|
11349
|
+
if (everyCached) apply(cached);
|
|
11350
|
+
else setBusy(true);
|
|
11351
|
+
void load();
|
|
11068
11352
|
return () => {
|
|
11069
11353
|
active = false;
|
|
11354
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
11070
11355
|
};
|
|
11071
|
-
}, [
|
|
11072
|
-
const prices = useMemo(
|
|
11073
|
-
() =>
|
|
11074
|
-
[
|
|
11075
|
-
);
|
|
11076
|
-
const pricesYesterday = useMemo(
|
|
11077
|
-
() => mapFluentPricesToTokenIdentities(tokens, pricesBySymbolYesterday),
|
|
11078
|
-
[tokens, pricesBySymbolYesterday]
|
|
11356
|
+
}, [subjectKey]);
|
|
11357
|
+
const { prices, prices24hAgo: pricesYesterday } = useMemo(
|
|
11358
|
+
() => splitFluentTokenUsdPricePoints(points),
|
|
11359
|
+
[points]
|
|
11079
11360
|
);
|
|
11080
11361
|
return { prices, pricesYesterday, busy };
|
|
11081
11362
|
}
|
|
@@ -11199,12 +11480,14 @@ function useFluentTransactionHistory(params) {
|
|
|
11199
11480
|
|
|
11200
11481
|
// src/widget/walletMenuSubPages.ts
|
|
11201
11482
|
var DEPOSIT_SWAP_TAB = "deposit-swap";
|
|
11483
|
+
var SENT_TRANSFER_TAB = "sent-transfer";
|
|
11202
11484
|
var WALLET_MENU_SUB_PAGES = {
|
|
11203
11485
|
settings: { title: "Settings" },
|
|
11204
11486
|
send: { title: "Send" },
|
|
11205
11487
|
bridge: { title: "Swap" },
|
|
11206
11488
|
activity: { title: "Transfer" },
|
|
11207
11489
|
[DEPOSIT_SWAP_TAB]: { title: "Transfer" },
|
|
11490
|
+
[SENT_TRANSFER_TAB]: { title: "Transfer" },
|
|
11208
11491
|
// Closed with an X, not walked back from: leaving it is the rejection.
|
|
11209
11492
|
review: { title: "Confirm transaction", dismiss: "close" }
|
|
11210
11493
|
};
|
|
@@ -11745,6 +12028,7 @@ function WalletMenuActionCard({
|
|
|
11745
12028
|
tokenListError = null,
|
|
11746
12029
|
onSendToken,
|
|
11747
12030
|
pendingTransfers,
|
|
12031
|
+
sentTransfer,
|
|
11748
12032
|
sentDeposits,
|
|
11749
12033
|
depositSwap,
|
|
11750
12034
|
onMintUsdnr,
|
|
@@ -11917,7 +12201,12 @@ function WalletMenuActionCard({
|
|
|
11917
12201
|
accountAddress,
|
|
11918
12202
|
tokens,
|
|
11919
12203
|
revisionCounter: balanceRevisionCounter,
|
|
11920
|
-
userTokenStore
|
|
12204
|
+
userTokenStore,
|
|
12205
|
+
// The account drawer unmounts its content when it closes, so this card is
|
|
12206
|
+
// mounted exactly while the wallet menu is open: the mount reads once for
|
|
12207
|
+
// the opening, and the schedule catches transfers that arrive from outside
|
|
12208
|
+
// the widget while it stays open.
|
|
12209
|
+
pollIntervalMs: FLUENT_BALANCE_POLL_INTERVAL_MS
|
|
11921
12210
|
});
|
|
11922
12211
|
const { prices, pricesYesterday, busy: pricesBusy } = useFluentTokenUsdPrices(displayTokens);
|
|
11923
12212
|
const activityPriceOf = useActivityPrices(prices, displayTokens);
|
|
@@ -12107,12 +12396,25 @@ function WalletMenuActionCard({
|
|
|
12107
12396
|
onSend: onSendToken,
|
|
12108
12397
|
onSent: () => {
|
|
12109
12398
|
setHomePanel("activity");
|
|
12110
|
-
onTabChange(
|
|
12399
|
+
onTabChange(SENT_TRANSFER_TAB);
|
|
12111
12400
|
onRevealAccount?.();
|
|
12112
12401
|
}
|
|
12113
12402
|
}
|
|
12114
12403
|
);
|
|
12115
12404
|
}
|
|
12405
|
+
if (tab === SENT_TRANSFER_TAB) {
|
|
12406
|
+
if (!sentTransfer || !accountAddress) return null;
|
|
12407
|
+
return /* @__PURE__ */ jsx(
|
|
12408
|
+
SentTransferDetail,
|
|
12409
|
+
{
|
|
12410
|
+
transfer: sentTransfer,
|
|
12411
|
+
account: accountAddress,
|
|
12412
|
+
network: resolvedConfig.network,
|
|
12413
|
+
priceOf: activityPriceOf,
|
|
12414
|
+
track
|
|
12415
|
+
}
|
|
12416
|
+
);
|
|
12417
|
+
}
|
|
12116
12418
|
if (tab === DEPOSIT_SWAP_TAB) {
|
|
12117
12419
|
if (!depositSwap || !accountAddress) return null;
|
|
12118
12420
|
return /* @__PURE__ */ jsx(
|
|
@@ -13875,7 +14177,13 @@ function BridgeForm({
|
|
|
13875
14177
|
const receiveToken = twoStep && swapTarget ? swapTarget : deliveredToken;
|
|
13876
14178
|
const receiveAmount = twoStep ? quote?.amountOut : bridge.receiveAmount;
|
|
13877
14179
|
const approximate = isSwap || twoStep ? "\u2248 " : "";
|
|
13878
|
-
const receiveText = receiveAmount === void 0 || receiveAmount === 0n ? twoStep && swapQuote.loading ? "\u2026" : "0" : `${approximate}${formatAmount(receiveAmount, receiveToken.decimals)}`;
|
|
14180
|
+
const receiveText = receiveAmount === void 0 || receiveAmount === 0n ? twoStep && swapQuote.loading ? "\u2026" : "0" : `${approximate}${formatAmount(receiveAmount, receiveToken.decimals, receiveToken.symbol)}`;
|
|
14181
|
+
const receiveExact = receiveAmount === void 0 || receiveAmount === 0n ? void 0 : `${formatUnits(receiveAmount, receiveToken.decimals)} ${receiveToken.symbol}`;
|
|
14182
|
+
const receiveUsd = formatAmountUsd(
|
|
14183
|
+
receiveAmount === void 0 ? "0" : formatUnits(receiveAmount, receiveToken.decimals),
|
|
14184
|
+
priceOf(receiveToken.symbol)
|
|
14185
|
+
);
|
|
14186
|
+
const receiveUsdText = receiveUsd && receiveAmount !== void 0 && receiveAmount > 0n ? `${approximate}${receiveUsd}` : receiveUsd;
|
|
13879
14187
|
const isFastPath = deliveredToken.route === "fast-path";
|
|
13880
14188
|
const showApprovalSteps = bridge.connected && !bridge.wrongChain && isErc20 && !isSwap;
|
|
13881
14189
|
const approvalStep = Number(form.amount) > 0 && !bridge.needsApproval && !bridge.approving ? 2 : 1;
|
|
@@ -13920,7 +14228,7 @@ function BridgeForm({
|
|
|
13920
14228
|
"span",
|
|
13921
14229
|
{
|
|
13922
14230
|
title: bridge.sourceBalance !== void 0 ? formatUnits(bridge.sourceBalance, token.decimals) : void 0,
|
|
13923
|
-
children: bridge.balanceLoading ? "Loading balance..." : `${formatAmount(bridge.sourceBalance, token.decimals)} ${token.symbol}`
|
|
14231
|
+
children: bridge.balanceLoading ? "Loading balance..." : `${formatAmount(bridge.sourceBalance, token.decimals, token.symbol)} ${token.symbol}`
|
|
13924
14232
|
}
|
|
13925
14233
|
),
|
|
13926
14234
|
/* @__PURE__ */ jsx(
|
|
@@ -13945,6 +14253,7 @@ function BridgeForm({
|
|
|
13945
14253
|
{
|
|
13946
14254
|
className: `block truncate font-medium leading-[1.2] ${receiveText === "0" ? "text-foreground/40" : "text-foreground"}`,
|
|
13947
14255
|
style: getAmountFontStyle(receiveText),
|
|
14256
|
+
title: receiveExact,
|
|
13948
14257
|
children: receiveText
|
|
13949
14258
|
}
|
|
13950
14259
|
) }),
|
|
@@ -13958,6 +14267,7 @@ function BridgeForm({
|
|
|
13958
14267
|
}
|
|
13959
14268
|
) : /* @__PURE__ */ jsx(TokenChip, { symbol: deliveredToken.symbol })
|
|
13960
14269
|
] }),
|
|
14270
|
+
receiveUsdText ? /* @__PURE__ */ jsx("span", { className: "min-w-0 truncate text-sm text-foreground/60", title: receiveUsdText, children: receiveUsdText }) : null,
|
|
13961
14271
|
swapProblem ? /* @__PURE__ */ jsx("span", { className: "text-xs text-destructive", children: swapProblem }) : null
|
|
13962
14272
|
] })
|
|
13963
14273
|
] }),
|
|
@@ -14011,7 +14321,8 @@ function BridgeForm({
|
|
|
14011
14321
|
SummaryRow,
|
|
14012
14322
|
{
|
|
14013
14323
|
label: "Minimum received",
|
|
14014
|
-
value: minimumOut === void 0 ? swapQuote.loading ? "Pricing\u2026" : "\u2014" : `${formatAmount(minimumOut, swapTarget.decimals)} ${swapTarget.symbol}`,
|
|
14324
|
+
value: minimumOut === void 0 ? swapQuote.loading ? "Pricing\u2026" : "\u2014" : `${formatAmount(minimumOut, swapTarget.decimals, swapTarget.symbol)} ${swapTarget.symbol}`,
|
|
14325
|
+
valueTitle: minimumOut === void 0 ? void 0 : `${formatUnits(minimumOut, swapTarget.decimals)} ${swapTarget.symbol}`,
|
|
14015
14326
|
tooltip: SLIPPAGE_TOOLTIP
|
|
14016
14327
|
}
|
|
14017
14328
|
),
|
|
@@ -14993,6 +15304,7 @@ function encodeBatchCall(call) {
|
|
|
14993
15304
|
};
|
|
14994
15305
|
}
|
|
14995
15306
|
var FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY = "selfFunded=true";
|
|
15307
|
+
var FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS = 50000n;
|
|
14996
15308
|
function getFluentZeroDevErc20PaymasterTokens(network = "testnet") {
|
|
14997
15309
|
return Object.fromEntries(
|
|
14998
15310
|
getFluentDefaultWidgetGasTokens(network).filter((token) => !isFluentNativeToken(token) && token.address).map((token) => [
|
|
@@ -15070,7 +15382,7 @@ function createFluentZeroDevErc20Paymaster(params) {
|
|
|
15070
15382
|
getPaymasterData: (userOperation) => {
|
|
15071
15383
|
const contextToken = getPaymasterContextToken(userOperation.context);
|
|
15072
15384
|
return paymasterClient.sponsorUserOperation({
|
|
15073
|
-
userOperation: withoutChainMetadata(userOperation),
|
|
15385
|
+
userOperation: withMinimumPostOpGas(withoutChainMetadata(userOperation)),
|
|
15074
15386
|
gasToken: contextToken ?? gasToken.address
|
|
15075
15387
|
});
|
|
15076
15388
|
}
|
|
@@ -15133,6 +15445,14 @@ function getPaymasterContextToken(context) {
|
|
|
15133
15445
|
const token = context.token;
|
|
15134
15446
|
return typeof token === "string" && token.startsWith("0x") ? token : void 0;
|
|
15135
15447
|
}
|
|
15448
|
+
function withMinimumPostOpGas(userOperation) {
|
|
15449
|
+
const limit = userOperation.paymasterPostOpGasLimit;
|
|
15450
|
+
if (limit !== void 0 && limit >= FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS) return userOperation;
|
|
15451
|
+
return {
|
|
15452
|
+
...userOperation,
|
|
15453
|
+
paymasterPostOpGasLimit: FLUENT_ZERODEV_ERC20_MIN_POSTOP_GAS
|
|
15454
|
+
};
|
|
15455
|
+
}
|
|
15136
15456
|
function withoutChainMetadata(userOperation) {
|
|
15137
15457
|
const {
|
|
15138
15458
|
chain: _chain,
|
|
@@ -20107,7 +20427,7 @@ function FluentWidgetContent({
|
|
|
20107
20427
|
reviewOriginRef.current = null;
|
|
20108
20428
|
const wasSend = batchReview?.id === FLUENT_SEND_TOKEN_OP_ID;
|
|
20109
20429
|
if (outcome === "confirmed" && wasSend) {
|
|
20110
|
-
setWalletMenuTab(
|
|
20430
|
+
setWalletMenuTab(SENT_TRANSFER_TAB);
|
|
20111
20431
|
setAccountOpen(true);
|
|
20112
20432
|
return;
|
|
20113
20433
|
}
|
|
@@ -20150,10 +20470,12 @@ function FluentWidgetContent({
|
|
|
20150
20470
|
});
|
|
20151
20471
|
const [pendingTransfers, setPendingTransfers] = useState([]);
|
|
20152
20472
|
const pendingTransferCount = useRef(0);
|
|
20473
|
+
const [sentTransfer, setSentTransfer] = useState(null);
|
|
20153
20474
|
const beginTransfer = useCallback(
|
|
20154
20475
|
(transfer) => {
|
|
20155
20476
|
const id = `pending-${pendingTransferCount.current += 1}`;
|
|
20156
20477
|
setPendingTransfers((list) => [...list, { ...transfer, id }]);
|
|
20478
|
+
setSentTransfer({ ...transfer, id });
|
|
20157
20479
|
setWalletMenuPanel("activity");
|
|
20158
20480
|
return id;
|
|
20159
20481
|
},
|
|
@@ -20161,12 +20483,14 @@ function FluentWidgetContent({
|
|
|
20161
20483
|
);
|
|
20162
20484
|
const endTransfer = useCallback((id) => {
|
|
20163
20485
|
setPendingTransfers((list) => list.filter((transfer) => transfer.id !== id));
|
|
20486
|
+
setSentTransfer((transfer) => transfer?.id === id && !transfer.hash ? null : transfer);
|
|
20164
20487
|
}, []);
|
|
20165
20488
|
const settleTransfer = useCallback(
|
|
20166
20489
|
(id, hash) => {
|
|
20167
20490
|
setPendingTransfers(
|
|
20168
20491
|
(list) => list.map((transfer) => transfer.id === id ? { ...transfer, hash } : transfer)
|
|
20169
20492
|
);
|
|
20493
|
+
setSentTransfer((transfer) => transfer?.id === id ? { ...transfer, hash } : transfer);
|
|
20170
20494
|
setTimeout(() => {
|
|
20171
20495
|
setPendingTransfers(
|
|
20172
20496
|
(list) => list.map((transfer) => transfer.id === id ? { ...transfer, expired: true } : transfer)
|
|
@@ -20176,6 +20500,9 @@ function FluentWidgetContent({
|
|
|
20176
20500
|
},
|
|
20177
20501
|
[endTransfer]
|
|
20178
20502
|
);
|
|
20503
|
+
useEffect(() => {
|
|
20504
|
+
if (walletMenuTab === SENT_TRANSFER_TAB && !sentTransfer) setWalletMenuTab("home");
|
|
20505
|
+
}, [walletMenuTab, sentTransfer, setWalletMenuTab]);
|
|
20179
20506
|
const [sentDeposits, setSentDeposits] = useState([]);
|
|
20180
20507
|
const addSentDeposit = useCallback((deposit) => {
|
|
20181
20508
|
setSentDeposits((list) => [...list, deposit]);
|
|
@@ -20810,6 +21137,7 @@ function FluentWidgetContent({
|
|
|
20810
21137
|
onPanelChange: setWalletMenuPanel,
|
|
20811
21138
|
onSendToken: sendToken,
|
|
20812
21139
|
pendingTransfers,
|
|
21140
|
+
sentTransfer: sentTransfer ?? void 0,
|
|
20813
21141
|
sentDeposits,
|
|
20814
21142
|
depositSwap,
|
|
20815
21143
|
onMintUsdnr: mintUsdnr,
|