@pollar/react 0.12.1-rc.26 → 0.12.1-rc.27
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.css +315 -295
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +13 -3
- package/dist/index.d.ts +13 -3
- package/dist/index.js +1675 -1609
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1676 -1610
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { AUTH_ERROR_CODES, authErrorMessage, rampLegTitle, rampRequirementCopy, rampTrustlineAsset, rampWalletStep, rampResolutionText, rampRailLabel, describeRampAction, rampStepTitle, rampLegStatus, rampOrderStopped, rampOrderReceive, rampLegNote, countryName, rampNoRouteText, rampFieldError, rampFieldValid, rampFailureReason, rampLegTimeLeft, rampStepStatusText, rampOrderResolutionText, rampFailureNeedsSupport, rampSupportCopy,
|
|
2
|
+
import { AUTH_ERROR_CODES, authErrorMessage, rampLegTitle, rampRequirementCopy, rampTrustlineAsset, rampWalletStep, rampResolutionText, rampRailLabel, describeRampAction, rampStepTitle, rampLegStatus, rampOrderStopped, rampOrderReceive, rampLegNote, countryName, rampNoRouteText, rampFieldError, rampFieldValid, rampFailureReason, rampLegTimeLeft, rampStepStatusText, rampOrderResolutionText, rampFailureNeedsSupport, rampSupportCopy, startBackoffPoll, isPollarNetworkError, transactionErrorMessage, isPollarApiError, isTransientApiError, rampCountries, rampQuoteFields, rampNextApproval, rampSupportContact, WalletType, bridgeSourceChains, bridgeTargetChains, isBridgeSettled, isPollarClient, PollarClient, isInteractiveAuthAdapter, isTransientFailure, isAuthEntryAdapterStep, completeAuthEntryStep, isKycSettled, rampTrustlineErrorText, toBaseUnits, resolveLanguage, languageFromTag, localizedText, appUnavailableMessage, fromBaseUnits, cosignRefusalMessage, assertRampStellarSigner } from '@pollar/core';
|
|
3
3
|
import { createContext, forwardRef, useState, useCallback, useEffect, useMemo, useRef, useContext, useSyncExternalStore, useId, useLayoutEffect, Component } from 'react';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { createPortal } from 'react-dom';
|
|
@@ -1309,7 +1309,7 @@ var PollarModalFooter = ({ language: languageProp }) => {
|
|
|
1309
1309
|
/* @__PURE__ */ jsx("img", { src: LOGO_POLLAR_WORDMARK_ON_DARK, alt: "Pollar", className: "pollar-footer-logo pollar-logo-on-dark" }),
|
|
1310
1310
|
/* @__PURE__ */ jsxs("span", { className: "pollar-footer-version", children: [
|
|
1311
1311
|
"v",
|
|
1312
|
-
"0.12.1-rc.
|
|
1312
|
+
"0.12.1-rc.27"
|
|
1313
1313
|
] })
|
|
1314
1314
|
] });
|
|
1315
1315
|
};
|
|
@@ -4983,7 +4983,8 @@ function LoginModalTemplate({
|
|
|
4983
4983
|
const cssVars = buildModalCssVars(theme, accentColor, styleOverrides, "hero");
|
|
4984
4984
|
const status = authStateToStatus(authState.step);
|
|
4985
4985
|
const isLoading = status === "LOADING";
|
|
4986
|
-
const isEmailCodeError = authState.step === "error" && (authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_EXPIRED || authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_INVALID
|
|
4986
|
+
const isEmailCodeError = authState.step === "error" && (authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_EXPIRED || authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_INVALID || // A rate limit or a server error on verify: the same code can go again.
|
|
4987
|
+
authState.errorCode === AUTH_ERROR_CODES.EMAIL_VERIFY_FAILED);
|
|
4987
4988
|
const awaitingEmailCode = authState.step === "entering_code" || authState.step === "verifying_email_code" || isEmailCodeError;
|
|
4988
4989
|
const statusMessage = authState.step === "error" ? authErrorMessage(authState.code, language) ?? authState.message : copy.status[authState.step];
|
|
4989
4990
|
const BackButton = ({ onClick }) => /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-back-btn", onClick, "aria-label": copy.back, children: /* @__PURE__ */ jsx(
|
|
@@ -5406,6 +5407,10 @@ function LoginModal({ onClose, inline = false }) {
|
|
|
5406
5407
|
getClient().cancelLogin();
|
|
5407
5408
|
}
|
|
5408
5409
|
function handleRetry() {
|
|
5410
|
+
if (authState.step === "error" && authState.errorCode === AUTH_ERROR_CODES.EMAIL_SEND_FAILED && authState.code === "RATE_LIMITED" && authState.clientSessionId && authState.email) {
|
|
5411
|
+
getClient().sendEmailCode(authState.email);
|
|
5412
|
+
return;
|
|
5413
|
+
}
|
|
5409
5414
|
getClient().logout();
|
|
5410
5415
|
if (styles.emailEnabled) {
|
|
5411
5416
|
getClient().beginEmailLogin();
|
|
@@ -5643,7 +5648,9 @@ var RAMP_COPY = {
|
|
|
5643
5648
|
send: (amount, code) => `Send ${amount} ${code}`,
|
|
5644
5649
|
delivering: (code) => `Your ${code} is on its way`,
|
|
5645
5650
|
payingOut: (currency) => `Your ${currency} is on its way to your account`,
|
|
5646
|
-
|
|
5651
|
+
stepLabel: (position, total, title) => `Step ${position} of ${total}: ${title}`,
|
|
5652
|
+
finalStep: "Done",
|
|
5653
|
+
paidAt: "Paid",
|
|
5647
5654
|
paidDone: (amount, currency) => `You paid ${amount} ${currency}.`,
|
|
5648
5655
|
sentDone: (amount, code) => `You sent ${amount} ${code}.`,
|
|
5649
5656
|
receivedDone: (amount, code, chain) => `You received ${amount} ${code} on ${chain}.`,
|
|
@@ -5660,7 +5667,6 @@ var RAMP_COPY = {
|
|
|
5660
5667
|
received: (amount) => `+${amount}`,
|
|
5661
5668
|
arrived: (chain) => `It reached your wallet on ${chain}.`,
|
|
5662
5669
|
paidOut: "It was sent to your account.",
|
|
5663
|
-
finish: "Done",
|
|
5664
5670
|
details: "Details"
|
|
5665
5671
|
},
|
|
5666
5672
|
somethingWrong: "Something went wrong.",
|
|
@@ -5809,7 +5815,9 @@ var RAMP_COPY = {
|
|
|
5809
5815
|
send: (amount, code) => `Env\xEDa ${amount} ${code}`,
|
|
5810
5816
|
delivering: (code) => `Tu ${code} est\xE1 en camino`,
|
|
5811
5817
|
payingOut: (currency) => `Tus ${currency} van en camino a tu cuenta`,
|
|
5812
|
-
|
|
5818
|
+
stepLabel: (position, total, title) => `Paso ${position} de ${total}: ${title}`,
|
|
5819
|
+
finalStep: "Listo",
|
|
5820
|
+
paidAt: "Pagado",
|
|
5813
5821
|
paidDone: (amount, currency) => `Pagaste ${amount} ${currency}.`,
|
|
5814
5822
|
sentDone: (amount, code) => `Enviaste ${amount} ${code}.`,
|
|
5815
5823
|
receivedDone: (amount, code, chain) => `Recibiste ${amount} ${code} en ${chain}.`,
|
|
@@ -5826,7 +5834,6 @@ var RAMP_COPY = {
|
|
|
5826
5834
|
received: (amount) => `+${amount}`,
|
|
5827
5835
|
arrived: (chain) => `Lleg\xF3 a tu wallet en ${chain}.`,
|
|
5828
5836
|
paidOut: "Se envi\xF3 a tu cuenta.",
|
|
5829
|
-
finish: "Listo",
|
|
5830
5837
|
details: "Detalles"
|
|
5831
5838
|
},
|
|
5832
5839
|
somethingWrong: "Algo sali\xF3 mal.",
|
|
@@ -5975,7 +5982,9 @@ var RAMP_COPY = {
|
|
|
5975
5982
|
send: (amount, code) => `Envie ${amount} ${code}`,
|
|
5976
5983
|
delivering: (code) => `Seu ${code} est\xE1 a caminho`,
|
|
5977
5984
|
payingOut: (currency) => `Seus ${currency} est\xE3o a caminho da sua conta`,
|
|
5978
|
-
|
|
5985
|
+
stepLabel: (position, total, title) => `Etapa ${position} de ${total}: ${title}`,
|
|
5986
|
+
finalStep: "Pronto",
|
|
5987
|
+
paidAt: "Pago em",
|
|
5979
5988
|
paidDone: (amount, currency) => `Voc\xEA pagou ${amount} ${currency}.`,
|
|
5980
5989
|
sentDone: (amount, code) => `Voc\xEA enviou ${amount} ${code}.`,
|
|
5981
5990
|
receivedDone: (amount, code, chain) => `Voc\xEA recebeu ${amount} ${code} na ${chain}.`,
|
|
@@ -5992,7 +6001,6 @@ var RAMP_COPY = {
|
|
|
5992
6001
|
received: (amount) => `+${amount}`,
|
|
5993
6002
|
arrived: (chain) => `Chegou \xE0 sua carteira na ${chain}.`,
|
|
5994
6003
|
paidOut: "Foi enviado para a sua conta.",
|
|
5995
|
-
finish: "Pronto",
|
|
5996
6004
|
details: "Detalhes"
|
|
5997
6005
|
},
|
|
5998
6006
|
somethingWrong: "Algo deu errado.",
|
|
@@ -6454,6 +6462,7 @@ function RampWidgetTemplate({
|
|
|
6454
6462
|
language: languageProp,
|
|
6455
6463
|
confirmation = null,
|
|
6456
6464
|
onCancelOrder,
|
|
6465
|
+
cosignPrompt = null,
|
|
6457
6466
|
cancelling = false,
|
|
6458
6467
|
cancelError = null
|
|
6459
6468
|
}) {
|
|
@@ -6465,6 +6474,7 @@ function RampWidgetTemplate({
|
|
|
6465
6474
|
const [detailsOpen, setDetailsOpen] = useState(false);
|
|
6466
6475
|
const [viewing, setViewing] = useState(null);
|
|
6467
6476
|
const [leaving, setLeaving] = useState(false);
|
|
6477
|
+
const [doneDetailsOpen, setDoneDetailsOpen] = useState(false);
|
|
6468
6478
|
useEffect(() => {
|
|
6469
6479
|
setViewing(null);
|
|
6470
6480
|
setLeaving(false);
|
|
@@ -6574,7 +6584,25 @@ function RampWidgetTemplate({
|
|
|
6574
6584
|
return screen.kind === "action" ? copy.screens.signedDone : copy.screens.ranDone;
|
|
6575
6585
|
};
|
|
6576
6586
|
const finalNote = order?.legs.map((leg) => rampLegNote(leg, language)).find((note) => note !== null) ?? null;
|
|
6577
|
-
const
|
|
6587
|
+
const paidQr = (screen) => {
|
|
6588
|
+
if (!screen.key.endsWith(":pay")) return null;
|
|
6589
|
+
const instructions = screen.leg.paymentRequest?.instructions;
|
|
6590
|
+
return instructions?.kind === "qr" ? instructions.scannable?.image ?? null : null;
|
|
6591
|
+
};
|
|
6592
|
+
const paidRows = (screen) => {
|
|
6593
|
+
if (!screen.key.endsWith(":pay") || !order) return [];
|
|
6594
|
+
const at = screen.leg.paymentReceivedAt;
|
|
6595
|
+
return [
|
|
6596
|
+
...at ? [
|
|
6597
|
+
{
|
|
6598
|
+
label: copy.screens.paidAt,
|
|
6599
|
+
value: new Date(at).toLocaleString(language, { dateStyle: "medium", timeStyle: "short" })
|
|
6600
|
+
}
|
|
6601
|
+
] : [],
|
|
6602
|
+
{ label: copy.order, value: `\u2026${order.id.slice(-8)}`, copyValue: order.id, mono: true }
|
|
6603
|
+
];
|
|
6604
|
+
};
|
|
6605
|
+
const screenRowsOf = (screen) => screen.steps.length ? screen.steps.flatMap(
|
|
6578
6606
|
(st) => st.hash ? [
|
|
6579
6607
|
{
|
|
6580
6608
|
label: rampStepTitle(st, screen.leg, language),
|
|
@@ -6591,6 +6619,7 @@ function RampWidgetTemplate({
|
|
|
6591
6619
|
copyValue: screen.leg.onchainTxHash
|
|
6592
6620
|
}
|
|
6593
6621
|
] : [];
|
|
6622
|
+
const screenRows = (screen) => [...paidRows(screen), ...screenRowsOf(screen)];
|
|
6594
6623
|
const stepTitle = {
|
|
6595
6624
|
input: onramp ? copy.title.buy : copy.title.sell,
|
|
6596
6625
|
loading_quote: copy.title.finding,
|
|
@@ -6680,41 +6709,33 @@ function RampWidgetTemplate({
|
|
|
6680
6709
|
}
|
|
6681
6710
|
) }, label)) })
|
|
6682
6711
|
] }),
|
|
6683
|
-
step === "status" && screens.length > 0 && !(leaving && !settled) && /* @__PURE__ */
|
|
6684
|
-
|
|
6712
|
+
step === "status" && screens.length > 0 && !(leaving && !settled) && /* @__PURE__ */ jsx("ol", { className: "pollar-ramp-stepper", "aria-label": copy.progress, children: [...screens, null].map((screen, i) => {
|
|
6713
|
+
const state = i < currentScreen || completed && i === screens.length ? "done" : screen?.status === "failed" ? "failed" : i === currentScreen ? "current" : "upcoming";
|
|
6714
|
+
const busy = state === "current" && !settled && !(screen?.kind === "action" && order?.pendingAction);
|
|
6715
|
+
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
6685
6716
|
"button",
|
|
6686
6717
|
{
|
|
6687
6718
|
type: "button",
|
|
6688
|
-
className: "pollar-ramp-
|
|
6689
|
-
"data-
|
|
6690
|
-
disabled: shownScreen === 0,
|
|
6691
|
-
onClick: () => setViewing(shownScreen - 1),
|
|
6692
|
-
"aria-label": copy.back,
|
|
6693
|
-
children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M10 3 5 8l5 5", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
6694
|
-
}
|
|
6695
|
-
),
|
|
6696
|
-
/* @__PURE__ */ jsx("ol", { className: "pollar-ramp-screens-bar", "aria-label": copy.progress, children: [...screens.map((s) => s.key), "final"].map((key, i) => /* @__PURE__ */ jsx(
|
|
6697
|
-
"li",
|
|
6698
|
-
{
|
|
6699
|
-
"data-done": i < currentScreen || completed && i === screens.length || void 0,
|
|
6719
|
+
className: "pollar-ramp-stepper-step",
|
|
6720
|
+
"data-state": state,
|
|
6700
6721
|
"data-shown": i === shownScreen || void 0,
|
|
6701
|
-
"
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6722
|
+
"aria-current": i === shownScreen ? "step" : void 0,
|
|
6723
|
+
"aria-label": copy.screens.stepLabel(i + 1, screens.length + 1, screen?.title ?? copy.screens.finalStep),
|
|
6724
|
+
disabled: i > currentScreen,
|
|
6725
|
+
onClick: () => setViewing(i >= currentScreen ? null : i),
|
|
6726
|
+
children: state === "done" ? /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx(
|
|
6727
|
+
"path",
|
|
6728
|
+
{
|
|
6729
|
+
d: "M3 8.5 6.5 12 13 4.5",
|
|
6730
|
+
stroke: "currentColor",
|
|
6731
|
+
strokeWidth: "2.2",
|
|
6732
|
+
strokeLinecap: "round",
|
|
6733
|
+
strokeLinejoin: "round"
|
|
6734
|
+
}
|
|
6735
|
+
) }) : state === "failed" ? /* @__PURE__ */ jsx("svg", { width: "12", height: "12", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M3 3l10 10M13 3 3 13", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round" }) }) : busy ? /* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm", "aria-hidden": true }) : i + 1
|
|
6715
6736
|
}
|
|
6716
|
-
)
|
|
6717
|
-
|
|
6737
|
+
) }, screen?.key ?? "final");
|
|
6738
|
+
}) }),
|
|
6718
6739
|
step === "input" && pendingOrders.length > 0 && /* @__PURE__ */ jsxs("section", { className: "pollar-ramp-payment pollar-ramp-saved", "aria-label": copy.pendingAria, children: [
|
|
6719
6740
|
/* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: copy.pendingNote }),
|
|
6720
6741
|
pendingOrders.map((pending) => /* @__PURE__ */ jsx("div", { className: "pollar-ramp-saved-row", children: /* @__PURE__ */ jsx(
|
|
@@ -7041,7 +7062,6 @@ function RampWidgetTemplate({
|
|
|
7041
7062
|
/* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: arrivedText }),
|
|
7042
7063
|
finalNote && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: finalNote })
|
|
7043
7064
|
] }),
|
|
7044
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: onClose, children: copy.screens.finish }),
|
|
7045
7065
|
/* @__PURE__ */ jsx(TxReview, { data: { title: "", kind: "other", rows: orderRows }, language })
|
|
7046
7066
|
] }) : shownScreen < currentScreen ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7047
7067
|
/* @__PURE__ */ jsxs("div", { className: "pollar-ramp-done", children: [
|
|
@@ -7058,7 +7078,26 @@ function RampWidgetTemplate({
|
|
|
7058
7078
|
/* @__PURE__ */ jsx("h3", { className: "pollar-ramp-done-title", children: screens[shownScreen].title }),
|
|
7059
7079
|
/* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: doneText(screens[shownScreen]) })
|
|
7060
7080
|
] }),
|
|
7061
|
-
screenRows(screens[shownScreen]).length > 0 && /* @__PURE__ */ jsx(
|
|
7081
|
+
screenRows(screens[shownScreen]).length > 0 && /* @__PURE__ */ jsx(
|
|
7082
|
+
TxReview,
|
|
7083
|
+
{
|
|
7084
|
+
data: { title: "", kind: "other", rows: screenRows(screens[shownScreen]) },
|
|
7085
|
+
open: doneDetailsOpen,
|
|
7086
|
+
onToggle: () => setDoneDetailsOpen((open) => !open),
|
|
7087
|
+
language
|
|
7088
|
+
}
|
|
7089
|
+
),
|
|
7090
|
+
doneDetailsOpen && paidQr(screens[shownScreen]) && /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-paid-qr", children: [
|
|
7091
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-ramp-payment-label", children: copy.paymentQr }),
|
|
7092
|
+
paidQr(screens[shownScreen]).inlineSafe ? /* @__PURE__ */ jsx(
|
|
7093
|
+
"div",
|
|
7094
|
+
{
|
|
7095
|
+
className: "pollar-ramp-qr",
|
|
7096
|
+
"aria-label": copy.paymentQr,
|
|
7097
|
+
dangerouslySetInnerHTML: { __html: paidQr(screens[shownScreen]).data }
|
|
7098
|
+
}
|
|
7099
|
+
) : /* @__PURE__ */ jsx("img", { src: scannableImageSrc(paidQr(screens[shownScreen])), alt: copy.paymentQr })
|
|
7100
|
+
] })
|
|
7062
7101
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7063
7102
|
shown && /* @__PURE__ */ jsx("h3", { className: "pollar-ramp-screen-title", "data-status": shown.status, children: askedInstead ? view.title : shown.title }),
|
|
7064
7103
|
shown?.status === "failed" && shown.leg.failure && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-field-error", children: rampFailureReason(shown.leg.failure, language) }),
|
|
@@ -7080,6 +7119,7 @@ function RampWidgetTemplate({
|
|
|
7080
7119
|
] })
|
|
7081
7120
|
] }, s.kind)) }),
|
|
7082
7121
|
confirmation && /* @__PURE__ */ jsx(InlineConfirm, { confirmation, language, network }),
|
|
7122
|
+
cosignPrompt,
|
|
7083
7123
|
order.failure && /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-payment-field", children: [
|
|
7084
7124
|
/* @__PURE__ */ jsx("span", { className: "pollar-ramp-payment-label", children: copy.whatToDo }),
|
|
7085
7125
|
/* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: rampOrderResolutionText(order, language) }),
|
|
@@ -7178,7 +7218,7 @@ function RampWidgetTemplate({
|
|
|
7178
7218
|
] }) : copy.paid }),
|
|
7179
7219
|
!settled && view.canSign && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", disabled: signing, onClick: onSign, children: signing ? copy.waitingWallet : copy.authorize }),
|
|
7180
7220
|
!settled && view.action?.kind === "SIGNATURE" && !view.canSign && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: copy.preparingSignature }),
|
|
7181
|
-
!settled && view.canApprove && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: onApprove, children: copy.approveOnDevice }),
|
|
7221
|
+
!settled && view.canApprove && !cosignPrompt && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: onApprove, children: copy.approveOnDevice }),
|
|
7182
7222
|
!settled && view.link && /* @__PURE__ */ jsx(
|
|
7183
7223
|
"a",
|
|
7184
7224
|
{
|
|
@@ -7802,637 +7842,1226 @@ function ProviderRegistrationModal({
|
|
|
7802
7842
|
}
|
|
7803
7843
|
) });
|
|
7804
7844
|
}
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
const
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
if (known) return known;
|
|
7813
|
-
const message = error.body.message;
|
|
7814
|
-
if (typeof message === "string" && message && !/^[A-Z0-9_]+$/.test(message)) return message;
|
|
7815
|
-
}
|
|
7816
|
-
return fallback;
|
|
7817
|
-
}
|
|
7818
|
-
var DECIMAL = /^\d+(\.\d+)?$/;
|
|
7819
|
-
var QUOTE_DEBOUNCE_MS = 600;
|
|
7820
|
-
function seededSelection(routes, seed) {
|
|
7821
|
-
const countries = rampCountries(routes);
|
|
7822
|
-
const wanted = seed.country?.trim().toUpperCase();
|
|
7823
|
-
const country = wanted ? countries.find((c) => c.country === wanted) : countries[0];
|
|
7824
|
-
if (!country) return null;
|
|
7825
|
-
const fiat = country.fiats.find((f) => f.currency === seed.fiat?.trim().toUpperCase()) ?? null;
|
|
7826
|
-
const resolvedFiat = fiat ?? country.fiats[0];
|
|
7827
|
-
const asset = routes.find(
|
|
7828
|
-
(r) => r.fiat.country === country.country && resolvedFiat !== void 0 && fiatKey(r.fiat) === fiatKey(resolvedFiat) && r.asset.code.toUpperCase() === seed.asset?.trim().toUpperCase()
|
|
7829
|
-
)?.asset;
|
|
7830
|
-
const amount = seed.amount?.trim() ?? "";
|
|
7831
|
-
return {
|
|
7832
|
-
country: country.country,
|
|
7833
|
-
fiatChoice: fiat ? fiatKey(fiat) : "",
|
|
7834
|
-
assetChoice: asset ? assetKey3(asset) : "",
|
|
7835
|
-
amount: DECIMAL.test(amount) ? amount : ""
|
|
7836
|
-
};
|
|
7837
|
-
}
|
|
7838
|
-
async function signLegWithWallet(client, orderId, actionId, copy) {
|
|
7839
|
-
const lent = [];
|
|
7840
|
-
const lend = (chain, encoding, handler) => {
|
|
7845
|
+
function useCosign() {
|
|
7846
|
+
const { getClient, isAuthenticated } = usePollar();
|
|
7847
|
+
const [state, setState] = useState({ pending: [] });
|
|
7848
|
+
const [loaded, setLoaded] = useState(false);
|
|
7849
|
+
useEffect(() => getClient().onCosignStateChange(setState), [getClient]);
|
|
7850
|
+
const refresh = useCallback(async () => {
|
|
7851
|
+
if (!isAuthenticated) return;
|
|
7841
7852
|
try {
|
|
7842
|
-
|
|
7843
|
-
}
|
|
7853
|
+
await getClient().cosign.pending();
|
|
7854
|
+
} finally {
|
|
7855
|
+
setLoaded(true);
|
|
7844
7856
|
}
|
|
7857
|
+
}, [getClient, isAuthenticated]);
|
|
7858
|
+
useEffect(() => {
|
|
7859
|
+
void refresh();
|
|
7860
|
+
}, [refresh]);
|
|
7861
|
+
return {
|
|
7862
|
+
pending: state.pending,
|
|
7863
|
+
...state.lastResolved ? { lastResolved: state.lastResolved } : {},
|
|
7864
|
+
loaded,
|
|
7865
|
+
refresh,
|
|
7866
|
+
approve: useCallback((request) => getClient().cosign.approve(request), [getClient]),
|
|
7867
|
+
reject: useCallback((request) => getClient().cosign.reject(request), [getClient]),
|
|
7868
|
+
verify: useCallback((request) => getClient().cosign.verify(request), [getClient]),
|
|
7869
|
+
inspectQuorum: useCallback(() => getClient().cosign.inspectQuorum(), [getClient]),
|
|
7870
|
+
devices: useCallback(() => getClient().cosign.devices(), [getClient]),
|
|
7871
|
+
revokeDevice: useCallback(
|
|
7872
|
+
(deviceId, options) => getClient().cosign.revokeDevice(deviceId, options),
|
|
7873
|
+
[getClient]
|
|
7874
|
+
),
|
|
7875
|
+
switchCustody: useCallback((to) => getClient().cosign.switchCustody(to), [getClient])
|
|
7845
7876
|
};
|
|
7846
|
-
lend("STELLAR", "xdr", async (action) => {
|
|
7847
|
-
const wallet = client.getWallet();
|
|
7848
|
-
if (!wallet) throw new Error(copy.connectStellarWallet);
|
|
7849
|
-
assertRampStellarSigner(action, wallet.address);
|
|
7850
|
-
const outcome = await client.signTx(action.payload.value);
|
|
7851
|
-
if (client.getWallet()?.address !== wallet.address) throw new Error(copy.walletChanged);
|
|
7852
|
-
if (outcome.status === "signed") return outcome.signedXdr;
|
|
7853
|
-
throw new Error(
|
|
7854
|
-
outcome.status === "error" ? outcome.message ?? outcome.details ?? copy.signingCancelled : copy.signingCancelled
|
|
7855
|
-
);
|
|
7856
|
-
});
|
|
7857
|
-
lend("SOLANA", "solana-v0-json", async (action) => {
|
|
7858
|
-
const payload = JSON.parse(action.payload.value);
|
|
7859
|
-
const solanaWallet = () => client.getWallets().find((w) => w.chain === "SOLANA" && w.custody === "external");
|
|
7860
|
-
const wallet = solanaWallet();
|
|
7861
|
-
if (!wallet || payload.from !== wallet.address || !payload.unsignedTransaction) throw new Error(copy.solanaWalletMismatch);
|
|
7862
|
-
const signed = await client.signSolanaTransaction(payload.unsignedTransaction);
|
|
7863
|
-
if (solanaWallet()?.address !== wallet.address) throw new Error(copy.walletChanged);
|
|
7864
|
-
return signed;
|
|
7865
|
-
});
|
|
7866
|
-
try {
|
|
7867
|
-
return await client.signRampLeg(orderId, actionId);
|
|
7868
|
-
} finally {
|
|
7869
|
-
for (const release of lent) release();
|
|
7870
|
-
}
|
|
7871
7877
|
}
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
const verifyAttempt = useRef(null);
|
|
7928
|
-
const countries = useMemo(() => rampCountries(routes), [routes]);
|
|
7929
|
-
const fiats = countries.find((c) => c.country === country)?.fiats ?? [];
|
|
7930
|
-
const fiat = fiats.find((f) => fiatKey(f) === fiatChoice) ?? fiats[0] ?? null;
|
|
7931
|
-
const assets = useMemo(() => {
|
|
7932
|
-
const seen = /* @__PURE__ */ new Map();
|
|
7933
|
-
for (const route of routes)
|
|
7934
|
-
if (fiat && route.fiat.country === country && fiatKey(route.fiat) === fiatKey(fiat))
|
|
7935
|
-
seen.set(assetKey3(route.asset), route.asset);
|
|
7936
|
-
return [...seen.values()];
|
|
7937
|
-
}, [routes, country, fiat]);
|
|
7938
|
-
const asset = assets.find((a) => assetKey3(a) === assetChoice) ?? assets[0] ?? null;
|
|
7939
|
-
const fields = selected ? rampQuoteFields(selected, language) : [];
|
|
7940
|
-
const sellAvailable = useWalletAvailable(
|
|
7941
|
-
direction === "OFFRAMP" && asset ? { chain: asset.chain, code: asset.code, issuer: asset.identifier } : null
|
|
7942
|
-
);
|
|
7943
|
-
const [quoting, setQuoting] = useState(false);
|
|
7944
|
-
const [routeChoice, setRouteChoice] = useState(BEST_ROUTE);
|
|
7945
|
-
const quoteRun = useRef(0);
|
|
7946
|
-
const quoteInput = step === "input" && fiat && asset && DECIMAL.test(amount.trim()) && Number(amount) > 0;
|
|
7947
|
-
const quoteKey = quoteInput ? `${direction}|${fiatKey(fiat)}|${assetKey3(asset)}|${amount.trim()}` : null;
|
|
7948
|
-
useEffect(() => {
|
|
7949
|
-
const run = ++quoteRun.current;
|
|
7950
|
-
if (!quoteKey || !fiat || !asset) {
|
|
7951
|
-
setQuoting(false);
|
|
7952
|
-
if (step === "input") {
|
|
7953
|
-
setQuotes([]);
|
|
7954
|
-
setRejected([]);
|
|
7955
|
-
}
|
|
7956
|
-
return;
|
|
7957
|
-
}
|
|
7958
|
-
setQuoting(true);
|
|
7959
|
-
const timer = setTimeout(() => {
|
|
7960
|
-
client.quoteRamp({
|
|
7961
|
-
direction,
|
|
7962
|
-
fiat: { currency: fiat.currency, rail: fiat.rail, country: fiat.country },
|
|
7963
|
-
asset: { code: asset.code, identifier: asset.identifier, chain: asset.chain },
|
|
7964
|
-
amount: { value: amount.trim(), denomination: "in" }
|
|
7965
|
-
}).then((result) => {
|
|
7966
|
-
if (run !== quoteRun.current) return;
|
|
7967
|
-
setQuotes(result.quotes);
|
|
7968
|
-
setRejected(result.rejected);
|
|
7969
|
-
setErrorMsg(null);
|
|
7970
|
-
}).catch((error) => {
|
|
7971
|
-
if (run !== quoteRun.current) return;
|
|
7972
|
-
setQuotes([]);
|
|
7973
|
-
if (isPollarApiError(error) && error.code === "SDK_RAMPS_NO_ROUTE") {
|
|
7974
|
-
setRejected(Array.isArray(error.body.rejected) ? error.body.rejected : []);
|
|
7975
|
-
} else {
|
|
7976
|
-
setRejected([]);
|
|
7977
|
-
setErrorMsg(rampErrorMessage(error, copy.findRouteFailed, copy, language));
|
|
7978
|
-
}
|
|
7979
|
-
}).finally(() => {
|
|
7980
|
-
if (run === quoteRun.current) setQuoting(false);
|
|
7981
|
-
});
|
|
7982
|
-
}, QUOTE_DEBOUNCE_MS);
|
|
7983
|
-
return () => clearTimeout(timer);
|
|
7984
|
-
}, [quoteKey]);
|
|
7985
|
-
const chosenQuote = (routeChoice !== BEST_ROUTE ? quotes.find((q) => routeKey(q) === routeChoice) : void 0) ?? quotes[0] ?? null;
|
|
7986
|
-
useEffect(() => {
|
|
7987
|
-
if (direction === "OFFRAMP") void refreshWalletBalance();
|
|
7988
|
-
}, [direction, refreshWalletBalance]);
|
|
7989
|
-
async function loadRoutes(next) {
|
|
7990
|
-
setRoutesLoading(true);
|
|
7991
|
-
try {
|
|
7992
|
-
const { routes: found } = await client.getRampRoutes(next);
|
|
7993
|
-
setRoutes(found);
|
|
7994
|
-
const seed = seedRef.current?.direction === next ? seedRef.current.options : null;
|
|
7995
|
-
if (seed) seedRef.current = null;
|
|
7996
|
-
const seeded = seed ? seededSelection(found, seed) : null;
|
|
7997
|
-
if (seeded) {
|
|
7998
|
-
setCountry(seeded.country);
|
|
7999
|
-
setFiatChoice(seeded.fiatChoice);
|
|
8000
|
-
setAssetChoice(seeded.assetChoice);
|
|
8001
|
-
setAmount(seeded.amount);
|
|
8002
|
-
return;
|
|
8003
|
-
}
|
|
8004
|
-
const first = rampCountries(found)[0]?.country ?? "";
|
|
8005
|
-
setCountry((current) => found.some((r) => r.fiat.country === current) ? current : first);
|
|
8006
|
-
} catch (error) {
|
|
8007
|
-
setRoutes([]);
|
|
8008
|
-
setErrorMsg(rampErrorMessage(error, copy.loadRoutesFailed, copy, language));
|
|
8009
|
-
} finally {
|
|
8010
|
-
setRoutesLoading(false);
|
|
8011
|
-
}
|
|
8012
|
-
}
|
|
8013
|
-
async function loadPendingOrders() {
|
|
8014
|
-
try {
|
|
8015
|
-
const page = await client.listRampOrders({ open: "true", limit: 5 });
|
|
8016
|
-
setPendingOrders(page.orders);
|
|
8017
|
-
} catch {
|
|
8018
|
-
setPendingOrders([]);
|
|
7878
|
+
|
|
7879
|
+
// src/components/cosign-modal/cosign-copy.ts
|
|
7880
|
+
var COSIGN_COPY = {
|
|
7881
|
+
en: {
|
|
7882
|
+
title: "Approvals",
|
|
7883
|
+
manyPending: (count) => `${count} approvals waiting`,
|
|
7884
|
+
close: "Close",
|
|
7885
|
+
whyTitle: "Why am I seeing this?",
|
|
7886
|
+
whyBody: "Your wallet needs this device's signature. Neither the app nor Pollar can approve this without you.",
|
|
7887
|
+
rejectRequest: "Reject this request",
|
|
7888
|
+
closeTitle: "Close without signing?",
|
|
7889
|
+
closeBody: "The request stays pending. The app can't continue until you approve it.",
|
|
7890
|
+
backToSign: "Go back and sign",
|
|
7891
|
+
closeAnyway: "Close anyway",
|
|
7892
|
+
activateWallet: "Activate wallet",
|
|
7893
|
+
status: { APPROVED: "Approved", REJECTED: "Rejected", EXPIRED: "Expired", FAILED: "Failed", PENDING: "Pending" },
|
|
7894
|
+
signedAppSends: "Signed. The app will send it.",
|
|
7895
|
+
signedSent: "Signed and sent",
|
|
7896
|
+
signed: "Signed",
|
|
7897
|
+
nothingSigned: "Nothing was signed.",
|
|
7898
|
+
nothingWaiting: "Nothing waits for your approval.",
|
|
7899
|
+
next: (step) => `Next: ${step}. It appears here in a few seconds.`,
|
|
7900
|
+
closingIn: (seconds) => `Closing in ${seconds}s`,
|
|
7901
|
+
expired: "expired",
|
|
7902
|
+
expiresIn: "Expires in",
|
|
7903
|
+
checking: "Checking...",
|
|
7904
|
+
verified: "Checked",
|
|
7905
|
+
checkedExact: "We checked this is exactly what you're approving.",
|
|
7906
|
+
notVerified: "Not verified:",
|
|
7907
|
+
reject: "Reject",
|
|
7908
|
+
rejecting: "Rejecting...",
|
|
7909
|
+
approve: "Approve",
|
|
7910
|
+
approving: "Approving...",
|
|
7911
|
+
genericError: "Something went wrong. Please try again.",
|
|
7912
|
+
unreachable: "We could not reach Pollar, so nothing was approved. Check your connection and approve again.",
|
|
7913
|
+
deviceNotLinked: "This device isn't linked to your wallet yet, so it can't approve. Add it with a device that already is, your passkey or your email.",
|
|
7914
|
+
linkDevice: "Link this device",
|
|
7915
|
+
transaction: "Transaction",
|
|
7916
|
+
operations: {
|
|
7917
|
+
payment: "Send",
|
|
7918
|
+
path_payment_strict_send: "Swap",
|
|
7919
|
+
change_trust: "Add asset",
|
|
7920
|
+
create_account: "Create account",
|
|
7921
|
+
invoke_contract: "Contract call",
|
|
7922
|
+
soroban_auth: "Authorize a contract call",
|
|
7923
|
+
manage_data: "Manage data",
|
|
7924
|
+
transfer: "Send",
|
|
7925
|
+
ramp_payment: "Ramp payment",
|
|
7926
|
+
cctp_burn: "Move USDC",
|
|
7927
|
+
swap: "Swap",
|
|
7928
|
+
earn_deposit: "Deposit",
|
|
7929
|
+
earn_withdraw: "Withdraw",
|
|
7930
|
+
evm_delegation: "Enable atomic transactions",
|
|
7931
|
+
provider_sign_in: "Confirm it's you",
|
|
7932
|
+
sep10: "Confirm it's you"
|
|
8019
7933
|
}
|
|
8020
|
-
}
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
}
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
7934
|
+
},
|
|
7935
|
+
es: {
|
|
7936
|
+
title: "Aprobaciones",
|
|
7937
|
+
manyPending: (count) => `${count} aprobaciones pendientes`,
|
|
7938
|
+
close: "Cerrar",
|
|
7939
|
+
whyTitle: "\xBFPor qu\xE9 ves esto?",
|
|
7940
|
+
whyBody: "Tu billetera necesita la firma de este dispositivo. Ni la app ni Pollar pueden aprobar esto sin ti.",
|
|
7941
|
+
rejectRequest: "Rechazar esta solicitud",
|
|
7942
|
+
closeTitle: "\xBFCerrar sin firmar?",
|
|
7943
|
+
closeBody: "La solicitud queda pendiente. La app no puede seguir hasta que la apruebes.",
|
|
7944
|
+
backToSign: "Volver y firmar",
|
|
7945
|
+
closeAnyway: "Cerrar igual",
|
|
7946
|
+
activateWallet: "Activar billetera",
|
|
7947
|
+
status: { APPROVED: "Aprobada", REJECTED: "Rechazada", EXPIRED: "Vencida", FAILED: "Fallida", PENDING: "Pendiente" },
|
|
7948
|
+
signedAppSends: "Firmada. La app la enviar\xE1.",
|
|
7949
|
+
signedSent: "Firmada y enviada",
|
|
7950
|
+
signed: "Firmada",
|
|
7951
|
+
nothingSigned: "No se firm\xF3 nada.",
|
|
7952
|
+
nothingWaiting: "No hay nada esperando tu aprobaci\xF3n.",
|
|
7953
|
+
next: (step) => `Siguiente: ${step}. Aparecer\xE1 aqu\xED en unos segundos.`,
|
|
7954
|
+
closingIn: (seconds) => `Se cierra en ${seconds}s`,
|
|
7955
|
+
expired: "vencida",
|
|
7956
|
+
expiresIn: "Vence en",
|
|
7957
|
+
checking: "Verificando...",
|
|
7958
|
+
verified: "Comprobada",
|
|
7959
|
+
checkedExact: "Comprobamos que esto es exactamente lo que est\xE1s aprobando.",
|
|
7960
|
+
notVerified: "Sin verificar:",
|
|
7961
|
+
reject: "Rechazar",
|
|
7962
|
+
rejecting: "Rechazando...",
|
|
7963
|
+
approve: "Aprobar",
|
|
7964
|
+
approving: "Aprobando...",
|
|
7965
|
+
genericError: "Algo sali\xF3 mal. Intenta de nuevo.",
|
|
7966
|
+
unreachable: "No pudimos conectar con Pollar, as\xED que no se aprob\xF3 nada. Revisa tu conexi\xF3n y aprueba de nuevo.",
|
|
7967
|
+
deviceNotLinked: "Este dispositivo a\xFAn no est\xE1 vinculado a tu billetera, as\xED que no puede aprobar. Agr\xE9galo con un dispositivo que ya lo est\xE9, tu passkey o tu email.",
|
|
7968
|
+
linkDevice: "Vincular este dispositivo",
|
|
7969
|
+
transaction: "Transacci\xF3n",
|
|
7970
|
+
operations: {
|
|
7971
|
+
payment: "Enviar",
|
|
7972
|
+
path_payment_strict_send: "Intercambiar",
|
|
7973
|
+
change_trust: "Agregar activo",
|
|
7974
|
+
create_account: "Crear cuenta",
|
|
7975
|
+
invoke_contract: "Llamada a contrato",
|
|
7976
|
+
soroban_auth: "Autorizar una llamada a contrato",
|
|
7977
|
+
manage_data: "Gestionar datos",
|
|
7978
|
+
transfer: "Enviar",
|
|
7979
|
+
ramp_payment: "Pago de rampa",
|
|
7980
|
+
cctp_burn: "Mover USDC",
|
|
7981
|
+
swap: "Intercambiar",
|
|
7982
|
+
earn_deposit: "Depositar",
|
|
7983
|
+
earn_withdraw: "Retirar",
|
|
7984
|
+
evm_delegation: "Activar transacciones at\xF3micas",
|
|
7985
|
+
provider_sign_in: "Confirma que eres t\xFA",
|
|
7986
|
+
sep10: "Confirma que eres t\xFA"
|
|
8050
7987
|
}
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
|
|
8065
|
-
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
7988
|
+
},
|
|
7989
|
+
pt: {
|
|
7990
|
+
title: "Aprova\xE7\xF5es",
|
|
7991
|
+
manyPending: (count) => `${count} aprova\xE7\xF5es pendentes`,
|
|
7992
|
+
close: "Fechar",
|
|
7993
|
+
whyTitle: "Por que estou vendo isto?",
|
|
7994
|
+
whyBody: "Sua carteira precisa da assinatura deste dispositivo. Nem o app nem a Pollar podem aprovar isto sem voc\xEA.",
|
|
7995
|
+
rejectRequest: "Rejeitar esta solicita\xE7\xE3o",
|
|
7996
|
+
closeTitle: "Fechar sem assinar?",
|
|
7997
|
+
closeBody: "A solicita\xE7\xE3o fica pendente. O app n\xE3o pode continuar at\xE9 voc\xEA aprov\xE1-la.",
|
|
7998
|
+
backToSign: "Voltar e assinar",
|
|
7999
|
+
closeAnyway: "Fechar mesmo assim",
|
|
8000
|
+
activateWallet: "Ativar carteira",
|
|
8001
|
+
status: { APPROVED: "Aprovada", REJECTED: "Rejeitada", EXPIRED: "Expirada", FAILED: "Falhou", PENDING: "Pendente" },
|
|
8002
|
+
signedAppSends: "Assinada. O app vai envi\xE1-la.",
|
|
8003
|
+
signedSent: "Assinada e enviada",
|
|
8004
|
+
signed: "Assinada",
|
|
8005
|
+
nothingSigned: "Nada foi assinado.",
|
|
8006
|
+
nothingWaiting: "Nada aguarda a sua aprova\xE7\xE3o.",
|
|
8007
|
+
next: (step) => `Pr\xF3ximo: ${step}. Aparece aqui em alguns segundos.`,
|
|
8008
|
+
closingIn: (seconds) => `Fechando em ${seconds}s`,
|
|
8009
|
+
expired: "expirada",
|
|
8010
|
+
expiresIn: "Expira em",
|
|
8011
|
+
checking: "Verificando...",
|
|
8012
|
+
verified: "Conferida",
|
|
8013
|
+
checkedExact: "Conferimos que isto \xE9 exatamente o que voc\xEA est\xE1 aprovando.",
|
|
8014
|
+
notVerified: "N\xE3o verificada:",
|
|
8015
|
+
reject: "Rejeitar",
|
|
8016
|
+
rejecting: "Rejeitando...",
|
|
8017
|
+
approve: "Aprovar",
|
|
8018
|
+
approving: "Aprovando...",
|
|
8019
|
+
genericError: "Algo deu errado. Tente novamente.",
|
|
8020
|
+
unreachable: "N\xE3o conseguimos conectar \xE0 Pollar, ent\xE3o nada foi aprovado. Verifique sua conex\xE3o e aprove novamente.",
|
|
8021
|
+
deviceNotLinked: "Este dispositivo ainda n\xE3o est\xE1 vinculado \xE0 sua carteira, ent\xE3o n\xE3o pode aprovar. Adicione-o com um dispositivo que j\xE1 esteja, sua passkey ou seu email.",
|
|
8022
|
+
linkDevice: "Vincular este dispositivo",
|
|
8023
|
+
transaction: "Transa\xE7\xE3o",
|
|
8024
|
+
operations: {
|
|
8025
|
+
payment: "Enviar",
|
|
8026
|
+
path_payment_strict_send: "Trocar",
|
|
8027
|
+
change_trust: "Adicionar ativo",
|
|
8028
|
+
create_account: "Criar conta",
|
|
8029
|
+
invoke_contract: "Chamada de contrato",
|
|
8030
|
+
soroban_auth: "Autorizar uma chamada de contrato",
|
|
8031
|
+
manage_data: "Gerenciar dados",
|
|
8032
|
+
transfer: "Enviar",
|
|
8033
|
+
ramp_payment: "Pagamento de rampa",
|
|
8034
|
+
cctp_burn: "Mover USDC",
|
|
8035
|
+
swap: "Trocar",
|
|
8036
|
+
earn_deposit: "Depositar",
|
|
8037
|
+
earn_withdraw: "Sacar",
|
|
8038
|
+
evm_delegation: "Ativar transa\xE7\xF5es at\xF4micas",
|
|
8039
|
+
provider_sign_in: "Confirme que \xE9 voc\xEA",
|
|
8040
|
+
sep10: "Confirme que \xE9 voc\xEA"
|
|
8089
8041
|
}
|
|
8090
|
-
void resumeRoute(awaitingAccount.routeKey);
|
|
8091
|
-
}, [awaitingAccount, resolvedRequest]);
|
|
8092
|
-
function handleDirectionChange(next) {
|
|
8093
|
-
seedRef.current = null;
|
|
8094
|
-
setDirection(next);
|
|
8095
|
-
setErrorMsg(null);
|
|
8096
|
-
setAwaitingAccount(null);
|
|
8097
8042
|
}
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8043
|
+
};
|
|
8044
|
+
function labelOf2(request, copy) {
|
|
8045
|
+
const op = request.operation ?? "";
|
|
8046
|
+
return copy.operations[op] ?? (op ? op.replace(/_/g, " ") : copy.transaction);
|
|
8047
|
+
}
|
|
8048
|
+
function expiresIn(request, copy) {
|
|
8049
|
+
const ms = new Date(request.expiresAt).getTime() - Date.now();
|
|
8050
|
+
if (!Number.isFinite(ms) || ms <= 0) return copy.expired;
|
|
8051
|
+
const h = Math.floor(ms / 36e5);
|
|
8052
|
+
const m = Math.floor(ms % 36e5 / 6e4);
|
|
8053
|
+
return h > 0 ? `${h}h ${m}m` : `${m}m`;
|
|
8054
|
+
}
|
|
8055
|
+
function outcomeText(request, copy) {
|
|
8056
|
+
if (request.status !== "APPROVED")
|
|
8057
|
+
return `${copy.status[request.status] ?? request.status.toLowerCase()}. ${copy.nothingSigned}`;
|
|
8058
|
+
if (request.submit?.hash) return copy.signedSent;
|
|
8059
|
+
if (request.signedXdr) return copy.signedAppSends;
|
|
8060
|
+
return copy.status.APPROVED ?? "Approved";
|
|
8061
|
+
}
|
|
8062
|
+
function StepRow({
|
|
8063
|
+
request,
|
|
8064
|
+
review,
|
|
8065
|
+
copy,
|
|
8066
|
+
language
|
|
8067
|
+
}) {
|
|
8068
|
+
const [open, setOpen] = useState(false);
|
|
8069
|
+
const ok = request.status === "APPROVED";
|
|
8070
|
+
return /* @__PURE__ */ jsxs("div", { className: `pollar-cosign-step${ok ? "" : " pollar-cosign-step-bad"}`, children: [
|
|
8071
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "pollar-cosign-step-head", "aria-expanded": open, onClick: () => setOpen((v) => !v), children: [
|
|
8072
|
+
/* @__PURE__ */ jsx(OutcomeIcon, { ok }),
|
|
8073
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-cosign-step-title", children: review.title }),
|
|
8074
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-cosign-step-status", children: ok ? copy.signed : copy.status[request.status] ?? request.status }),
|
|
8075
|
+
/* @__PURE__ */ jsx(
|
|
8076
|
+
"svg",
|
|
8077
|
+
{
|
|
8078
|
+
width: "10",
|
|
8079
|
+
height: "10",
|
|
8080
|
+
viewBox: "0 0 12 12",
|
|
8081
|
+
fill: "none",
|
|
8082
|
+
"aria-hidden": true,
|
|
8083
|
+
style: { transform: open ? "rotate(180deg)" : "none", transition: "transform 150ms" },
|
|
8084
|
+
children: /* @__PURE__ */ jsx("path", { d: "M2 4l4 4 4-4", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" })
|
|
8085
|
+
}
|
|
8086
|
+
)
|
|
8087
|
+
] }),
|
|
8088
|
+
open && /* @__PURE__ */ jsx(TxReview, { data: review, language, detailsOnly: true })
|
|
8089
|
+
] });
|
|
8090
|
+
}
|
|
8091
|
+
function CloseIcon() {
|
|
8092
|
+
return /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "m3 3 8 8M11 3l-8 8", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round" }) });
|
|
8093
|
+
}
|
|
8094
|
+
function VerifiedIcon() {
|
|
8095
|
+
return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: [
|
|
8096
|
+
/* @__PURE__ */ jsx("circle", { cx: "7", cy: "7", r: "7", fill: "currentColor" }),
|
|
8097
|
+
/* @__PURE__ */ jsx("path", { d: "M3.5 7l2.5 2.5 4.5-5", stroke: "white", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round" })
|
|
8098
|
+
] });
|
|
8099
|
+
}
|
|
8100
|
+
function CosignModalTemplate({
|
|
8101
|
+
theme,
|
|
8102
|
+
accentColor,
|
|
8103
|
+
styleOverrides,
|
|
8104
|
+
pending,
|
|
8105
|
+
current,
|
|
8106
|
+
verification,
|
|
8107
|
+
busy,
|
|
8108
|
+
error,
|
|
8109
|
+
approveBlocked = false,
|
|
8110
|
+
deviceNotLinked = false,
|
|
8111
|
+
onLinkDevice,
|
|
8112
|
+
lastResolved,
|
|
8113
|
+
history = [],
|
|
8114
|
+
explorerUrlOf,
|
|
8115
|
+
closesIn = null,
|
|
8116
|
+
nextStep = null,
|
|
8117
|
+
language: languageProp,
|
|
8118
|
+
network,
|
|
8119
|
+
onSelect,
|
|
8120
|
+
onApprove,
|
|
8121
|
+
onReject,
|
|
8122
|
+
onClose,
|
|
8123
|
+
confirmingClose = false,
|
|
8124
|
+
onKeepOpen,
|
|
8125
|
+
onCloseAnyway,
|
|
8126
|
+
inline = false
|
|
8127
|
+
}) {
|
|
8128
|
+
const language = useInheritedLanguage(languageProp);
|
|
8129
|
+
const copy = COSIGN_COPY[language];
|
|
8130
|
+
const cssVars = buildModalCssVars(theme, accentColor, styleOverrides);
|
|
8131
|
+
const verified = verification?.ok === true && !deviceNotLinked;
|
|
8132
|
+
const canVote = !!current && verified && !busy && !approveBlocked;
|
|
8133
|
+
const [verifiedOpenFor, setVerifiedOpenFor] = useState(null);
|
|
8134
|
+
const verifiedOpen = !!current && verifiedOpenFor === current.id;
|
|
8135
|
+
const reviewOf = (request) => reviewFromRequest(
|
|
8136
|
+
{
|
|
8137
|
+
chain: request.network,
|
|
8138
|
+
network,
|
|
8139
|
+
operation: request.operation,
|
|
8140
|
+
summary: request.summary,
|
|
8141
|
+
details: request.details,
|
|
8142
|
+
signWith: request.account ?? request.signWith,
|
|
8143
|
+
raw: request.unsignedPayload,
|
|
8144
|
+
fallbackTitle: labelOf2(request, copy),
|
|
8145
|
+
...request.status === "PENDING" ? { extraRows: [{ label: copy.expiresIn, value: expiresIn(request, copy) }] } : {},
|
|
8146
|
+
appPaysFee: request.submit?.sponsored ?? request.appPaysFee,
|
|
8147
|
+
...request.submit?.hash ? { hash: { value: request.submit.hash, explorerUrl: explorerUrlOf?.(request) ?? null } } : {}
|
|
8148
|
+
},
|
|
8149
|
+
TX_REVIEW_COPY[language]
|
|
8150
|
+
);
|
|
8151
|
+
const review = current ? reviewOf(current) : null;
|
|
8152
|
+
const grouped = pending.length > 1;
|
|
8153
|
+
const shown = grouped ? null : current ?? (pending.length === 0 ? lastResolved : void 0) ?? null;
|
|
8154
|
+
const shownReview = shown ? shown === current ? review : reviewOf(shown) : null;
|
|
8155
|
+
const doneSteps = history.filter((r) => !(pending.length === 0 && r.id === lastResolved?.id));
|
|
8156
|
+
const heading = confirmingClose ? copy.closeTitle : grouped ? copy.manyPending(pending.length) : shownReview?.title ?? copy.title;
|
|
8157
|
+
const chip = current && !confirmingClose && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
8158
|
+
!verification && !deviceNotLinked && /* @__PURE__ */ jsxs("span", { className: "pollar-cosign-chip", children: [
|
|
8159
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm", "aria-hidden": true }),
|
|
8160
|
+
copy.checking
|
|
8161
|
+
] }),
|
|
8162
|
+
verified && /* @__PURE__ */ jsxs(
|
|
8163
|
+
"button",
|
|
8164
|
+
{
|
|
8165
|
+
type: "button",
|
|
8166
|
+
className: "pollar-cosign-chip pollar-cosign-chip-ok",
|
|
8167
|
+
"aria-expanded": verifiedOpen,
|
|
8168
|
+
onClick: () => setVerifiedOpenFor(verifiedOpen ? null : current.id),
|
|
8169
|
+
children: [
|
|
8170
|
+
/* @__PURE__ */ jsx(VerifiedIcon, {}),
|
|
8171
|
+
copy.verified
|
|
8172
|
+
]
|
|
8124
8173
|
}
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8174
|
+
)
|
|
8175
|
+
] });
|
|
8176
|
+
return /* @__PURE__ */ jsxs(
|
|
8177
|
+
"div",
|
|
8178
|
+
{
|
|
8179
|
+
className: inline ? "pollar-cosign-modal pollar-cosign-inline" : "pollar-modal-card pollar-cosign-modal",
|
|
8180
|
+
"data-theme": theme,
|
|
8181
|
+
style: cssVars,
|
|
8182
|
+
onClick: (e) => e.stopPropagation(),
|
|
8183
|
+
children: [
|
|
8184
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header", children: [
|
|
8185
|
+
/* @__PURE__ */ jsxs("h2", { className: "pollar-modal-title pollar-cosign-heading", children: [
|
|
8186
|
+
!confirmingClose && /* @__PURE__ */ jsx(TitleMark, { chain: shown?.network, asset: shownReview ? headlineAsset(shownReview) : void 0 }),
|
|
8187
|
+
/* @__PURE__ */ jsx("span", { children: heading })
|
|
8188
|
+
] }),
|
|
8189
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header-actions", children: [
|
|
8190
|
+
!grouped && chip,
|
|
8191
|
+
!confirmingClose && !inline && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-modal-close", onClick: onClose, "aria-label": copy.close, title: copy.close, children: /* @__PURE__ */ jsx(CloseIcon, {}) })
|
|
8192
|
+
] })
|
|
8193
|
+
] }),
|
|
8194
|
+
confirmingClose ? /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-leave", children: [
|
|
8195
|
+
/* @__PURE__ */ jsx("p", { className: "pollar-cosign-muted", children: copy.closeBody }),
|
|
8196
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-cosign-btn pollar-cosign-btn-primary", onClick: onKeepOpen, children: copy.backToSign }),
|
|
8197
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-cosign-text-btn", onClick: onCloseAnyway, children: copy.closeAnyway })
|
|
8198
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
8199
|
+
doneSteps.map((r) => /* @__PURE__ */ jsx(StepRow, { request: r, review: reviewOf(r), copy, language }, r.id)),
|
|
8200
|
+
pending.length === 0 && (lastResolved && shownReview ? /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-detail", children: [
|
|
8201
|
+
/* @__PURE__ */ jsx(TxReview, { data: shownReview, language }, lastResolved.id),
|
|
8202
|
+
/* @__PURE__ */ jsxs("div", { className: `pollar-outcome${lastResolved.status === "APPROVED" ? "" : " pollar-outcome-bad"}`, children: [
|
|
8203
|
+
/* @__PURE__ */ jsxs("p", { className: "pollar-outcome-main", children: [
|
|
8204
|
+
/* @__PURE__ */ jsx(OutcomeIcon, { ok: lastResolved.status === "APPROVED" }),
|
|
8205
|
+
outcomeText(lastResolved, copy)
|
|
8206
|
+
] }),
|
|
8207
|
+
nextStep && /* @__PURE__ */ jsxs("p", { className: "pollar-outcome-note", children: [
|
|
8208
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm", "aria-hidden": true }),
|
|
8209
|
+
" ",
|
|
8210
|
+
copy.next(nextStep)
|
|
8211
|
+
] }),
|
|
8212
|
+
closesIn !== null && /* @__PURE__ */ jsx("p", { className: "pollar-outcome-note", children: copy.closingIn(closesIn) })
|
|
8213
|
+
] })
|
|
8214
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-empty", children: [
|
|
8215
|
+
/* @__PURE__ */ jsx("p", { className: "pollar-cosign-muted", children: copy.nothingWaiting }),
|
|
8216
|
+
closesIn !== null && /* @__PURE__ */ jsx("p", { className: "pollar-cosign-muted pollar-cosign-closing", children: copy.closingIn(closesIn) })
|
|
8217
|
+
] })),
|
|
8218
|
+
grouped && /* @__PURE__ */ jsx("ul", { className: "pollar-cosign-list", children: pending.map((r) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
8219
|
+
"button",
|
|
8220
|
+
{
|
|
8221
|
+
type: "button",
|
|
8222
|
+
className: `pollar-cosign-item${current?.id === r.id ? " pollar-cosign-item-active" : ""}`,
|
|
8223
|
+
onClick: () => onSelect(r),
|
|
8224
|
+
children: [
|
|
8225
|
+
/* @__PURE__ */ jsxs("span", { className: "pollar-cosign-heading", children: [
|
|
8226
|
+
/* @__PURE__ */ jsx(TitleMark, { chain: r.network, asset: headlineAsset(reviewOf(r)) }),
|
|
8227
|
+
reviewOf(r).title
|
|
8228
|
+
] }),
|
|
8229
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-cosign-muted", children: expiresIn(r, copy) })
|
|
8230
|
+
]
|
|
8231
|
+
}
|
|
8232
|
+
) }, r.id)) }),
|
|
8233
|
+
current && review && /* @__PURE__ */ jsxs("div", { className: `pollar-cosign-detail${grouped ? " pollar-cosign-detail-grouped" : ""}`, children: [
|
|
8234
|
+
grouped && /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-detail-head", children: [
|
|
8235
|
+
/* @__PURE__ */ jsx("p", { className: "pollar-cosign-detail-title", children: review.title }),
|
|
8236
|
+
chip
|
|
8237
|
+
] }),
|
|
8238
|
+
/* @__PURE__ */ jsx(
|
|
8239
|
+
TxReview,
|
|
8240
|
+
{
|
|
8241
|
+
data: review,
|
|
8242
|
+
language,
|
|
8243
|
+
detailsIntro: { title: copy.whyTitle, body: copy.whyBody },
|
|
8244
|
+
detailsAction: {
|
|
8245
|
+
label: busy === "rejecting" ? copy.rejecting : copy.rejectRequest,
|
|
8246
|
+
onClick: () => onReject(current),
|
|
8247
|
+
disabled: !!busy
|
|
8248
|
+
}
|
|
8249
|
+
},
|
|
8250
|
+
current.id
|
|
8251
|
+
),
|
|
8252
|
+
verified && verifiedOpen && /* @__PURE__ */ jsx("div", { className: "pollar-cosign-verify pollar-cosign-verify-ok", children: copy.checkedExact }),
|
|
8253
|
+
deviceNotLinked ? /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-verify pollar-cosign-verify-bad", children: [
|
|
8254
|
+
copy.deviceNotLinked,
|
|
8255
|
+
onLinkDevice && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-cosign-link", onClick: onLinkDevice, children: copy.linkDevice })
|
|
8256
|
+
] }) : verification && !verification.ok && /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-verify pollar-cosign-verify-bad", children: [
|
|
8257
|
+
copy.notVerified,
|
|
8258
|
+
" ",
|
|
8259
|
+
verification.reason
|
|
8260
|
+
] }),
|
|
8261
|
+
error && /* @__PURE__ */ jsx("div", { className: "pollar-cosign-error", children: error }),
|
|
8262
|
+
/* @__PURE__ */ jsx(
|
|
8263
|
+
"button",
|
|
8264
|
+
{
|
|
8265
|
+
type: "button",
|
|
8266
|
+
className: "pollar-cosign-btn pollar-cosign-btn-primary",
|
|
8267
|
+
disabled: !canVote,
|
|
8268
|
+
onClick: () => onApprove(current),
|
|
8269
|
+
children: busy === "approving" ? copy.approving : review.kind === "activate_wallet" ? copy.activateWallet : copy.approve
|
|
8270
|
+
}
|
|
8271
|
+
)
|
|
8272
|
+
] })
|
|
8273
|
+
] }),
|
|
8274
|
+
!inline && /* @__PURE__ */ jsx(PollarModalFooter, {})
|
|
8275
|
+
]
|
|
8128
8276
|
}
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
if (
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
|
|
8277
|
+
);
|
|
8278
|
+
}
|
|
8279
|
+
var CLOSE_AFTER_SECONDS = 3;
|
|
8280
|
+
var CLOSE_AFTER_SENT_SECONDS = 5;
|
|
8281
|
+
var NEXT_REQUEST_EVERY_MS = 2e3;
|
|
8282
|
+
function CosignModal(props) {
|
|
8283
|
+
const { styles } = usePollar();
|
|
8284
|
+
const { overlayStyle } = modalChrome(styles);
|
|
8285
|
+
return /* @__PURE__ */ jsx(PollarOverlay, { style: overlayStyle, children: /* @__PURE__ */ jsx(CosignPrompt, { ...props }) });
|
|
8286
|
+
}
|
|
8287
|
+
function CosignPrompt({ nextStep = null, onClose, inline = false }) {
|
|
8288
|
+
const { getClient, styles, network, openRecoveryModal } = usePollar();
|
|
8289
|
+
const { theme, accentColor, styleOverrides } = modalChrome(styles);
|
|
8290
|
+
const { pending, lastResolved, loaded, refresh, approve, reject, verify, inspectQuorum } = useCosign();
|
|
8291
|
+
const language = useModalLanguage();
|
|
8292
|
+
const [selectedId, setSelectedId] = useState(null);
|
|
8293
|
+
const [verification, setVerification] = useState(null);
|
|
8294
|
+
const [busy, setBusy] = useState(null);
|
|
8295
|
+
const [error, setError] = useState(null);
|
|
8296
|
+
const [approveFailedFor, setApproveFailedFor] = useState(null);
|
|
8297
|
+
const [quorumFailure, setQuorumFailure] = useState(null);
|
|
8298
|
+
const [deviceNotLinked, setDeviceNotLinked] = useState(false);
|
|
8299
|
+
useEffect(() => {
|
|
8300
|
+
let cancelled = false;
|
|
8301
|
+
inspectQuorum().then((q) => {
|
|
8302
|
+
if (cancelled || q.ok) return;
|
|
8303
|
+
if (q.code === "DEVICE_NOT_ENROLLED") setDeviceNotLinked(true);
|
|
8304
|
+
else setQuorumFailure(q.reason);
|
|
8305
|
+
}).catch(() => void 0);
|
|
8306
|
+
return () => {
|
|
8307
|
+
cancelled = true;
|
|
8308
|
+
};
|
|
8309
|
+
}, [inspectQuorum]);
|
|
8310
|
+
const current = pending.find((r) => r.id === selectedId) ?? pending[0] ?? null;
|
|
8311
|
+
const [history, setHistory] = useState([]);
|
|
8312
|
+
const resolvedBeforeOpen = useRef(lastResolved?.id);
|
|
8313
|
+
useEffect(() => {
|
|
8314
|
+
if (!lastResolved || lastResolved.id === resolvedBeforeOpen.current) return;
|
|
8315
|
+
setHistory((list) => [...list.filter((r) => r.id !== lastResolved.id), lastResolved]);
|
|
8316
|
+
}, [lastResolved]);
|
|
8317
|
+
const [askedToClose, setAskedToClose] = useState(false);
|
|
8318
|
+
const confirmingClose = askedToClose && pending.length > 0;
|
|
8319
|
+
const requestClose = () => pending.length > 0 ? setAskedToClose(true) : onClose();
|
|
8320
|
+
const currentRef = useRef(current);
|
|
8321
|
+
currentRef.current = current;
|
|
8322
|
+
const currentId = current?.id ?? null;
|
|
8323
|
+
useEffect(() => {
|
|
8324
|
+
const request = currentRef.current;
|
|
8325
|
+
if (!request) return;
|
|
8326
|
+
setVerification(null);
|
|
8327
|
+
setError(null);
|
|
8328
|
+
setApproveFailedFor(null);
|
|
8329
|
+
let cancelled = false;
|
|
8330
|
+
verify(request).then((v) => {
|
|
8331
|
+
if (!cancelled) setVerification(v);
|
|
8332
|
+
}).catch((err) => {
|
|
8333
|
+
if (!cancelled) setVerification({ ok: false, reason: err instanceof Error ? err.message : String(err) });
|
|
8334
|
+
});
|
|
8335
|
+
return () => {
|
|
8336
|
+
cancelled = true;
|
|
8337
|
+
};
|
|
8338
|
+
}, [currentId, verify]);
|
|
8339
|
+
const onCloseRef = useRef(onClose);
|
|
8340
|
+
onCloseRef.current = onClose;
|
|
8341
|
+
useEffect(() => {
|
|
8342
|
+
return getClient().onAuthStateChange((authState) => {
|
|
8343
|
+
if (authState.step === "idle") onCloseRef.current();
|
|
8344
|
+
});
|
|
8345
|
+
}, [getClient]);
|
|
8346
|
+
const silent = pending.length === 0 && (lastResolved ? lastResolved.status === "APPROVED" && !lastResolved.submit?.hash && !lastResolved.signedXdr : loaded);
|
|
8347
|
+
const sent = pending.length === 0 && lastResolved?.status === "APPROVED" && !!lastResolved.submit?.hash;
|
|
8348
|
+
const awaitingNext = sent && !!nextStep;
|
|
8349
|
+
const closeAfter = awaitingNext ? null : sent ? CLOSE_AFTER_SENT_SECONDS : silent ? CLOSE_AFTER_SECONDS : null;
|
|
8350
|
+
useEffect(() => {
|
|
8351
|
+
if (!awaitingNext) return;
|
|
8352
|
+
return startBackoffPoll(refresh, NEXT_REQUEST_EVERY_MS);
|
|
8353
|
+
}, [awaitingNext, refresh]);
|
|
8354
|
+
const [closesIn, setClosesIn] = useState(null);
|
|
8355
|
+
useEffect(() => {
|
|
8356
|
+
if (closeAfter === null) {
|
|
8357
|
+
setClosesIn(null);
|
|
8358
|
+
return;
|
|
8166
8359
|
}
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
setErrorMsg(copy.addRecovery);
|
|
8176
|
-
openRecoveryModal();
|
|
8177
|
-
return;
|
|
8360
|
+
let left = closeAfter;
|
|
8361
|
+
setClosesIn(left);
|
|
8362
|
+
const timer = setInterval(() => {
|
|
8363
|
+
left -= 1;
|
|
8364
|
+
if (left > 0) setClosesIn(left);
|
|
8365
|
+
else {
|
|
8366
|
+
clearInterval(timer);
|
|
8367
|
+
onCloseRef.current();
|
|
8178
8368
|
}
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8369
|
+
}, 1e3);
|
|
8370
|
+
return () => clearInterval(timer);
|
|
8371
|
+
}, [closeAfter, lastResolved?.id]);
|
|
8372
|
+
const run = useCallback(
|
|
8373
|
+
async (kind, request, action) => {
|
|
8374
|
+
setBusy(kind);
|
|
8375
|
+
setError(null);
|
|
8376
|
+
try {
|
|
8377
|
+
await action(request);
|
|
8378
|
+
} catch (err) {
|
|
8379
|
+
if (isPollarNetworkError(err) || err instanceof TypeError) {
|
|
8380
|
+
setError(COSIGN_COPY[language].unreachable);
|
|
8381
|
+
void refresh().catch(() => void 0);
|
|
8382
|
+
return;
|
|
8383
|
+
}
|
|
8384
|
+
setError(
|
|
8385
|
+
transactionErrorMessage(isPollarApiError(err) ? err.code : null, err instanceof Error ? err.message : null, language)
|
|
8386
|
+
);
|
|
8387
|
+
const retryable = isTransientApiError(err) || isPollarApiError(err) && err.code === "SDK_COSIGN_GAS_PENDING";
|
|
8388
|
+
if (kind === "approving" && !retryable) setApproveFailedFor(request.id);
|
|
8389
|
+
} finally {
|
|
8390
|
+
setBusy(null);
|
|
8186
8391
|
}
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8392
|
+
},
|
|
8393
|
+
[language, refresh]
|
|
8394
|
+
);
|
|
8395
|
+
return /* @__PURE__ */ jsx(
|
|
8396
|
+
CosignModalTemplate,
|
|
8397
|
+
{
|
|
8398
|
+
inline,
|
|
8399
|
+
theme,
|
|
8400
|
+
accentColor,
|
|
8401
|
+
styleOverrides,
|
|
8402
|
+
pending,
|
|
8403
|
+
current,
|
|
8404
|
+
verification: current ? quorumFailure ? { ok: false, reason: quorumFailure } : verification : null,
|
|
8405
|
+
busy,
|
|
8406
|
+
error,
|
|
8407
|
+
approveBlocked: !!current && approveFailedFor === current.id,
|
|
8408
|
+
deviceNotLinked,
|
|
8409
|
+
onLinkDevice: () => {
|
|
8410
|
+
onClose();
|
|
8411
|
+
openRecoveryModal();
|
|
8412
|
+
},
|
|
8413
|
+
...lastResolved ? { lastResolved } : {},
|
|
8414
|
+
closesIn,
|
|
8415
|
+
nextStep: awaitingNext ? nextStep : null,
|
|
8416
|
+
language,
|
|
8417
|
+
network,
|
|
8418
|
+
history,
|
|
8419
|
+
explorerUrlOf: (r) => r.submit?.hash ? explorerTxUrl(r.network, r.submit.hash, network) : null,
|
|
8420
|
+
onSelect: (r) => setSelectedId(r.id),
|
|
8421
|
+
onApprove: (r) => void run("approving", r, approve),
|
|
8422
|
+
onReject: (r) => void run("rejecting", r, reject),
|
|
8423
|
+
onClose: requestClose,
|
|
8424
|
+
confirmingClose,
|
|
8425
|
+
onKeepOpen: () => setAskedToClose(false),
|
|
8426
|
+
onCloseAnyway: onClose
|
|
8192
8427
|
}
|
|
8428
|
+
);
|
|
8429
|
+
}
|
|
8430
|
+
var PAYMENT_CHECK_EVERY_MS = 1e4;
|
|
8431
|
+
var PAYMENT_CHECK_WINDOW_MS = 2 * 6e4;
|
|
8432
|
+
function rampErrorMessage(error, fallback, copy, language) {
|
|
8433
|
+
const unavailable = appUnavailableMessage(error, language);
|
|
8434
|
+
if (unavailable) return unavailable;
|
|
8435
|
+
if (isPollarApiError(error)) {
|
|
8436
|
+
const known = copy.errors[error.code];
|
|
8437
|
+
if (known) return known;
|
|
8438
|
+
const message = error.body.message;
|
|
8439
|
+
if (typeof message === "string" && message && !/^[A-Z0-9_]+$/.test(message)) return message;
|
|
8193
8440
|
}
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8441
|
+
return fallback;
|
|
8442
|
+
}
|
|
8443
|
+
var DECIMAL = /^\d+(\.\d+)?$/;
|
|
8444
|
+
var QUOTE_DEBOUNCE_MS = 600;
|
|
8445
|
+
function seededSelection(routes, seed) {
|
|
8446
|
+
const countries = rampCountries(routes);
|
|
8447
|
+
const wanted = seed.country?.trim().toUpperCase();
|
|
8448
|
+
const country = wanted ? countries.find((c) => c.country === wanted) : countries[0];
|
|
8449
|
+
if (!country) return null;
|
|
8450
|
+
const fiat = country.fiats.find((f) => f.currency === seed.fiat?.trim().toUpperCase()) ?? null;
|
|
8451
|
+
const resolvedFiat = fiat ?? country.fiats[0];
|
|
8452
|
+
const asset = routes.find(
|
|
8453
|
+
(r) => r.fiat.country === country.country && resolvedFiat !== void 0 && fiatKey(r.fiat) === fiatKey(resolvedFiat) && r.asset.code.toUpperCase() === seed.asset?.trim().toUpperCase()
|
|
8454
|
+
)?.asset;
|
|
8455
|
+
const amount = seed.amount?.trim() ?? "";
|
|
8456
|
+
return {
|
|
8457
|
+
country: country.country,
|
|
8458
|
+
fiatChoice: fiat ? fiatKey(fiat) : "",
|
|
8459
|
+
assetChoice: asset ? assetKey3(asset) : "",
|
|
8460
|
+
amount: DECIMAL.test(amount) ? amount : ""
|
|
8461
|
+
};
|
|
8462
|
+
}
|
|
8463
|
+
async function signLegWithWallet(client, orderId, actionId, copy) {
|
|
8464
|
+
const lent = [];
|
|
8465
|
+
const lend = (chain, encoding, handler) => {
|
|
8466
|
+
try {
|
|
8467
|
+
lent.push(client.registerRampSigningHandler(chain, encoding, handler));
|
|
8468
|
+
} catch {
|
|
8203
8469
|
}
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
const
|
|
8207
|
-
if (
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8470
|
+
};
|
|
8471
|
+
lend("STELLAR", "xdr", async (action) => {
|
|
8472
|
+
const wallet = client.getWallet();
|
|
8473
|
+
if (!wallet) throw new Error(copy.connectStellarWallet);
|
|
8474
|
+
assertRampStellarSigner(action, wallet.address);
|
|
8475
|
+
const outcome = await client.signTx(action.payload.value);
|
|
8476
|
+
if (client.getWallet()?.address !== wallet.address) throw new Error(copy.walletChanged);
|
|
8477
|
+
if (outcome.status === "signed") return outcome.signedXdr;
|
|
8478
|
+
throw new Error(
|
|
8479
|
+
outcome.status === "error" ? outcome.message ?? outcome.details ?? copy.signingCancelled : copy.signingCancelled
|
|
8480
|
+
);
|
|
8481
|
+
});
|
|
8482
|
+
lend("SOLANA", "solana-v0-json", async (action) => {
|
|
8483
|
+
const payload = JSON.parse(action.payload.value);
|
|
8484
|
+
const solanaWallet = () => client.getWallets().find((w) => w.chain === "SOLANA" && w.custody === "external");
|
|
8485
|
+
const wallet = solanaWallet();
|
|
8486
|
+
if (!wallet || payload.from !== wallet.address || !payload.unsignedTransaction) throw new Error(copy.solanaWalletMismatch);
|
|
8487
|
+
const signed = await client.signSolanaTransaction(payload.unsignedTransaction);
|
|
8488
|
+
if (solanaWallet()?.address !== wallet.address) throw new Error(copy.walletChanged);
|
|
8489
|
+
return signed;
|
|
8490
|
+
});
|
|
8491
|
+
try {
|
|
8492
|
+
return await client.signRampLeg(orderId, actionId);
|
|
8493
|
+
} finally {
|
|
8494
|
+
for (const release of lent) release();
|
|
8495
|
+
}
|
|
8496
|
+
}
|
|
8497
|
+
function RampWidget({ onClose, language: languageProp, initial }) {
|
|
8498
|
+
const {
|
|
8499
|
+
getClient,
|
|
8500
|
+
styles,
|
|
8501
|
+
network,
|
|
8502
|
+
openCosignModal,
|
|
8503
|
+
setCosignNextStep,
|
|
8504
|
+
openRecoveryModal,
|
|
8505
|
+
recovery,
|
|
8506
|
+
recoveryLocked,
|
|
8507
|
+
appConfig,
|
|
8508
|
+
cosign,
|
|
8509
|
+
refreshWalletBalance,
|
|
8510
|
+
registerCosignHost
|
|
8511
|
+
} = usePollar();
|
|
8512
|
+
const client = getClient();
|
|
8513
|
+
const language = useModalLanguage(languageProp);
|
|
8514
|
+
const copy = RAMP_COPY[language];
|
|
8515
|
+
const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
|
|
8516
|
+
const [step, setStep] = useState("input");
|
|
8517
|
+
const confirmation = useInlineConfirmation(step === "status");
|
|
8518
|
+
const [direction, setDirection] = useState(initial?.direction === "sell" ? "OFFRAMP" : "ONRAMP");
|
|
8519
|
+
const seedRef = useRef(
|
|
8520
|
+
initial ? { direction: initial.direction === "sell" ? "OFFRAMP" : "ONRAMP", options: initial } : null
|
|
8521
|
+
);
|
|
8522
|
+
const [routes, setRoutes] = useState([]);
|
|
8523
|
+
const [routesLoading, setRoutesLoading] = useState(true);
|
|
8524
|
+
const [country, setCountry] = useState("");
|
|
8525
|
+
const [fiatChoice, setFiatChoice] = useState("");
|
|
8526
|
+
const [assetChoice, setAssetChoice] = useState("");
|
|
8527
|
+
const [amount, setAmount] = useState("");
|
|
8528
|
+
const [quotes, setQuotes] = useState([]);
|
|
8529
|
+
const [rejected, setRejected] = useState([]);
|
|
8530
|
+
const [selected, setSelected] = useState(null);
|
|
8531
|
+
const [startingQuoteId, setStartingQuoteId] = useState(null);
|
|
8532
|
+
const [fieldValues, setFieldValues] = useState({});
|
|
8533
|
+
const [order, setOrder] = useState(null);
|
|
8534
|
+
const [pendingOrders, setPendingOrders] = useState([]);
|
|
8535
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
8536
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
8537
|
+
const [signing, setSigning] = useState(false);
|
|
8538
|
+
const [errorMsg, setErrorMsg] = useState(null);
|
|
8539
|
+
const [verifying, setVerifying] = useState(null);
|
|
8540
|
+
const [trustingAsset, setTrustingAsset] = useState(null);
|
|
8541
|
+
const [walletBusy, setWalletBusy] = useState(null);
|
|
8542
|
+
const [retrying, setRetrying] = useState(false);
|
|
8543
|
+
const [cancelling, setCancelling] = useState(false);
|
|
8544
|
+
const [cancelError, setCancelError] = useState(null);
|
|
8545
|
+
const [awaitingAccount, setAwaitingAccount] = useState(null);
|
|
8546
|
+
const [pollTrouble, setPollTrouble] = useState(false);
|
|
8547
|
+
const [pollKey, setPollKey] = useState(0);
|
|
8548
|
+
const [paymentCheckUntil, setPaymentCheckUntil] = useState(null);
|
|
8549
|
+
const checkErrorRef = useRef(null);
|
|
8550
|
+
const promptedApproval = useRef(null);
|
|
8551
|
+
const custodyChoice = appConfig.application?.walletCustodyMode === "USER_CHOICE";
|
|
8552
|
+
const appChains = appConfig.application?.chains;
|
|
8553
|
+
const verifyAttempt = useRef(null);
|
|
8554
|
+
const countries = useMemo(() => rampCountries(routes), [routes]);
|
|
8555
|
+
const fiats = countries.find((c) => c.country === country)?.fiats ?? [];
|
|
8556
|
+
const fiat = fiats.find((f) => fiatKey(f) === fiatChoice) ?? fiats[0] ?? null;
|
|
8557
|
+
const assets = useMemo(() => {
|
|
8558
|
+
const seen = /* @__PURE__ */ new Map();
|
|
8559
|
+
for (const route of routes)
|
|
8560
|
+
if (fiat && route.fiat.country === country && fiatKey(route.fiat) === fiatKey(fiat))
|
|
8561
|
+
seen.set(assetKey3(route.asset), route.asset);
|
|
8562
|
+
return [...seen.values()];
|
|
8563
|
+
}, [routes, country, fiat]);
|
|
8564
|
+
const asset = assets.find((a) => assetKey3(a) === assetChoice) ?? assets[0] ?? null;
|
|
8565
|
+
const fields = selected ? rampQuoteFields(selected, language) : [];
|
|
8566
|
+
const sellAvailable = useWalletAvailable(
|
|
8567
|
+
direction === "OFFRAMP" && asset ? { chain: asset.chain, code: asset.code, issuer: asset.identifier } : null
|
|
8568
|
+
);
|
|
8569
|
+
const [quoting, setQuoting] = useState(false);
|
|
8570
|
+
const [routeChoice, setRouteChoice] = useState(BEST_ROUTE);
|
|
8571
|
+
const quoteRun = useRef(0);
|
|
8572
|
+
const quoteInput = step === "input" && fiat && asset && DECIMAL.test(amount.trim()) && Number(amount) > 0;
|
|
8573
|
+
const quoteKey = quoteInput ? `${direction}|${fiatKey(fiat)}|${assetKey3(asset)}|${amount.trim()}` : null;
|
|
8574
|
+
useEffect(() => {
|
|
8575
|
+
const run = ++quoteRun.current;
|
|
8576
|
+
if (!quoteKey || !fiat || !asset) {
|
|
8577
|
+
setQuoting(false);
|
|
8578
|
+
if (step === "input") {
|
|
8579
|
+
setQuotes([]);
|
|
8580
|
+
setRejected([]);
|
|
8238
8581
|
}
|
|
8239
|
-
|
|
8240
|
-
if (isPollarApiError(error) && error.code === "VALIDATION_ERROR" && rampQuoteFields(quote).length) setStep("contact");
|
|
8241
|
-
else setStep("select_route");
|
|
8242
|
-
} finally {
|
|
8243
|
-
setIsLoading(false);
|
|
8244
|
-
setStartingQuoteId(null);
|
|
8582
|
+
return;
|
|
8245
8583
|
}
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8584
|
+
setQuoting(true);
|
|
8585
|
+
const timer = setTimeout(() => {
|
|
8586
|
+
client.quoteRamp({
|
|
8587
|
+
direction,
|
|
8588
|
+
fiat: { currency: fiat.currency, rail: fiat.rail, country: fiat.country },
|
|
8589
|
+
asset: { code: asset.code, identifier: asset.identifier, chain: asset.chain },
|
|
8590
|
+
amount: { value: amount.trim(), denomination: "in" }
|
|
8591
|
+
}).then((result) => {
|
|
8592
|
+
if (run !== quoteRun.current) return;
|
|
8593
|
+
setQuotes(result.quotes);
|
|
8594
|
+
setRejected(result.rejected);
|
|
8595
|
+
setErrorMsg(null);
|
|
8596
|
+
}).catch((error) => {
|
|
8597
|
+
if (run !== quoteRun.current) return;
|
|
8598
|
+
setQuotes([]);
|
|
8599
|
+
if (isPollarApiError(error) && error.code === "SDK_RAMPS_NO_ROUTE") {
|
|
8600
|
+
setRejected(Array.isArray(error.body.rejected) ? error.body.rejected : []);
|
|
8601
|
+
} else {
|
|
8602
|
+
setRejected([]);
|
|
8603
|
+
setErrorMsg(rampErrorMessage(error, copy.findRouteFailed, copy, language));
|
|
8604
|
+
}
|
|
8605
|
+
}).finally(() => {
|
|
8606
|
+
if (run === quoteRun.current) setQuoting(false);
|
|
8607
|
+
});
|
|
8608
|
+
}, QUOTE_DEBOUNCE_MS);
|
|
8609
|
+
return () => clearTimeout(timer);
|
|
8610
|
+
}, [quoteKey]);
|
|
8611
|
+
const chosenQuote = (routeChoice !== BEST_ROUTE ? quotes.find((q) => routeKey(q) === routeChoice) : void 0) ?? quotes[0] ?? null;
|
|
8612
|
+
useEffect(() => {
|
|
8613
|
+
if (direction === "OFFRAMP") void refreshWalletBalance();
|
|
8614
|
+
}, [direction, refreshWalletBalance]);
|
|
8615
|
+
async function loadRoutes(next) {
|
|
8616
|
+
setRoutesLoading(true);
|
|
8252
8617
|
try {
|
|
8253
|
-
|
|
8618
|
+
const { routes: found } = await client.getRampRoutes(next);
|
|
8619
|
+
setRoutes(found);
|
|
8620
|
+
const seed = seedRef.current?.direction === next ? seedRef.current.options : null;
|
|
8621
|
+
if (seed) seedRef.current = null;
|
|
8622
|
+
const seeded = seed ? seededSelection(found, seed) : null;
|
|
8623
|
+
if (seeded) {
|
|
8624
|
+
setCountry(seeded.country);
|
|
8625
|
+
setFiatChoice(seeded.fiatChoice);
|
|
8626
|
+
setAssetChoice(seeded.assetChoice);
|
|
8627
|
+
setAmount(seeded.amount);
|
|
8628
|
+
return;
|
|
8629
|
+
}
|
|
8630
|
+
const first = rampCountries(found)[0]?.country ?? "";
|
|
8631
|
+
setCountry((current) => found.some((r) => r.fiat.country === current) ? current : first);
|
|
8254
8632
|
} catch (error) {
|
|
8255
|
-
|
|
8256
|
-
|
|
8257
|
-
error,
|
|
8258
|
-
error instanceof Error && error.message ? error.message : copy.signingCancelled,
|
|
8259
|
-
copy,
|
|
8260
|
-
language
|
|
8261
|
-
)
|
|
8262
|
-
);
|
|
8263
|
-
setOrder(await client.getRampOrder(order.id).catch(() => order));
|
|
8633
|
+
setRoutes([]);
|
|
8634
|
+
setErrorMsg(rampErrorMessage(error, copy.loadRoutesFailed, copy, language));
|
|
8264
8635
|
} finally {
|
|
8265
|
-
|
|
8636
|
+
setRoutesLoading(false);
|
|
8266
8637
|
}
|
|
8267
8638
|
}
|
|
8268
|
-
async function
|
|
8269
|
-
setIsLoading(true);
|
|
8270
|
-
setErrorMsg(null);
|
|
8639
|
+
async function loadPendingOrders() {
|
|
8271
8640
|
try {
|
|
8272
|
-
const
|
|
8273
|
-
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
setStep("status");
|
|
8277
|
-
} catch (error) {
|
|
8278
|
-
setErrorMsg(rampErrorMessage(error, copy.resumeOrderFailed, copy, language));
|
|
8279
|
-
} finally {
|
|
8280
|
-
setIsLoading(false);
|
|
8641
|
+
const page = await client.listRampOrders({ open: "true", limit: 5 });
|
|
8642
|
+
setPendingOrders(page.orders);
|
|
8643
|
+
} catch {
|
|
8644
|
+
setPendingOrders([]);
|
|
8281
8645
|
}
|
|
8282
8646
|
}
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
setQuotes([]);
|
|
8288
|
-
setRejected([]);
|
|
8289
|
-
setErrorMsg(null);
|
|
8290
|
-
setStep("input");
|
|
8647
|
+
useEffect(() => {
|
|
8648
|
+
void loadRoutes(direction);
|
|
8649
|
+
}, [client, direction]);
|
|
8650
|
+
useEffect(() => {
|
|
8291
8651
|
void loadPendingOrders();
|
|
8292
|
-
}
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8652
|
+
}, [client]);
|
|
8653
|
+
const orderId = order?.id ?? null;
|
|
8654
|
+
useEffect(() => {
|
|
8655
|
+
if (step !== "status" || !orderId) return;
|
|
8656
|
+
const controller = new AbortController();
|
|
8657
|
+
client.pollRampOrder(orderId, {
|
|
8658
|
+
signal: controller.signal,
|
|
8659
|
+
onUpdate: (next) => {
|
|
8660
|
+
setOrder(next);
|
|
8661
|
+
setPollTrouble(false);
|
|
8662
|
+
},
|
|
8663
|
+
onError: () => setPollTrouble(true)
|
|
8664
|
+
}).catch((error) => {
|
|
8665
|
+
if (!controller.signal.aborted) setErrorMsg(rampErrorMessage(error, copy.readOrderFailed, copy, language));
|
|
8666
|
+
});
|
|
8667
|
+
return () => controller.abort();
|
|
8668
|
+
}, [client, step, orderId, pollKey]);
|
|
8669
|
+
const awaitingPayment = step === "status" && order?.pendingAction?.kind === "FIAT_PAYMENT";
|
|
8670
|
+
useEffect(() => {
|
|
8671
|
+
if (paymentCheckUntil === null || !orderId) return;
|
|
8672
|
+
if (!awaitingPayment) {
|
|
8311
8673
|
setPaymentCheckUntil(null);
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8674
|
+
setPollKey((key) => key + 1);
|
|
8675
|
+
return;
|
|
8676
|
+
}
|
|
8677
|
+
return startBackoffPoll(async () => {
|
|
8678
|
+
if (Date.now() >= paymentCheckUntil) {
|
|
8679
|
+
setPaymentCheckUntil(null);
|
|
8680
|
+
return;
|
|
8681
|
+
}
|
|
8682
|
+
setOrder(await client.checkRampOrder(orderId));
|
|
8683
|
+
}, PAYMENT_CHECK_EVERY_MS);
|
|
8684
|
+
}, [client, orderId, awaitingPayment, paymentCheckUntil]);
|
|
8685
|
+
useEffect(() => {
|
|
8686
|
+
if (awaitingPayment || checkErrorRef.current === null) return;
|
|
8687
|
+
const shown = checkErrorRef.current;
|
|
8688
|
+
checkErrorRef.current = null;
|
|
8689
|
+
setErrorMsg((current) => current === shown ? null : current);
|
|
8690
|
+
}, [awaitingPayment]);
|
|
8691
|
+
const hostsCosign = step === "status" && !!order && !["completed", "failed", "refunded"].includes(order.state);
|
|
8692
|
+
const hostsCosignRef = useRef(hostsCosign);
|
|
8693
|
+
hostsCosignRef.current = hostsCosign;
|
|
8694
|
+
useEffect(() => hostsCosign ? registerCosignHost() : void 0, [hostsCosign, registerCosignHost]);
|
|
8695
|
+
const approval = order?.pendingAction?.kind === "COSIGN_APPROVAL" ? order.pendingAction.actionId : null;
|
|
8696
|
+
const approvalRequest = order?.pendingAction?.kind === "COSIGN_APPROVAL" ? order.pendingAction.cosignRequestId : null;
|
|
8697
|
+
useEffect(() => {
|
|
8698
|
+
if (!approval || promptedApproval.current === approval) return;
|
|
8699
|
+
promptedApproval.current = approval;
|
|
8700
|
+
void client.cosign.pending().catch(() => []).then(async (requests) => {
|
|
8701
|
+
const request = requests.find((r) => r.id === approvalRequest);
|
|
8702
|
+
if (request && await client.autoApproveSignIn(request)) return;
|
|
8703
|
+
if (!hostsCosignRef.current) openCosignModal();
|
|
8704
|
+
});
|
|
8705
|
+
}, [approval, approvalRequest, client, openCosignModal]);
|
|
8706
|
+
const nextApproval = step === "status" && order ? rampNextApproval(order, language) : null;
|
|
8707
|
+
useEffect(() => {
|
|
8708
|
+
setCosignNextStep(nextApproval);
|
|
8709
|
+
}, [nextApproval, setCosignNextStep]);
|
|
8710
|
+
useEffect(() => () => setCosignNextStep(null), [setCosignNextStep]);
|
|
8711
|
+
const resolvedRequest = cosign.lastResolved;
|
|
8712
|
+
useEffect(() => {
|
|
8713
|
+
if (!awaitingAccount || resolvedRequest?.id !== awaitingAccount.requestId) return;
|
|
8714
|
+
setAwaitingAccount(null);
|
|
8715
|
+
if (resolvedRequest.status !== "APPROVED") {
|
|
8716
|
+
setErrorMsg(copy.accountNotApproved);
|
|
8717
|
+
return;
|
|
8315
8718
|
}
|
|
8719
|
+
void resumeRoute(awaitingAccount.routeKey);
|
|
8720
|
+
}, [awaitingAccount, resolvedRequest]);
|
|
8721
|
+
function handleDirectionChange(next) {
|
|
8722
|
+
seedRef.current = null;
|
|
8723
|
+
setDirection(next);
|
|
8724
|
+
setErrorMsg(null);
|
|
8725
|
+
setAwaitingAccount(null);
|
|
8316
8726
|
}
|
|
8317
|
-
async function
|
|
8318
|
-
if (!
|
|
8319
|
-
|
|
8727
|
+
async function handleFindRoute() {
|
|
8728
|
+
if (!fiat || !asset) return [];
|
|
8729
|
+
if (!DECIMAL.test(amount.trim()) || Number(amount) <= 0) {
|
|
8730
|
+
setErrorMsg(copy.amountInvalid);
|
|
8731
|
+
return [];
|
|
8732
|
+
}
|
|
8733
|
+
setStep("loading_quote");
|
|
8320
8734
|
setErrorMsg(null);
|
|
8735
|
+
setSelected(null);
|
|
8321
8736
|
try {
|
|
8322
|
-
|
|
8323
|
-
|
|
8737
|
+
const result = await client.quoteRamp({
|
|
8738
|
+
direction,
|
|
8739
|
+
fiat: { currency: fiat.currency, rail: fiat.rail, country: fiat.country },
|
|
8740
|
+
asset: { code: asset.code, identifier: asset.identifier, chain: asset.chain },
|
|
8741
|
+
amount: { value: amount.trim(), denomination: "in" }
|
|
8742
|
+
});
|
|
8743
|
+
setQuotes(result.quotes);
|
|
8744
|
+
setRejected(result.rejected);
|
|
8745
|
+
setStep("select_route");
|
|
8746
|
+
return result.quotes;
|
|
8324
8747
|
} catch (error) {
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8748
|
+
if (isPollarApiError(error) && error.code === "SDK_RAMPS_NO_ROUTE") {
|
|
8749
|
+
setQuotes([]);
|
|
8750
|
+
setRejected(Array.isArray(error.body.rejected) ? error.body.rejected : []);
|
|
8751
|
+
setStep("select_route");
|
|
8752
|
+
return [];
|
|
8753
|
+
}
|
|
8754
|
+
setErrorMsg(rampErrorMessage(error, copy.findRouteFailed, copy, language));
|
|
8755
|
+
setStep("error");
|
|
8756
|
+
return [];
|
|
8328
8757
|
}
|
|
8329
8758
|
}
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
8333
|
-
|
|
8759
|
+
function handleVerifyRoute(requirement) {
|
|
8760
|
+
setErrorMsg(null);
|
|
8761
|
+
verifyAttempt.current = requirement;
|
|
8762
|
+
setVerifying(requirement);
|
|
8763
|
+
}
|
|
8764
|
+
function closeVerification() {
|
|
8765
|
+
verifyAttempt.current = null;
|
|
8766
|
+
setVerifying(null);
|
|
8767
|
+
}
|
|
8768
|
+
function verificationDone(requirement) {
|
|
8769
|
+
if (verifyAttempt.current !== requirement) return;
|
|
8770
|
+
closeVerification();
|
|
8771
|
+
void handleFindRoute();
|
|
8772
|
+
}
|
|
8773
|
+
async function handleTrustAsset(asset2) {
|
|
8774
|
+
if (trustingAsset) return;
|
|
8775
|
+
setTrustingAsset(`${asset2.code}:${asset2.issuer}`);
|
|
8776
|
+
setErrorMsg(null);
|
|
8334
8777
|
try {
|
|
8335
|
-
|
|
8336
|
-
|
|
8778
|
+
const outcome = await client.setTrustline(asset2);
|
|
8779
|
+
if (outcome.status === "error") {
|
|
8780
|
+
setErrorMsg(rampTrustlineErrorText(outcome, asset2.code, language));
|
|
8781
|
+
return;
|
|
8782
|
+
}
|
|
8783
|
+
if (outcome.status === "cosign_pending") {
|
|
8784
|
+
setErrorMsg(copy.approveTrustline(asset2.code));
|
|
8785
|
+
openCosignModal();
|
|
8786
|
+
return;
|
|
8787
|
+
}
|
|
8788
|
+
await client.refreshAssets().catch(() => {
|
|
8789
|
+
});
|
|
8790
|
+
await handleFindRoute();
|
|
8337
8791
|
} catch (error) {
|
|
8338
|
-
|
|
8792
|
+
setErrorMsg(rampErrorMessage(error, copy.addTrustlineFailed(asset2.code), copy, language));
|
|
8339
8793
|
} finally {
|
|
8340
|
-
|
|
8794
|
+
setTrustingAsset(null);
|
|
8341
8795
|
}
|
|
8342
8796
|
}
|
|
8343
|
-
async function
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
const heldForRecovery = step === "status" && order?.failure?.resolutionAction === "set_up_recovery";
|
|
8348
|
-
const wasRecoveryLocked = useRef(recoveryLocked);
|
|
8349
|
-
useEffect(() => {
|
|
8350
|
-
if (heldForRecovery && wasRecoveryLocked.current && !recoveryLocked && recovery) void handleRetryOrder();
|
|
8351
|
-
wasRecoveryLocked.current = recoveryLocked;
|
|
8352
|
-
}, [heldForRecovery, recoveryLocked, recovery]);
|
|
8353
|
-
async function handleRefresh() {
|
|
8354
|
-
if (refreshing) return;
|
|
8355
|
-
setRefreshing(true);
|
|
8797
|
+
async function handleWalletStep(walletStep, index, custody) {
|
|
8798
|
+
if (walletBusy !== null) return;
|
|
8799
|
+
setWalletBusy(index);
|
|
8800
|
+
setErrorMsg(null);
|
|
8356
8801
|
try {
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
await loadRoutes(direction);
|
|
8363
|
-
await loadPendingOrders();
|
|
8364
|
-
if (direction === "OFFRAMP") await refreshWalletBalance();
|
|
8802
|
+
const { recoveryRequired } = await client.runRampWalletStep(walletStep, custody);
|
|
8803
|
+
if (recoveryRequired) {
|
|
8804
|
+
setErrorMsg(copy.addRecovery);
|
|
8805
|
+
openRecoveryModal();
|
|
8806
|
+
return;
|
|
8365
8807
|
}
|
|
8808
|
+
await handleFindRoute();
|
|
8366
8809
|
} catch (error) {
|
|
8367
|
-
|
|
8810
|
+
const code = isPollarApiError(error) ? error.code : null;
|
|
8811
|
+
if (code === "SDK_RAMPS_WALLET_NOT_READY") {
|
|
8812
|
+
setErrorMsg(copy.approveAccount);
|
|
8813
|
+
openCosignModal();
|
|
8814
|
+
return;
|
|
8815
|
+
}
|
|
8816
|
+
setErrorMsg(
|
|
8817
|
+
code === "SDK_WALLET_PROVISIONING_DISABLED" ? copy.noWalletCreation : rampErrorMessage(error, copy.prepareWalletFailed, copy, language)
|
|
8818
|
+
);
|
|
8368
8819
|
} finally {
|
|
8369
|
-
|
|
8820
|
+
setWalletBusy(null);
|
|
8370
8821
|
}
|
|
8371
8822
|
}
|
|
8372
|
-
|
|
8373
|
-
|
|
8374
|
-
|
|
8375
|
-
|
|
8376
|
-
};
|
|
8377
|
-
const label = stepLabel[step];
|
|
8378
|
-
if (verifying) {
|
|
8379
|
-
const progress = { progress: { position: verifying.completed + 1, total: verifying.total } };
|
|
8380
|
-
const done = () => verificationDone(verifying);
|
|
8381
|
-
if (verifying.type === "FORM")
|
|
8382
|
-
return /* @__PURE__ */ jsx(
|
|
8383
|
-
RequirementFormModal,
|
|
8384
|
-
{
|
|
8385
|
-
formId: verifying.optionId,
|
|
8386
|
-
...progress,
|
|
8387
|
-
language: languageProp,
|
|
8388
|
-
onClose: closeVerification,
|
|
8389
|
-
onSubmitted: done
|
|
8390
|
-
}
|
|
8391
|
-
);
|
|
8392
|
-
if (verifying.type === "REGISTRY_CHECK")
|
|
8393
|
-
return /* @__PURE__ */ jsx(
|
|
8394
|
-
RegistryCheckModal,
|
|
8395
|
-
{
|
|
8396
|
-
optionId: verifying.optionId,
|
|
8397
|
-
...progress,
|
|
8398
|
-
language: languageProp,
|
|
8399
|
-
onClose: closeVerification,
|
|
8400
|
-
onApproved: done
|
|
8401
|
-
}
|
|
8402
|
-
);
|
|
8403
|
-
if (verifying.type === "PROVIDER_REGISTRATION")
|
|
8404
|
-
return /* @__PURE__ */ jsx(
|
|
8405
|
-
ProviderRegistrationModal,
|
|
8406
|
-
{
|
|
8407
|
-
corridorId: verifying.corridorId,
|
|
8408
|
-
...progress,
|
|
8409
|
-
language: languageProp,
|
|
8410
|
-
onClose: closeVerification,
|
|
8411
|
-
onRegistered: done
|
|
8412
|
-
}
|
|
8413
|
-
);
|
|
8414
|
-
return /* @__PURE__ */ jsx(
|
|
8415
|
-
KycModal,
|
|
8416
|
-
{
|
|
8417
|
-
country,
|
|
8418
|
-
corridorId: verifying.corridorId,
|
|
8419
|
-
providerId: verifying.optionId,
|
|
8420
|
-
language: languageProp,
|
|
8421
|
-
onClose: closeVerification,
|
|
8422
|
-
onApproved: done
|
|
8423
|
-
}
|
|
8424
|
-
);
|
|
8823
|
+
async function resumeRoute(key) {
|
|
8824
|
+
const same = (await handleFindRoute()).find((q) => routeKey(q) === key);
|
|
8825
|
+
if (same) handleSelectQuote(same, true);
|
|
8826
|
+
else setErrorMsg(copy.routeGone);
|
|
8425
8827
|
}
|
|
8426
|
-
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8828
|
+
function handleSelectQuote(quote, fresh = false) {
|
|
8829
|
+
if (!fresh && Date.parse(quote.expiresAt) <= Date.now()) {
|
|
8830
|
+
void resumeRoute(routeKey(quote));
|
|
8831
|
+
return;
|
|
8832
|
+
}
|
|
8833
|
+
setSelected(quote);
|
|
8834
|
+
setErrorMsg(null);
|
|
8835
|
+
const missing = rampQuoteFields(quote).some((f) => !f.optional && !(fieldValues[f.key] ?? "").trim());
|
|
8836
|
+
if (missing) setStep("contact");
|
|
8837
|
+
else void startOrder(quote, fresh);
|
|
8838
|
+
}
|
|
8839
|
+
async function startOrder(quote, fresh = false) {
|
|
8840
|
+
setIsLoading(true);
|
|
8841
|
+
setStartingQuoteId(quote.quoteId);
|
|
8842
|
+
setErrorMsg(null);
|
|
8843
|
+
setAwaitingAccount(null);
|
|
8844
|
+
try {
|
|
8845
|
+
const payee = Object.fromEntries(
|
|
8846
|
+
rampQuoteFields(quote).map((f) => [f.key, (fieldValues[f.key] ?? "").trim()]).filter(([, value]) => value)
|
|
8847
|
+
);
|
|
8848
|
+
const created = await client.createRampOrder({
|
|
8849
|
+
quoteId: quote.quoteId,
|
|
8850
|
+
...Object.keys(payee).length ? { payee } : {}
|
|
8851
|
+
});
|
|
8852
|
+
setOrder(created);
|
|
8853
|
+
setStep("status");
|
|
8854
|
+
} catch (error) {
|
|
8855
|
+
if (isPollarApiError(error) && error.code === "SDK_RAMPS_WALLET_NOT_READY") {
|
|
8856
|
+
const pending = await client.cosign.pending().catch(() => []);
|
|
8857
|
+
const request = pending.find((r) => r.intent === "add_accounts");
|
|
8858
|
+
if (request) setAwaitingAccount({ routeKey: routeKey(quote), requestId: request.id });
|
|
8859
|
+
else setErrorMsg(rampErrorMessage(error, copy.startOrderFailed, copy, language));
|
|
8860
|
+
openCosignModal();
|
|
8861
|
+
setStep("select_route");
|
|
8862
|
+
return;
|
|
8863
|
+
}
|
|
8864
|
+
if (isPollarApiError(error) && error.code === "SDK_RAMPS_QUOTE_EXPIRED" && !fresh) {
|
|
8865
|
+
void resumeRoute(routeKey(quote));
|
|
8866
|
+
return;
|
|
8867
|
+
}
|
|
8868
|
+
setErrorMsg(rampErrorMessage(error, copy.startOrderFailed, copy, language));
|
|
8869
|
+
if (isPollarApiError(error) && error.code === "VALIDATION_ERROR" && rampQuoteFields(quote).length) setStep("contact");
|
|
8870
|
+
else setStep("select_route");
|
|
8871
|
+
} finally {
|
|
8872
|
+
setIsLoading(false);
|
|
8873
|
+
setStartingQuoteId(null);
|
|
8874
|
+
}
|
|
8875
|
+
}
|
|
8876
|
+
async function handleSign() {
|
|
8877
|
+
const action = order?.pendingAction;
|
|
8878
|
+
if (!order || action?.kind !== "SIGNATURE" || signing) return;
|
|
8879
|
+
setSigning(true);
|
|
8880
|
+
setErrorMsg(null);
|
|
8881
|
+
try {
|
|
8882
|
+
setOrder(await signLegWithWallet(client, order.id, action.actionId, copy));
|
|
8883
|
+
} catch (error) {
|
|
8884
|
+
setErrorMsg(
|
|
8885
|
+
rampErrorMessage(
|
|
8886
|
+
error,
|
|
8887
|
+
error instanceof Error && error.message ? error.message : copy.signingCancelled,
|
|
8888
|
+
copy,
|
|
8889
|
+
language
|
|
8890
|
+
)
|
|
8891
|
+
);
|
|
8892
|
+
setOrder(await client.getRampOrder(order.id).catch(() => order));
|
|
8893
|
+
} finally {
|
|
8894
|
+
setSigning(false);
|
|
8895
|
+
}
|
|
8896
|
+
}
|
|
8897
|
+
async function handleResumeOrder(id) {
|
|
8898
|
+
setIsLoading(true);
|
|
8899
|
+
setErrorMsg(null);
|
|
8900
|
+
try {
|
|
8901
|
+
const found = await client.getRampOrder(id);
|
|
8902
|
+
seedRef.current = null;
|
|
8903
|
+
setDirection(found.direction);
|
|
8904
|
+
setOrder(found);
|
|
8905
|
+
setStep("status");
|
|
8906
|
+
} catch (error) {
|
|
8907
|
+
setErrorMsg(rampErrorMessage(error, copy.resumeOrderFailed, copy, language));
|
|
8908
|
+
} finally {
|
|
8909
|
+
setIsLoading(false);
|
|
8910
|
+
}
|
|
8911
|
+
}
|
|
8912
|
+
function handleNewOrder() {
|
|
8913
|
+
setAwaitingAccount(null);
|
|
8914
|
+
setOrder(null);
|
|
8915
|
+
setSelected(null);
|
|
8916
|
+
setQuotes([]);
|
|
8917
|
+
setRejected([]);
|
|
8918
|
+
setErrorMsg(null);
|
|
8919
|
+
setStep("input");
|
|
8920
|
+
void loadPendingOrders();
|
|
8921
|
+
}
|
|
8922
|
+
function handleBack() {
|
|
8923
|
+
setErrorMsg(null);
|
|
8924
|
+
setAwaitingAccount(null);
|
|
8925
|
+
setStep(step === "contact" ? "select_route" : "input");
|
|
8926
|
+
}
|
|
8927
|
+
function handleStepSelect(target) {
|
|
8928
|
+
setErrorMsg(null);
|
|
8929
|
+
setAwaitingAccount(null);
|
|
8930
|
+
setStep(target === copy.steps.route ? "select_route" : "input");
|
|
8931
|
+
}
|
|
8932
|
+
async function handleCheckPayment() {
|
|
8933
|
+
if (!order || paymentCheckUntil !== null) return;
|
|
8934
|
+
setErrorMsg(null);
|
|
8935
|
+
setPaymentCheckUntil(Date.now() + PAYMENT_CHECK_WINDOW_MS);
|
|
8936
|
+
try {
|
|
8937
|
+
setOrder(await client.checkRampOrder(order.id));
|
|
8938
|
+
} catch (error) {
|
|
8939
|
+
if (isPollarNetworkError(error)) return;
|
|
8940
|
+
setPaymentCheckUntil(null);
|
|
8941
|
+
const message = rampErrorMessage(error, copy.checkPaymentFailed, copy, language);
|
|
8942
|
+
checkErrorRef.current = message;
|
|
8943
|
+
setErrorMsg(message);
|
|
8944
|
+
}
|
|
8945
|
+
}
|
|
8946
|
+
async function handleRetryOrder() {
|
|
8947
|
+
if (!order || retrying) return;
|
|
8948
|
+
setRetrying(true);
|
|
8949
|
+
setErrorMsg(null);
|
|
8950
|
+
try {
|
|
8951
|
+
setOrder(await client.retryRampOrder(order.id));
|
|
8952
|
+
setPollKey((key) => key + 1);
|
|
8953
|
+
} catch (error) {
|
|
8954
|
+
setErrorMsg(rampErrorMessage(error, copy.retryOrderFailed, copy, language));
|
|
8955
|
+
} finally {
|
|
8956
|
+
setRetrying(false);
|
|
8957
|
+
}
|
|
8958
|
+
}
|
|
8959
|
+
async function handleCancelOrder() {
|
|
8960
|
+
if (!order || cancelling) return;
|
|
8961
|
+
setCancelling(true);
|
|
8962
|
+
setCancelError(null);
|
|
8963
|
+
try {
|
|
8964
|
+
setOrder(await client.cancelRampOrder(order.id));
|
|
8965
|
+
void loadPendingOrders();
|
|
8966
|
+
} catch (error) {
|
|
8967
|
+
setCancelError(rampErrorMessage(error, copy.cancelOrderFailed, copy, language));
|
|
8968
|
+
} finally {
|
|
8969
|
+
setCancelling(false);
|
|
8970
|
+
}
|
|
8971
|
+
}
|
|
8972
|
+
async function handleRequote() {
|
|
8973
|
+
setOrder(null);
|
|
8974
|
+
await handleFindRoute();
|
|
8975
|
+
}
|
|
8976
|
+
const heldForRecovery = step === "status" && order?.failure?.resolutionAction === "set_up_recovery";
|
|
8977
|
+
const wasRecoveryLocked = useRef(recoveryLocked);
|
|
8978
|
+
useEffect(() => {
|
|
8979
|
+
if (heldForRecovery && wasRecoveryLocked.current && !recoveryLocked && recovery) void handleRetryOrder();
|
|
8980
|
+
wasRecoveryLocked.current = recoveryLocked;
|
|
8981
|
+
}, [heldForRecovery, recoveryLocked, recovery]);
|
|
8982
|
+
async function handleRefresh() {
|
|
8983
|
+
if (refreshing) return;
|
|
8984
|
+
setRefreshing(true);
|
|
8985
|
+
try {
|
|
8986
|
+
if (step === "status" && order) {
|
|
8987
|
+
setOrder(await client.getRampOrder(order.id));
|
|
8988
|
+
setPollKey((key) => key + 1);
|
|
8989
|
+
} else if (step === "select_route") await handleFindRoute();
|
|
8990
|
+
else {
|
|
8991
|
+
await loadRoutes(direction);
|
|
8992
|
+
await loadPendingOrders();
|
|
8993
|
+
if (direction === "OFFRAMP") await refreshWalletBalance();
|
|
8994
|
+
}
|
|
8995
|
+
} catch (error) {
|
|
8996
|
+
setErrorMsg(rampErrorMessage(error, copy.refreshFailed, copy, language));
|
|
8997
|
+
} finally {
|
|
8998
|
+
setRefreshing(false);
|
|
8999
|
+
}
|
|
9000
|
+
}
|
|
9001
|
+
const flowSteps = fields.length || quotes.some((q) => rampQuoteFields(q).length) ? [copy.steps.route, copy.steps.details, copy.steps.complete] : [copy.steps.route, copy.steps.complete];
|
|
9002
|
+
const stepLabel = {
|
|
9003
|
+
select_route: copy.steps.route,
|
|
9004
|
+
contact: copy.steps.details
|
|
9005
|
+
};
|
|
9006
|
+
const label = stepLabel[step];
|
|
9007
|
+
if (verifying) {
|
|
9008
|
+
const progress = { progress: { position: verifying.completed + 1, total: verifying.total } };
|
|
9009
|
+
const done = () => verificationDone(verifying);
|
|
9010
|
+
if (verifying.type === "FORM")
|
|
9011
|
+
return /* @__PURE__ */ jsx(
|
|
9012
|
+
RequirementFormModal,
|
|
9013
|
+
{
|
|
9014
|
+
formId: verifying.optionId,
|
|
9015
|
+
...progress,
|
|
9016
|
+
language: languageProp,
|
|
9017
|
+
onClose: closeVerification,
|
|
9018
|
+
onSubmitted: done
|
|
9019
|
+
}
|
|
9020
|
+
);
|
|
9021
|
+
if (verifying.type === "REGISTRY_CHECK")
|
|
9022
|
+
return /* @__PURE__ */ jsx(
|
|
9023
|
+
RegistryCheckModal,
|
|
9024
|
+
{
|
|
9025
|
+
optionId: verifying.optionId,
|
|
9026
|
+
...progress,
|
|
9027
|
+
language: languageProp,
|
|
9028
|
+
onClose: closeVerification,
|
|
9029
|
+
onApproved: done
|
|
9030
|
+
}
|
|
9031
|
+
);
|
|
9032
|
+
if (verifying.type === "PROVIDER_REGISTRATION")
|
|
9033
|
+
return /* @__PURE__ */ jsx(
|
|
9034
|
+
ProviderRegistrationModal,
|
|
9035
|
+
{
|
|
9036
|
+
corridorId: verifying.corridorId,
|
|
9037
|
+
...progress,
|
|
9038
|
+
language: languageProp,
|
|
9039
|
+
onClose: closeVerification,
|
|
9040
|
+
onRegistered: done
|
|
9041
|
+
}
|
|
9042
|
+
);
|
|
9043
|
+
return /* @__PURE__ */ jsx(
|
|
9044
|
+
KycModal,
|
|
9045
|
+
{
|
|
9046
|
+
country,
|
|
9047
|
+
corridorId: verifying.corridorId,
|
|
9048
|
+
providerId: verifying.optionId,
|
|
9049
|
+
language: languageProp,
|
|
9050
|
+
onClose: closeVerification,
|
|
9051
|
+
onApproved: done
|
|
9052
|
+
}
|
|
9053
|
+
);
|
|
9054
|
+
}
|
|
9055
|
+
return /* @__PURE__ */ jsx(PollarOverlay, { style: overlayStyle, onClick: step === "status" ? void 0 : onClose, children: /* @__PURE__ */ jsx(
|
|
9056
|
+
RampWidgetTemplate,
|
|
9057
|
+
{
|
|
9058
|
+
language,
|
|
9059
|
+
theme,
|
|
9060
|
+
accentColor,
|
|
9061
|
+
...styleOverrides ? { styleOverrides } : {},
|
|
9062
|
+
network,
|
|
9063
|
+
step,
|
|
9064
|
+
flowSteps,
|
|
8436
9065
|
flowStepIndex: label ? flowSteps.indexOf(label) : -1,
|
|
8437
9066
|
direction,
|
|
8438
9067
|
routesLoading,
|
|
@@ -8491,6 +9120,7 @@ function RampWidget({ onClose, language: languageProp, initial }) {
|
|
|
8491
9120
|
},
|
|
8492
9121
|
onSign: () => void handleSign(),
|
|
8493
9122
|
onApprove: openCosignModal,
|
|
9123
|
+
cosignPrompt: hostsCosign && cosign.pending.length > 0 ? /* @__PURE__ */ jsx(CosignPrompt, { inline: true, onClose: () => void 0 }) : null,
|
|
8494
9124
|
retrying,
|
|
8495
9125
|
onRetryOrder: () => void handleRetryOrder(),
|
|
8496
9126
|
onRequote: () => void handleRequote(),
|
|
@@ -11082,16 +11712,16 @@ function SwapModal({ onClose, initial }) {
|
|
|
11082
11712
|
useEffect(() => {
|
|
11083
11713
|
if (!settlementKey || settlementDone || !originLanded) return;
|
|
11084
11714
|
let cancelled = false;
|
|
11085
|
-
const read =
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
}
|
|
11715
|
+
const read = async () => {
|
|
11716
|
+
const status = await getSwapStatus(settlementKey);
|
|
11717
|
+
if (!cancelled) setSettlement((cur) => cur && cur.key === settlementKey ? { ...cur, value: status.settlement } : cur);
|
|
11718
|
+
};
|
|
11719
|
+
void read().catch(() => {
|
|
11089
11720
|
});
|
|
11090
|
-
|
|
11091
|
-
const id = setInterval(read, SETTLEMENT_POLL_MS);
|
|
11721
|
+
const stop = startBackoffPoll(read, SETTLEMENT_POLL_MS);
|
|
11092
11722
|
return () => {
|
|
11093
11723
|
cancelled = true;
|
|
11094
|
-
|
|
11724
|
+
stop();
|
|
11095
11725
|
};
|
|
11096
11726
|
}, [settlementKey, settlementDone, originLanded, getSwapStatus]);
|
|
11097
11727
|
const hash = transaction.step === "success" ? transaction.hash : null;
|
|
@@ -12277,8 +12907,7 @@ function EarnModal({ onClose, initial }) {
|
|
|
12277
12907
|
}, [refreshPosition]);
|
|
12278
12908
|
useEffect(() => {
|
|
12279
12909
|
if (step !== "form" || !onSolana && !provider || !opportunityId) return;
|
|
12280
|
-
|
|
12281
|
-
return () => clearInterval(id);
|
|
12910
|
+
return startBackoffPoll(async () => refreshPosition(), POSITION_POLL_MS);
|
|
12282
12911
|
}, [step, onSolana, provider, opportunityId, refreshPosition]);
|
|
12283
12912
|
useEffect(
|
|
12284
12913
|
() => () => {
|
|
@@ -13420,13 +14049,10 @@ function CardModal({ onClose, initial }) {
|
|
|
13420
14049
|
const kycPending = holder ? KYC_PENDING.has(holder.kycStatus) : false;
|
|
13421
14050
|
useEffect(() => {
|
|
13422
14051
|
if (!kycPending) return;
|
|
13423
|
-
|
|
13424
|
-
loadHolder()
|
|
13425
|
-
|
|
13426
|
-
}).catch(() => {
|
|
13427
|
-
});
|
|
14052
|
+
return startBackoffPoll(async () => {
|
|
14053
|
+
const h = await loadHolder();
|
|
14054
|
+
if (h?.kycStatus === "APPROVED") void loadCardData();
|
|
13428
14055
|
}, KYC_POLL_MS);
|
|
13429
|
-
return () => clearInterval(id);
|
|
13430
14056
|
}, [kycPending, loadHolder, loadCardData]);
|
|
13431
14057
|
useEffect(
|
|
13432
14058
|
() => () => {
|
|
@@ -13561,20 +14187,17 @@ function CardModal({ onClose, initial }) {
|
|
|
13561
14187
|
const fundingsInflight = (fundings ?? []).some((f) => FUNDING_INFLIGHT.has(f.status));
|
|
13562
14188
|
useEffect(() => {
|
|
13563
14189
|
if (panel !== "fund" || !fundingsInflight) return;
|
|
13564
|
-
|
|
13565
|
-
getClient().listCardFundings()
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
});
|
|
13572
|
-
return next;
|
|
14190
|
+
return startBackoffPoll(async () => {
|
|
14191
|
+
const next = await getClient().listCardFundings();
|
|
14192
|
+
setFundings((previous) => {
|
|
14193
|
+
const credited = next.some(
|
|
14194
|
+
(f) => f.status === "CREDITED" && previous?.find((p) => p.id === f.id)?.status !== "CREDITED"
|
|
14195
|
+
);
|
|
14196
|
+
if (credited) void loadCardData().catch(() => {
|
|
13573
14197
|
});
|
|
13574
|
-
|
|
14198
|
+
return next;
|
|
13575
14199
|
});
|
|
13576
14200
|
}, FUNDING_POLL_MS);
|
|
13577
|
-
return () => clearInterval(id);
|
|
13578
14201
|
}, [panel, fundingsInflight, getClient, loadCardData]);
|
|
13579
14202
|
const field = (key, label, extra = {}) => /* @__PURE__ */ jsxs("label", { className: "pollar-send-field", children: [
|
|
13580
14203
|
/* @__PURE__ */ jsx("span", { className: "pollar-send-label", children: label }),
|
|
@@ -13943,934 +14566,397 @@ function CardModal({ onClose, initial }) {
|
|
|
13943
14566
|
/* @__PURE__ */ jsx("div", { className: "pollar-modal-actions", children: /* @__PURE__ */ jsx(
|
|
13944
14567
|
"button",
|
|
13945
14568
|
{
|
|
13946
|
-
type: "button",
|
|
13947
|
-
className: "pollar-btn-primary",
|
|
13948
|
-
onClick: () => void fund(),
|
|
13949
|
-
disabled: busy !== null || !selectedRoute || !(Number(fundAmount) >= 1),
|
|
13950
|
-
children: busy === "fund-send" ? copy.sending : copy.fundFromWallet
|
|
13951
|
-
}
|
|
13952
|
-
) }),
|
|
13953
|
-
confirmation && /* @__PURE__ */ jsx(InlineConfirm, { confirmation, language }),
|
|
13954
|
-
!confirmation && sentFunding && (() => {
|
|
13955
|
-
const f = sentFunding;
|
|
13956
|
-
const state = (f.route === "DIRECT" ? copy.fundingSolana[f.status] : void 0) ?? copy.funding[f.status];
|
|
13957
|
-
const steps = FUNDING_STEPS[f.route];
|
|
13958
|
-
const step = steps.indexOf(f.status) + 1;
|
|
13959
|
-
const inflight = FUNDING_INFLIGHT.has(f.status);
|
|
13960
|
-
const failed = f.status === "FAILED";
|
|
13961
|
-
return /* @__PURE__ */ jsxs(
|
|
13962
|
-
"div",
|
|
13963
|
-
{
|
|
13964
|
-
className: `pollar-outcome${failed ? " pollar-outcome-bad" : ""}${inflight ? " pollar-outcome-busy" : ""}`,
|
|
13965
|
-
role: "status",
|
|
13966
|
-
children: [
|
|
13967
|
-
/* @__PURE__ */ jsxs("p", { className: "pollar-outcome-main", children: [
|
|
13968
|
-
inflight ? /* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm", "aria-hidden": true }) : /* @__PURE__ */ jsx(OutcomeIcon, { ok: !failed }),
|
|
13969
|
-
state?.title ?? f.status,
|
|
13970
|
-
" \xB7 ",
|
|
13971
|
-
money(f.amount, "USD", language)
|
|
13972
|
-
] }),
|
|
13973
|
-
inflight && step > 0 && /* @__PURE__ */ jsxs("p", { className: "pollar-outcome-note", children: [
|
|
13974
|
-
copy.stepOf(step, steps.length),
|
|
13975
|
-
" \xB7",
|
|
13976
|
-
" ",
|
|
13977
|
-
f.error === CREDIT_DELAYED ? copy.fundingProblem.delayed : state?.hint
|
|
13978
|
-
] }),
|
|
13979
|
-
failed && /* @__PURE__ */ jsx("p", { className: "pollar-outcome-note", children: fundingProblemText(f.error, copy) })
|
|
13980
|
-
]
|
|
13981
|
-
}
|
|
13982
|
-
);
|
|
13983
|
-
})(),
|
|
13984
|
-
earlierFundings.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
13985
|
-
/* @__PURE__ */ jsx("p", { className: "pollar-card-section-title", children: copy.yourFundings }),
|
|
13986
|
-
earlierFundings.map((f) => {
|
|
13987
|
-
const state = (f.route === "DIRECT" ? copy.fundingSolana[f.status] : void 0) ?? copy.funding[f.status];
|
|
13988
|
-
const steps = FUNDING_STEPS[f.route];
|
|
13989
|
-
const step = steps.indexOf(f.status) + 1;
|
|
13990
|
-
const inflight = FUNDING_INFLIGHT.has(f.status);
|
|
13991
|
-
return /* @__PURE__ */ jsxs("div", { className: "pollar-card-tx", "aria-busy": inflight, children: [
|
|
13992
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
13993
|
-
/* @__PURE__ */ jsxs("span", { className: "pollar-card-funding-title", children: [
|
|
13994
|
-
inflight && /* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm", "aria-hidden": true }),
|
|
13995
|
-
state?.title ?? f.status
|
|
13996
|
-
] }),
|
|
13997
|
-
inflight && step > 0 && /* @__PURE__ */ jsxs("span", { className: "pollar-card-tx-meta", role: "status", children: [
|
|
13998
|
-
copy.stepOf(step, steps.length),
|
|
13999
|
-
" \xB7",
|
|
14000
|
-
" ",
|
|
14001
|
-
f.error === CREDIT_DELAYED ? copy.fundingProblem.delayed : state?.hint
|
|
14002
|
-
] }),
|
|
14003
|
-
/* @__PURE__ */ jsxs("span", { className: "pollar-card-tx-meta", children: [
|
|
14004
|
-
new Date(f.createdAt).toLocaleString(),
|
|
14005
|
-
f.status === "FAILED" ? ` \xB7 ${fundingProblemText(f.error, copy)}` : ""
|
|
14006
|
-
] })
|
|
14007
|
-
] }),
|
|
14008
|
-
/* @__PURE__ */ jsx("div", { className: "pollar-card-tx-amount", "data-direction": f.status === "CREDITED" ? "credit" : void 0, children: money(f.amount, "USD", language) })
|
|
14009
|
-
] }, f.id);
|
|
14010
|
-
}),
|
|
14011
|
-
fundingsInflight && /* @__PURE__ */ jsx("p", { className: "pollar-card-note", children: copy.canClose })
|
|
14012
|
-
] }),
|
|
14013
|
-
!showManual && /* @__PURE__ */ jsxs("p", { className: "pollar-card-note", children: [
|
|
14014
|
-
copy.preferOtherWallet,
|
|
14015
|
-
" ",
|
|
14016
|
-
/* @__PURE__ */ jsx(
|
|
14017
|
-
"button",
|
|
14018
|
-
{
|
|
14019
|
-
type: "button",
|
|
14020
|
-
className: "pollar-card-link",
|
|
14021
|
-
onClick: () => void showManualAddress(),
|
|
14022
|
-
disabled: busy !== null,
|
|
14023
|
-
children: copy.showDeposit
|
|
14024
|
-
}
|
|
14025
|
-
)
|
|
14026
|
-
] }),
|
|
14027
|
-
showManual && deposit?.map((d) => /* @__PURE__ */ jsxs("div", { className: "pollar-card-deposit", children: [
|
|
14028
|
-
/* @__PURE__ */ jsx("strong", { children: d.network }),
|
|
14029
|
-
" (",
|
|
14030
|
-
copy.chain(d.chainId),
|
|
14031
|
-
")",
|
|
14032
|
-
/* @__PURE__ */ jsx("code", { children: d.address }),
|
|
14033
|
-
/* @__PURE__ */ jsx(CopyButton, { value: d.address, label: copy.copyAddress, language }),
|
|
14034
|
-
/* @__PURE__ */ jsx("p", { className: "pollar-card-note", children: copy.sendOnly(d.tokens.map((t) => (t.currency ?? "token").toUpperCase()).join(` ${copy.or} `), d.network) })
|
|
14035
|
-
] }, d.network)),
|
|
14036
|
-
showManual && deposit?.length === 0 && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: copy.noDeposit }),
|
|
14037
|
-
showManual && /* @__PURE__ */ jsx("p", { className: "pollar-card-note", children: /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-card-link", onClick: () => setShowManual(false), children: copy.hideDeposit }) })
|
|
14038
|
-
] }),
|
|
14039
|
-
error && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: error }),
|
|
14040
|
-
loadFailed && /* @__PURE__ */ jsx("div", { className: "pollar-modal-actions", children: /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: retryLoad, children: copy.retry }) }),
|
|
14041
|
-
/* @__PURE__ */ jsx(PollarModalFooter, { language })
|
|
14042
|
-
]
|
|
14043
|
-
}
|
|
14044
|
-
) });
|
|
14045
|
-
}
|
|
14046
|
-
|
|
14047
|
-
// src/components/sessions-modal/sessions-copy.ts
|
|
14048
|
-
var SESSIONS_COPY = {
|
|
14049
|
-
en: {
|
|
14050
|
-
title: "Active sessions",
|
|
14051
|
-
refresh: "Refresh",
|
|
14052
|
-
close: "Close",
|
|
14053
|
-
loading: "Loading\u2026",
|
|
14054
|
-
empty: "No active sessions.",
|
|
14055
|
-
thisDevice: "This device",
|
|
14056
|
-
activeNow: "Active now",
|
|
14057
|
-
otherDevices: "Other devices",
|
|
14058
|
-
signOutDevice: (device) => `Sign out ${device}`,
|
|
14059
|
-
signingOut: "Signing out\u2026",
|
|
14060
|
-
signOutThisDevice: "Sign out this device",
|
|
14061
|
-
noOtherDevices: "No other devices to sign out",
|
|
14062
|
-
signOutEverywhere: "Sign out everywhere",
|
|
14063
|
-
unknownDevice: "Unknown device",
|
|
14064
|
-
revokeFailed: "Could not sign out that device. Please try again.",
|
|
14065
|
-
justNow: "just now",
|
|
14066
|
-
secondsAgo: (n) => `${n}s ago`,
|
|
14067
|
-
minutesAgo: (n) => `${n}m ago`,
|
|
14068
|
-
hoursAgo: (n) => `${n}h ago`,
|
|
14069
|
-
daysAgo: (n) => `${n}d ago`
|
|
14070
|
-
},
|
|
14071
|
-
es: {
|
|
14072
|
-
title: "Sesiones activas",
|
|
14073
|
-
refresh: "Actualizar",
|
|
14074
|
-
close: "Cerrar",
|
|
14075
|
-
loading: "Cargando\u2026",
|
|
14076
|
-
empty: "No hay sesiones activas.",
|
|
14077
|
-
thisDevice: "Este dispositivo",
|
|
14078
|
-
activeNow: "Activa ahora",
|
|
14079
|
-
otherDevices: "Otros dispositivos",
|
|
14080
|
-
signOutDevice: (device) => `Cerrar sesi\xF3n en ${device}`,
|
|
14081
|
-
signingOut: "Cerrando sesi\xF3n\u2026",
|
|
14082
|
-
signOutThisDevice: "Cerrar sesi\xF3n en este dispositivo",
|
|
14083
|
-
noOtherDevices: "No hay otros dispositivos donde cerrar sesi\xF3n",
|
|
14084
|
-
signOutEverywhere: "Cerrar sesi\xF3n en todas partes",
|
|
14085
|
-
unknownDevice: "Dispositivo desconocido",
|
|
14086
|
-
revokeFailed: "No se pudo cerrar sesi\xF3n en ese dispositivo. Intenta de nuevo.",
|
|
14087
|
-
justNow: "justo ahora",
|
|
14088
|
-
secondsAgo: (n) => `hace ${n} s`,
|
|
14089
|
-
minutesAgo: (n) => `hace ${n} min`,
|
|
14090
|
-
hoursAgo: (n) => `hace ${n} h`,
|
|
14091
|
-
daysAgo: (n) => `hace ${n} d`
|
|
14092
|
-
},
|
|
14093
|
-
pt: {
|
|
14094
|
-
title: "Sess\xF5es ativas",
|
|
14095
|
-
refresh: "Atualizar",
|
|
14096
|
-
close: "Fechar",
|
|
14097
|
-
loading: "Carregando\u2026",
|
|
14098
|
-
empty: "Nenhuma sess\xE3o ativa.",
|
|
14099
|
-
thisDevice: "Este dispositivo",
|
|
14100
|
-
activeNow: "Ativa agora",
|
|
14101
|
-
otherDevices: "Outros dispositivos",
|
|
14102
|
-
signOutDevice: (device) => `Sair de ${device}`,
|
|
14103
|
-
signingOut: "Saindo\u2026",
|
|
14104
|
-
signOutThisDevice: "Sair deste dispositivo",
|
|
14105
|
-
noOtherDevices: "N\xE3o h\xE1 outros dispositivos para sair",
|
|
14106
|
-
signOutEverywhere: "Sair de todos os dispositivos",
|
|
14107
|
-
unknownDevice: "Dispositivo desconhecido",
|
|
14108
|
-
revokeFailed: "N\xE3o foi poss\xEDvel sair desse dispositivo. Tente novamente.",
|
|
14109
|
-
justNow: "agora mesmo",
|
|
14110
|
-
secondsAgo: (n) => `h\xE1 ${n} s`,
|
|
14111
|
-
minutesAgo: (n) => `h\xE1 ${n} min`,
|
|
14112
|
-
hoursAgo: (n) => `h\xE1 ${n} h`,
|
|
14113
|
-
daysAgo: (n) => `h\xE1 ${n} d`
|
|
14114
|
-
}
|
|
14115
|
-
};
|
|
14116
|
-
function describeDevice(s, copy) {
|
|
14117
|
-
if (s.deviceLabel) return normalizeDeviceLabel(s.deviceLabel);
|
|
14118
|
-
if (!s.userAgent) return copy.unknownDevice;
|
|
14119
|
-
return parseUserAgent(s.userAgent);
|
|
14120
|
-
}
|
|
14121
|
-
function normalizeDeviceLabel(label) {
|
|
14122
|
-
const parts = label.replace(/\s+/g, " ").split(/ (?:[—–-]|·) /);
|
|
14123
|
-
if (parts.length === 2 && parts[1] !== void 0) return `${parts[0]} \xB7 ${parts[1].toLowerCase()}`;
|
|
14124
|
-
return label;
|
|
14125
|
-
}
|
|
14126
|
-
function detectBrowser(ua) {
|
|
14127
|
-
if (/Edg\//.test(ua)) return "Edge";
|
|
14128
|
-
if (/OPR\//.test(ua)) return "Opera";
|
|
14129
|
-
if (/(Chrome|CriOS)\//.test(ua)) return "Chrome";
|
|
14130
|
-
if (/(Firefox|FxiOS)\//.test(ua)) return "Firefox";
|
|
14131
|
-
if (/Safari\//.test(ua)) return "Safari";
|
|
14132
|
-
return null;
|
|
14133
|
-
}
|
|
14134
|
-
function detectOS(ua) {
|
|
14135
|
-
if (/iPhone|iPad|iPod/.test(ua)) return "iOS";
|
|
14136
|
-
if (/Android/.test(ua)) return "Android";
|
|
14137
|
-
if (/Mac OS X/.test(ua)) return "macOS";
|
|
14138
|
-
if (/Windows NT/.test(ua)) return "Windows";
|
|
14139
|
-
if (/Linux/.test(ua)) return "Linux";
|
|
14140
|
-
return null;
|
|
14141
|
-
}
|
|
14142
|
-
function parseUserAgent(ua) {
|
|
14143
|
-
const browser = detectBrowser(ua);
|
|
14144
|
-
const os = detectOS(ua);
|
|
14145
|
-
if (browser && os) return `${os} \xB7 ${browser.toLowerCase()}`;
|
|
14146
|
-
if (os) return os;
|
|
14147
|
-
if (browser) return browser;
|
|
14148
|
-
return ua.slice(0, 48);
|
|
14149
|
-
}
|
|
14150
|
-
function formatRelative(iso, copy) {
|
|
14151
|
-
if (!iso) return "\u2014";
|
|
14152
|
-
const ts = new Date(iso).getTime();
|
|
14153
|
-
if (!Number.isFinite(ts)) return "\u2014";
|
|
14154
|
-
const diffSec = Math.round((Date.now() - ts) / 1e3);
|
|
14155
|
-
if (diffSec < 0) return copy.justNow;
|
|
14156
|
-
if (diffSec < 60) return copy.secondsAgo(diffSec);
|
|
14157
|
-
const diffMin = Math.round(diffSec / 60);
|
|
14158
|
-
if (diffMin < 60) return copy.minutesAgo(diffMin);
|
|
14159
|
-
const diffHr = Math.round(diffMin / 60);
|
|
14160
|
-
if (diffHr < 24) return copy.hoursAgo(diffHr);
|
|
14161
|
-
const diffDay = Math.round(diffHr / 24);
|
|
14162
|
-
if (diffDay < 30) return copy.daysAgo(diffDay);
|
|
14163
|
-
return new Date(iso).toLocaleDateString(void 0, { month: "short", day: "numeric", year: "numeric" });
|
|
14164
|
-
}
|
|
14165
|
-
function shortIp(hash) {
|
|
14166
|
-
if (!hash) return "";
|
|
14167
|
-
return hash.slice(0, 8);
|
|
14168
|
-
}
|
|
14169
|
-
function deviceKind(session) {
|
|
14170
|
-
const value = `${session.deviceLabel ?? ""} ${session.userAgent ?? ""}`.toLowerCase();
|
|
14171
|
-
if (/ipad|tablet/.test(value)) return "tablet";
|
|
14172
|
-
if (/android|iphone|ipod|mobile|phone/.test(value)) return "phone";
|
|
14173
|
-
return "desktop";
|
|
14174
|
-
}
|
|
14175
|
-
function DeviceIcon({ kind, size = "small" }) {
|
|
14176
|
-
const dimensions = size === "large" ? 30 : 18;
|
|
14177
|
-
if (kind === "phone") {
|
|
14178
|
-
return /* @__PURE__ */ jsxs("svg", { width: dimensions, height: dimensions, viewBox: "0 0 24 24", fill: "none", "aria-hidden": true, children: [
|
|
14179
|
-
/* @__PURE__ */ jsx("rect", { x: "7", y: "2.5", width: "10", height: "19", rx: "2.5", stroke: "currentColor", strokeWidth: "1.8" }),
|
|
14180
|
-
/* @__PURE__ */ jsx("path", { d: "M10.5 5h3M11 18.5h2", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })
|
|
14181
|
-
] });
|
|
14182
|
-
}
|
|
14183
|
-
if (kind === "tablet") {
|
|
14184
|
-
return /* @__PURE__ */ jsxs("svg", { width: dimensions, height: dimensions, viewBox: "0 0 24 24", fill: "none", "aria-hidden": true, children: [
|
|
14185
|
-
/* @__PURE__ */ jsx("rect", { x: "4.5", y: "2.5", width: "15", height: "19", rx: "2", stroke: "currentColor", strokeWidth: "1.8" }),
|
|
14186
|
-
/* @__PURE__ */ jsx("path", { d: "M11 18.5h2", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })
|
|
14187
|
-
] });
|
|
14188
|
-
}
|
|
14189
|
-
return /* @__PURE__ */ jsxs("svg", { width: dimensions, height: dimensions, viewBox: "0 0 24 24", fill: "none", "aria-hidden": true, children: [
|
|
14190
|
-
/* @__PURE__ */ jsx("rect", { x: "3", y: "3.5", width: "18", height: "12", rx: "1.8", stroke: "currentColor", strokeWidth: "1.8" }),
|
|
14191
|
-
/* @__PURE__ */ jsx("path", { d: "M8 20.5h8M12 15.5v5", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round" })
|
|
14192
|
-
] });
|
|
14193
|
-
}
|
|
14194
|
-
function CheckIcon() {
|
|
14195
|
-
return /* @__PURE__ */ jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "m2.5 6.2 2.1 2.1L9.6 3.6", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
14196
|
-
}
|
|
14197
|
-
function CloseIcon() {
|
|
14198
|
-
return /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "m3 3 8 8M11 3l-8 8", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round" }) });
|
|
14199
|
-
}
|
|
14200
|
-
function SessionsModalTemplate({
|
|
14201
|
-
theme,
|
|
14202
|
-
accentColor,
|
|
14203
|
-
styleOverrides,
|
|
14204
|
-
state,
|
|
14205
|
-
revokingFamilyId,
|
|
14206
|
-
signingOutEverywhere,
|
|
14207
|
-
revokeError,
|
|
14208
|
-
onRefresh,
|
|
14209
|
-
onRevoke,
|
|
14210
|
-
onLogoutEverywhere,
|
|
14211
|
-
onClose,
|
|
14212
|
-
language: languageProp
|
|
14213
|
-
}) {
|
|
14214
|
-
const language = useInheritedLanguage(languageProp);
|
|
14215
|
-
const copy = SESSIONS_COPY[language];
|
|
14216
|
-
const cssVars = buildModalCssVars(theme, accentColor, styleOverrides);
|
|
14217
|
-
const isLoading = state.step === "loading";
|
|
14218
|
-
const sessions = state.step === "loaded" ? state.sessions : [];
|
|
14219
|
-
const currentSession = sessions.find((s) => s.current);
|
|
14220
|
-
const otherSessions = sessions.filter((s) => !s.current);
|
|
14221
|
-
const otherCount = otherSessions.length;
|
|
14222
|
-
return /* @__PURE__ */ jsxs(
|
|
14223
|
-
"div",
|
|
14224
|
-
{
|
|
14225
|
-
className: "pollar-modal-card pollar-sessions-modal",
|
|
14226
|
-
"data-theme": theme,
|
|
14227
|
-
style: cssVars,
|
|
14228
|
-
onClick: (e) => e.stopPropagation(),
|
|
14229
|
-
children: [
|
|
14230
|
-
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header", children: [
|
|
14231
|
-
/* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: copy.title }),
|
|
14232
|
-
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header-actions", children: [
|
|
14569
|
+
type: "button",
|
|
14570
|
+
className: "pollar-btn-primary",
|
|
14571
|
+
onClick: () => void fund(),
|
|
14572
|
+
disabled: busy !== null || !selectedRoute || !(Number(fundAmount) >= 1),
|
|
14573
|
+
children: busy === "fund-send" ? copy.sending : copy.fundFromWallet
|
|
14574
|
+
}
|
|
14575
|
+
) }),
|
|
14576
|
+
confirmation && /* @__PURE__ */ jsx(InlineConfirm, { confirmation, language }),
|
|
14577
|
+
!confirmation && sentFunding && (() => {
|
|
14578
|
+
const f = sentFunding;
|
|
14579
|
+
const state = (f.route === "DIRECT" ? copy.fundingSolana[f.status] : void 0) ?? copy.funding[f.status];
|
|
14580
|
+
const steps = FUNDING_STEPS[f.route];
|
|
14581
|
+
const step = steps.indexOf(f.status) + 1;
|
|
14582
|
+
const inflight = FUNDING_INFLIGHT.has(f.status);
|
|
14583
|
+
const failed = f.status === "FAILED";
|
|
14584
|
+
return /* @__PURE__ */ jsxs(
|
|
14585
|
+
"div",
|
|
14586
|
+
{
|
|
14587
|
+
className: `pollar-outcome${failed ? " pollar-outcome-bad" : ""}${inflight ? " pollar-outcome-busy" : ""}`,
|
|
14588
|
+
role: "status",
|
|
14589
|
+
children: [
|
|
14590
|
+
/* @__PURE__ */ jsxs("p", { className: "pollar-outcome-main", children: [
|
|
14591
|
+
inflight ? /* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm", "aria-hidden": true }) : /* @__PURE__ */ jsx(OutcomeIcon, { ok: !failed }),
|
|
14592
|
+
state?.title ?? f.status,
|
|
14593
|
+
" \xB7 ",
|
|
14594
|
+
money(f.amount, "USD", language)
|
|
14595
|
+
] }),
|
|
14596
|
+
inflight && step > 0 && /* @__PURE__ */ jsxs("p", { className: "pollar-outcome-note", children: [
|
|
14597
|
+
copy.stepOf(step, steps.length),
|
|
14598
|
+
" \xB7",
|
|
14599
|
+
" ",
|
|
14600
|
+
f.error === CREDIT_DELAYED ? copy.fundingProblem.delayed : state?.hint
|
|
14601
|
+
] }),
|
|
14602
|
+
failed && /* @__PURE__ */ jsx("p", { className: "pollar-outcome-note", children: fundingProblemText(f.error, copy) })
|
|
14603
|
+
]
|
|
14604
|
+
}
|
|
14605
|
+
);
|
|
14606
|
+
})(),
|
|
14607
|
+
earlierFundings.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14608
|
+
/* @__PURE__ */ jsx("p", { className: "pollar-card-section-title", children: copy.yourFundings }),
|
|
14609
|
+
earlierFundings.map((f) => {
|
|
14610
|
+
const state = (f.route === "DIRECT" ? copy.fundingSolana[f.status] : void 0) ?? copy.funding[f.status];
|
|
14611
|
+
const steps = FUNDING_STEPS[f.route];
|
|
14612
|
+
const step = steps.indexOf(f.status) + 1;
|
|
14613
|
+
const inflight = FUNDING_INFLIGHT.has(f.status);
|
|
14614
|
+
return /* @__PURE__ */ jsxs("div", { className: "pollar-card-tx", "aria-busy": inflight, children: [
|
|
14615
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
14616
|
+
/* @__PURE__ */ jsxs("span", { className: "pollar-card-funding-title", children: [
|
|
14617
|
+
inflight && /* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm", "aria-hidden": true }),
|
|
14618
|
+
state?.title ?? f.status
|
|
14619
|
+
] }),
|
|
14620
|
+
inflight && step > 0 && /* @__PURE__ */ jsxs("span", { className: "pollar-card-tx-meta", role: "status", children: [
|
|
14621
|
+
copy.stepOf(step, steps.length),
|
|
14622
|
+
" \xB7",
|
|
14623
|
+
" ",
|
|
14624
|
+
f.error === CREDIT_DELAYED ? copy.fundingProblem.delayed : state?.hint
|
|
14625
|
+
] }),
|
|
14626
|
+
/* @__PURE__ */ jsxs("span", { className: "pollar-card-tx-meta", children: [
|
|
14627
|
+
new Date(f.createdAt).toLocaleString(),
|
|
14628
|
+
f.status === "FAILED" ? ` \xB7 ${fundingProblemText(f.error, copy)}` : ""
|
|
14629
|
+
] })
|
|
14630
|
+
] }),
|
|
14631
|
+
/* @__PURE__ */ jsx("div", { className: "pollar-card-tx-amount", "data-direction": f.status === "CREDITED" ? "credit" : void 0, children: money(f.amount, "USD", language) })
|
|
14632
|
+
] }, f.id);
|
|
14633
|
+
}),
|
|
14634
|
+
fundingsInflight && /* @__PURE__ */ jsx("p", { className: "pollar-card-note", children: copy.canClose })
|
|
14635
|
+
] }),
|
|
14636
|
+
!showManual && /* @__PURE__ */ jsxs("p", { className: "pollar-card-note", children: [
|
|
14637
|
+
copy.preferOtherWallet,
|
|
14638
|
+
" ",
|
|
14233
14639
|
/* @__PURE__ */ jsx(
|
|
14234
14640
|
"button",
|
|
14235
14641
|
{
|
|
14236
14642
|
type: "button",
|
|
14237
|
-
className: "pollar-
|
|
14238
|
-
onClick:
|
|
14239
|
-
disabled:
|
|
14240
|
-
|
|
14241
|
-
title: copy.refresh,
|
|
14242
|
-
children: /* @__PURE__ */ jsx(RefreshIcon, { spinning: isLoading })
|
|
14643
|
+
className: "pollar-card-link",
|
|
14644
|
+
onClick: () => void showManualAddress(),
|
|
14645
|
+
disabled: busy !== null,
|
|
14646
|
+
children: copy.showDeposit
|
|
14243
14647
|
}
|
|
14244
|
-
)
|
|
14245
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-modal-close", onClick: onClose, "aria-label": copy.close, title: copy.close, children: /* @__PURE__ */ jsx(CloseIcon, {}) })
|
|
14246
|
-
] })
|
|
14247
|
-
] }),
|
|
14248
|
-
/* @__PURE__ */ jsxs("div", { className: "pollar-sessions-list", children: [
|
|
14249
|
-
(state.step === "idle" || isLoading) && /* @__PURE__ */ jsxs("div", { className: "pollar-loading-block", children: [
|
|
14250
|
-
/* @__PURE__ */ jsx("div", { className: "pollar-spinner" }),
|
|
14251
|
-
/* @__PURE__ */ jsx("span", { children: copy.loading })
|
|
14252
|
-
] }),
|
|
14253
|
-
state.step === "error" && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: state.message }),
|
|
14254
|
-
state.step === "loaded" && sessions.length === 0 && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: copy.empty }),
|
|
14255
|
-
state.step === "loaded" && currentSession && /* @__PURE__ */ jsxs("div", { className: "pollar-sessions-current-card", children: [
|
|
14256
|
-
/* @__PURE__ */ jsxs("div", { className: "pollar-sessions-current-icon-wrap", children: [
|
|
14257
|
-
/* @__PURE__ */ jsx(DeviceIcon, { kind: deviceKind(currentSession), size: "large" }),
|
|
14258
|
-
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-current-check", children: /* @__PURE__ */ jsx(CheckIcon, {}) })
|
|
14259
|
-
] }),
|
|
14260
|
-
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-current-label", children: copy.thisDevice }),
|
|
14261
|
-
/* @__PURE__ */ jsx("strong", { className: "pollar-sessions-current-device", children: describeDevice(currentSession, copy) }),
|
|
14262
|
-
/* @__PURE__ */ jsxs("div", { className: "pollar-sessions-current-status", children: [
|
|
14263
|
-
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-status-dot" }),
|
|
14264
|
-
/* @__PURE__ */ jsx("span", { children: copy.activeNow }),
|
|
14265
|
-
currentSession.ipHash && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14266
|
-
/* @__PURE__ */ jsx("span", { children: "\xB7" }),
|
|
14267
|
-
/* @__PURE__ */ jsxs("span", { title: `ip-hash ${currentSession.ipHash}`, children: [
|
|
14268
|
-
"IP ",
|
|
14269
|
-
shortIp(currentSession.ipHash)
|
|
14270
|
-
] })
|
|
14271
|
-
] })
|
|
14272
|
-
] })
|
|
14273
|
-
] }),
|
|
14274
|
-
state.step === "loaded" && otherSessions.length > 0 && /* @__PURE__ */ jsxs("section", { className: "pollar-sessions-other-section", "aria-labelledby": "pollar-other-devices-heading", children: [
|
|
14275
|
-
/* @__PURE__ */ jsxs("h3", { id: "pollar-other-devices-heading", className: "pollar-sessions-section-title", children: [
|
|
14276
|
-
copy.otherDevices,
|
|
14277
|
-
" ",
|
|
14278
|
-
/* @__PURE__ */ jsx("span", { children: otherCount })
|
|
14279
|
-
] }),
|
|
14280
|
-
/* @__PURE__ */ jsx("div", { className: "pollar-sessions-grid", children: otherSessions.map((s) => {
|
|
14281
|
-
const isRevoking = revokingFamilyId === s.familyId;
|
|
14282
|
-
return /* @__PURE__ */ jsxs("div", { className: "pollar-sessions-item", children: [
|
|
14283
|
-
/* @__PURE__ */ jsxs("div", { className: "pollar-sessions-item-top", children: [
|
|
14284
|
-
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-item-icon", children: /* @__PURE__ */ jsx(DeviceIcon, { kind: deviceKind(s) }) }),
|
|
14285
|
-
/* @__PURE__ */ jsx(
|
|
14286
|
-
"button",
|
|
14287
|
-
{
|
|
14288
|
-
type: "button",
|
|
14289
|
-
className: "pollar-sessions-item-revoke",
|
|
14290
|
-
onClick: () => onRevoke(s.familyId),
|
|
14291
|
-
disabled: isRevoking || signingOutEverywhere,
|
|
14292
|
-
"aria-label": copy.signOutDevice(describeDevice(s, copy)),
|
|
14293
|
-
title: isRevoking ? copy.signingOut : copy.signOutThisDevice,
|
|
14294
|
-
children: isRevoking ? /* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm" }) : /* @__PURE__ */ jsx(CloseIcon, {})
|
|
14295
|
-
}
|
|
14296
|
-
)
|
|
14297
|
-
] }),
|
|
14298
|
-
/* @__PURE__ */ jsx("strong", { className: "pollar-sessions-item-device", children: describeDevice(s, copy) }),
|
|
14299
|
-
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-item-meta", children: formatRelative(s.lastUsedAt ?? s.createdAt, copy) })
|
|
14300
|
-
] }, s.familyId);
|
|
14301
|
-
}) })
|
|
14648
|
+
)
|
|
14302
14649
|
] }),
|
|
14303
|
-
|
|
14304
|
-
|
|
14305
|
-
|
|
14306
|
-
|
|
14307
|
-
|
|
14308
|
-
|
|
14309
|
-
|
|
14310
|
-
|
|
14311
|
-
|
|
14312
|
-
|
|
14313
|
-
|
|
14314
|
-
|
|
14315
|
-
|
|
14316
|
-
|
|
14317
|
-
|
|
14318
|
-
|
|
14319
|
-
|
|
14320
|
-
|
|
14321
|
-
);
|
|
14322
|
-
}
|
|
14323
|
-
function SessionsModal({ onClose }) {
|
|
14324
|
-
const { getClient, styles, sessions } = usePollar();
|
|
14325
|
-
const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
|
|
14326
|
-
const language = useModalLanguage();
|
|
14327
|
-
const copy = SESSIONS_COPY[language];
|
|
14328
|
-
const [revokingFamilyId, setRevokingFamilyId] = useState(null);
|
|
14329
|
-
const [signingOutEverywhere, setSigningOutEverywhere] = useState(false);
|
|
14330
|
-
const [revokeError, setRevokeError] = useState(null);
|
|
14331
|
-
const load = useCallback(() => {
|
|
14332
|
-
void getClient().fetchSessions();
|
|
14333
|
-
}, [getClient]);
|
|
14334
|
-
useEffect(() => {
|
|
14335
|
-
load();
|
|
14336
|
-
}, [load]);
|
|
14337
|
-
const onCloseRef = useRef(onClose);
|
|
14338
|
-
onCloseRef.current = onClose;
|
|
14339
|
-
useEffect(() => {
|
|
14340
|
-
return getClient().onAuthStateChange((authState) => {
|
|
14341
|
-
if (authState.step === "idle") onCloseRef.current();
|
|
14342
|
-
});
|
|
14343
|
-
}, [getClient]);
|
|
14344
|
-
const handleRevoke = useCallback(
|
|
14345
|
-
async (familyId) => {
|
|
14346
|
-
setRevokingFamilyId(familyId);
|
|
14347
|
-
setRevokeError(null);
|
|
14348
|
-
try {
|
|
14349
|
-
await getClient().revokeSession(familyId);
|
|
14350
|
-
} catch {
|
|
14351
|
-
setRevokeError(copy.revokeFailed);
|
|
14352
|
-
} finally {
|
|
14353
|
-
setRevokingFamilyId(null);
|
|
14354
|
-
load();
|
|
14355
|
-
}
|
|
14356
|
-
},
|
|
14357
|
-
[getClient, load, copy]
|
|
14358
|
-
);
|
|
14359
|
-
const handleLogoutEverywhere = useCallback(async () => {
|
|
14360
|
-
setSigningOutEverywhere(true);
|
|
14361
|
-
try {
|
|
14362
|
-
await getClient().logoutEverywhere();
|
|
14363
|
-
onClose();
|
|
14364
|
-
} catch {
|
|
14365
|
-
setSigningOutEverywhere(false);
|
|
14366
|
-
}
|
|
14367
|
-
}, [getClient, onClose]);
|
|
14368
|
-
return /* @__PURE__ */ jsx(PollarOverlay, { style: overlayStyle, onClick: onClose, children: /* @__PURE__ */ jsx(
|
|
14369
|
-
SessionsModalTemplate,
|
|
14370
|
-
{
|
|
14371
|
-
theme,
|
|
14372
|
-
accentColor,
|
|
14373
|
-
styleOverrides,
|
|
14374
|
-
state: sessions,
|
|
14375
|
-
revokingFamilyId,
|
|
14376
|
-
signingOutEverywhere,
|
|
14377
|
-
revokeError,
|
|
14378
|
-
onRefresh: () => load(),
|
|
14379
|
-
onRevoke: (familyId) => void handleRevoke(familyId),
|
|
14380
|
-
onLogoutEverywhere: () => void handleLogoutEverywhere(),
|
|
14381
|
-
onClose,
|
|
14382
|
-
language
|
|
14383
|
-
}
|
|
14384
|
-
) });
|
|
14385
|
-
}
|
|
14386
|
-
function useCosign() {
|
|
14387
|
-
const { getClient, isAuthenticated } = usePollar();
|
|
14388
|
-
const [state, setState] = useState({ pending: [] });
|
|
14389
|
-
const [loaded, setLoaded] = useState(false);
|
|
14390
|
-
useEffect(() => getClient().onCosignStateChange(setState), [getClient]);
|
|
14391
|
-
const refresh = useCallback(async () => {
|
|
14392
|
-
if (!isAuthenticated) return;
|
|
14393
|
-
try {
|
|
14394
|
-
await getClient().cosign.pending();
|
|
14395
|
-
} finally {
|
|
14396
|
-
setLoaded(true);
|
|
14397
|
-
}
|
|
14398
|
-
}, [getClient, isAuthenticated]);
|
|
14399
|
-
useEffect(() => {
|
|
14400
|
-
void refresh();
|
|
14401
|
-
}, [refresh]);
|
|
14402
|
-
return {
|
|
14403
|
-
pending: state.pending,
|
|
14404
|
-
...state.lastResolved ? { lastResolved: state.lastResolved } : {},
|
|
14405
|
-
loaded,
|
|
14406
|
-
refresh,
|
|
14407
|
-
approve: useCallback((request) => getClient().cosign.approve(request), [getClient]),
|
|
14408
|
-
reject: useCallback((request) => getClient().cosign.reject(request), [getClient]),
|
|
14409
|
-
verify: useCallback((request) => getClient().cosign.verify(request), [getClient]),
|
|
14410
|
-
inspectQuorum: useCallback(() => getClient().cosign.inspectQuorum(), [getClient]),
|
|
14411
|
-
devices: useCallback(() => getClient().cosign.devices(), [getClient]),
|
|
14412
|
-
revokeDevice: useCallback(
|
|
14413
|
-
(deviceId, options) => getClient().cosign.revokeDevice(deviceId, options),
|
|
14414
|
-
[getClient]
|
|
14415
|
-
),
|
|
14416
|
-
switchCustody: useCallback((to) => getClient().cosign.switchCustody(to), [getClient])
|
|
14417
|
-
};
|
|
14650
|
+
showManual && deposit?.map((d) => /* @__PURE__ */ jsxs("div", { className: "pollar-card-deposit", children: [
|
|
14651
|
+
/* @__PURE__ */ jsx("strong", { children: d.network }),
|
|
14652
|
+
" (",
|
|
14653
|
+
copy.chain(d.chainId),
|
|
14654
|
+
")",
|
|
14655
|
+
/* @__PURE__ */ jsx("code", { children: d.address }),
|
|
14656
|
+
/* @__PURE__ */ jsx(CopyButton, { value: d.address, label: copy.copyAddress, language }),
|
|
14657
|
+
/* @__PURE__ */ jsx("p", { className: "pollar-card-note", children: copy.sendOnly(d.tokens.map((t) => (t.currency ?? "token").toUpperCase()).join(` ${copy.or} `), d.network) })
|
|
14658
|
+
] }, d.network)),
|
|
14659
|
+
showManual && deposit?.length === 0 && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: copy.noDeposit }),
|
|
14660
|
+
showManual && /* @__PURE__ */ jsx("p", { className: "pollar-card-note", children: /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-card-link", onClick: () => setShowManual(false), children: copy.hideDeposit }) })
|
|
14661
|
+
] }),
|
|
14662
|
+
error && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: error }),
|
|
14663
|
+
loadFailed && /* @__PURE__ */ jsx("div", { className: "pollar-modal-actions", children: /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: retryLoad, children: copy.retry }) }),
|
|
14664
|
+
/* @__PURE__ */ jsx(PollarModalFooter, { language })
|
|
14665
|
+
]
|
|
14666
|
+
}
|
|
14667
|
+
) });
|
|
14418
14668
|
}
|
|
14419
14669
|
|
|
14420
|
-
// src/components/
|
|
14421
|
-
var
|
|
14670
|
+
// src/components/sessions-modal/sessions-copy.ts
|
|
14671
|
+
var SESSIONS_COPY = {
|
|
14422
14672
|
en: {
|
|
14423
|
-
title: "
|
|
14424
|
-
|
|
14673
|
+
title: "Active sessions",
|
|
14674
|
+
refresh: "Refresh",
|
|
14425
14675
|
close: "Close",
|
|
14426
|
-
|
|
14427
|
-
|
|
14428
|
-
|
|
14429
|
-
|
|
14430
|
-
|
|
14431
|
-
|
|
14432
|
-
|
|
14433
|
-
|
|
14434
|
-
|
|
14435
|
-
|
|
14436
|
-
|
|
14437
|
-
|
|
14438
|
-
|
|
14439
|
-
|
|
14440
|
-
|
|
14441
|
-
|
|
14442
|
-
|
|
14443
|
-
expiresIn: "Expires in",
|
|
14444
|
-
checking: "Checking...",
|
|
14445
|
-
verified: "Checked",
|
|
14446
|
-
checkedExact: "We checked this is exactly what you're approving.",
|
|
14447
|
-
notVerified: "Not verified:",
|
|
14448
|
-
reject: "Reject",
|
|
14449
|
-
rejecting: "Rejecting...",
|
|
14450
|
-
approve: "Approve",
|
|
14451
|
-
approving: "Approving...",
|
|
14452
|
-
genericError: "Something went wrong. Please try again.",
|
|
14453
|
-
unreachable: "We could not reach Pollar, so nothing was approved. Check your connection and approve again.",
|
|
14454
|
-
deviceNotLinked: "This device isn't linked to your wallet yet, so it can't approve. Add it with a device that already is, your passkey or your email.",
|
|
14455
|
-
linkDevice: "Link this device",
|
|
14456
|
-
transaction: "Transaction",
|
|
14457
|
-
operations: {
|
|
14458
|
-
payment: "Send",
|
|
14459
|
-
path_payment_strict_send: "Swap",
|
|
14460
|
-
change_trust: "Add asset",
|
|
14461
|
-
create_account: "Create account",
|
|
14462
|
-
invoke_contract: "Contract call",
|
|
14463
|
-
soroban_auth: "Authorize a contract call",
|
|
14464
|
-
manage_data: "Manage data",
|
|
14465
|
-
transfer: "Send",
|
|
14466
|
-
ramp_payment: "Ramp payment",
|
|
14467
|
-
cctp_burn: "Move USDC",
|
|
14468
|
-
swap: "Swap",
|
|
14469
|
-
earn_deposit: "Deposit",
|
|
14470
|
-
earn_withdraw: "Withdraw",
|
|
14471
|
-
evm_delegation: "Enable atomic transactions",
|
|
14472
|
-
provider_sign_in: "Confirm it's you",
|
|
14473
|
-
sep10: "Confirm it's you"
|
|
14474
|
-
}
|
|
14676
|
+
loading: "Loading\u2026",
|
|
14677
|
+
empty: "No active sessions.",
|
|
14678
|
+
thisDevice: "This device",
|
|
14679
|
+
activeNow: "Active now",
|
|
14680
|
+
otherDevices: "Other devices",
|
|
14681
|
+
signOutDevice: (device) => `Sign out ${device}`,
|
|
14682
|
+
signingOut: "Signing out\u2026",
|
|
14683
|
+
signOutThisDevice: "Sign out this device",
|
|
14684
|
+
noOtherDevices: "No other devices to sign out",
|
|
14685
|
+
signOutEverywhere: "Sign out everywhere",
|
|
14686
|
+
unknownDevice: "Unknown device",
|
|
14687
|
+
revokeFailed: "Could not sign out that device. Please try again.",
|
|
14688
|
+
justNow: "just now",
|
|
14689
|
+
secondsAgo: (n) => `${n}s ago`,
|
|
14690
|
+
minutesAgo: (n) => `${n}m ago`,
|
|
14691
|
+
hoursAgo: (n) => `${n}h ago`,
|
|
14692
|
+
daysAgo: (n) => `${n}d ago`
|
|
14475
14693
|
},
|
|
14476
14694
|
es: {
|
|
14477
|
-
title: "
|
|
14478
|
-
|
|
14695
|
+
title: "Sesiones activas",
|
|
14696
|
+
refresh: "Actualizar",
|
|
14479
14697
|
close: "Cerrar",
|
|
14480
|
-
|
|
14481
|
-
|
|
14482
|
-
|
|
14483
|
-
|
|
14484
|
-
|
|
14485
|
-
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14489
|
-
|
|
14490
|
-
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
|
|
14494
|
-
|
|
14495
|
-
|
|
14496
|
-
|
|
14497
|
-
expiresIn: "Vence en",
|
|
14498
|
-
checking: "Verificando...",
|
|
14499
|
-
verified: "Comprobada",
|
|
14500
|
-
checkedExact: "Comprobamos que esto es exactamente lo que est\xE1s aprobando.",
|
|
14501
|
-
notVerified: "Sin verificar:",
|
|
14502
|
-
reject: "Rechazar",
|
|
14503
|
-
rejecting: "Rechazando...",
|
|
14504
|
-
approve: "Aprobar",
|
|
14505
|
-
approving: "Aprobando...",
|
|
14506
|
-
genericError: "Algo sali\xF3 mal. Intenta de nuevo.",
|
|
14507
|
-
unreachable: "No pudimos conectar con Pollar, as\xED que no se aprob\xF3 nada. Revisa tu conexi\xF3n y aprueba de nuevo.",
|
|
14508
|
-
deviceNotLinked: "Este dispositivo a\xFAn no est\xE1 vinculado a tu billetera, as\xED que no puede aprobar. Agr\xE9galo con un dispositivo que ya lo est\xE9, tu passkey o tu email.",
|
|
14509
|
-
linkDevice: "Vincular este dispositivo",
|
|
14510
|
-
transaction: "Transacci\xF3n",
|
|
14511
|
-
operations: {
|
|
14512
|
-
payment: "Enviar",
|
|
14513
|
-
path_payment_strict_send: "Intercambiar",
|
|
14514
|
-
change_trust: "Agregar activo",
|
|
14515
|
-
create_account: "Crear cuenta",
|
|
14516
|
-
invoke_contract: "Llamada a contrato",
|
|
14517
|
-
soroban_auth: "Autorizar una llamada a contrato",
|
|
14518
|
-
manage_data: "Gestionar datos",
|
|
14519
|
-
transfer: "Enviar",
|
|
14520
|
-
ramp_payment: "Pago de rampa",
|
|
14521
|
-
cctp_burn: "Mover USDC",
|
|
14522
|
-
swap: "Intercambiar",
|
|
14523
|
-
earn_deposit: "Depositar",
|
|
14524
|
-
earn_withdraw: "Retirar",
|
|
14525
|
-
evm_delegation: "Activar transacciones at\xF3micas",
|
|
14526
|
-
provider_sign_in: "Confirma que eres t\xFA",
|
|
14527
|
-
sep10: "Confirma que eres t\xFA"
|
|
14528
|
-
}
|
|
14698
|
+
loading: "Cargando\u2026",
|
|
14699
|
+
empty: "No hay sesiones activas.",
|
|
14700
|
+
thisDevice: "Este dispositivo",
|
|
14701
|
+
activeNow: "Activa ahora",
|
|
14702
|
+
otherDevices: "Otros dispositivos",
|
|
14703
|
+
signOutDevice: (device) => `Cerrar sesi\xF3n en ${device}`,
|
|
14704
|
+
signingOut: "Cerrando sesi\xF3n\u2026",
|
|
14705
|
+
signOutThisDevice: "Cerrar sesi\xF3n en este dispositivo",
|
|
14706
|
+
noOtherDevices: "No hay otros dispositivos donde cerrar sesi\xF3n",
|
|
14707
|
+
signOutEverywhere: "Cerrar sesi\xF3n en todas partes",
|
|
14708
|
+
unknownDevice: "Dispositivo desconocido",
|
|
14709
|
+
revokeFailed: "No se pudo cerrar sesi\xF3n en ese dispositivo. Intenta de nuevo.",
|
|
14710
|
+
justNow: "justo ahora",
|
|
14711
|
+
secondsAgo: (n) => `hace ${n} s`,
|
|
14712
|
+
minutesAgo: (n) => `hace ${n} min`,
|
|
14713
|
+
hoursAgo: (n) => `hace ${n} h`,
|
|
14714
|
+
daysAgo: (n) => `hace ${n} d`
|
|
14529
14715
|
},
|
|
14530
14716
|
pt: {
|
|
14531
|
-
title: "
|
|
14532
|
-
|
|
14717
|
+
title: "Sess\xF5es ativas",
|
|
14718
|
+
refresh: "Atualizar",
|
|
14533
14719
|
close: "Fechar",
|
|
14534
|
-
|
|
14535
|
-
|
|
14536
|
-
|
|
14537
|
-
|
|
14538
|
-
|
|
14539
|
-
|
|
14540
|
-
|
|
14541
|
-
|
|
14542
|
-
|
|
14543
|
-
|
|
14544
|
-
|
|
14545
|
-
|
|
14546
|
-
|
|
14547
|
-
|
|
14548
|
-
|
|
14549
|
-
|
|
14550
|
-
|
|
14551
|
-
expiresIn: "Expira em",
|
|
14552
|
-
checking: "Verificando...",
|
|
14553
|
-
verified: "Conferida",
|
|
14554
|
-
checkedExact: "Conferimos que isto \xE9 exatamente o que voc\xEA est\xE1 aprovando.",
|
|
14555
|
-
notVerified: "N\xE3o verificada:",
|
|
14556
|
-
reject: "Rejeitar",
|
|
14557
|
-
rejecting: "Rejeitando...",
|
|
14558
|
-
approve: "Aprovar",
|
|
14559
|
-
approving: "Aprovando...",
|
|
14560
|
-
genericError: "Algo deu errado. Tente novamente.",
|
|
14561
|
-
unreachable: "N\xE3o conseguimos conectar \xE0 Pollar, ent\xE3o nada foi aprovado. Verifique sua conex\xE3o e aprove novamente.",
|
|
14562
|
-
deviceNotLinked: "Este dispositivo ainda n\xE3o est\xE1 vinculado \xE0 sua carteira, ent\xE3o n\xE3o pode aprovar. Adicione-o com um dispositivo que j\xE1 esteja, sua passkey ou seu email.",
|
|
14563
|
-
linkDevice: "Vincular este dispositivo",
|
|
14564
|
-
transaction: "Transa\xE7\xE3o",
|
|
14565
|
-
operations: {
|
|
14566
|
-
payment: "Enviar",
|
|
14567
|
-
path_payment_strict_send: "Trocar",
|
|
14568
|
-
change_trust: "Adicionar ativo",
|
|
14569
|
-
create_account: "Criar conta",
|
|
14570
|
-
invoke_contract: "Chamada de contrato",
|
|
14571
|
-
soroban_auth: "Autorizar uma chamada de contrato",
|
|
14572
|
-
manage_data: "Gerenciar dados",
|
|
14573
|
-
transfer: "Enviar",
|
|
14574
|
-
ramp_payment: "Pagamento de rampa",
|
|
14575
|
-
cctp_burn: "Mover USDC",
|
|
14576
|
-
swap: "Trocar",
|
|
14577
|
-
earn_deposit: "Depositar",
|
|
14578
|
-
earn_withdraw: "Sacar",
|
|
14579
|
-
evm_delegation: "Ativar transa\xE7\xF5es at\xF4micas",
|
|
14580
|
-
provider_sign_in: "Confirme que \xE9 voc\xEA",
|
|
14581
|
-
sep10: "Confirme que \xE9 voc\xEA"
|
|
14582
|
-
}
|
|
14720
|
+
loading: "Carregando\u2026",
|
|
14721
|
+
empty: "Nenhuma sess\xE3o ativa.",
|
|
14722
|
+
thisDevice: "Este dispositivo",
|
|
14723
|
+
activeNow: "Ativa agora",
|
|
14724
|
+
otherDevices: "Outros dispositivos",
|
|
14725
|
+
signOutDevice: (device) => `Sair de ${device}`,
|
|
14726
|
+
signingOut: "Saindo\u2026",
|
|
14727
|
+
signOutThisDevice: "Sair deste dispositivo",
|
|
14728
|
+
noOtherDevices: "N\xE3o h\xE1 outros dispositivos para sair",
|
|
14729
|
+
signOutEverywhere: "Sair de todos os dispositivos",
|
|
14730
|
+
unknownDevice: "Dispositivo desconhecido",
|
|
14731
|
+
revokeFailed: "N\xE3o foi poss\xEDvel sair desse dispositivo. Tente novamente.",
|
|
14732
|
+
justNow: "agora mesmo",
|
|
14733
|
+
secondsAgo: (n) => `h\xE1 ${n} s`,
|
|
14734
|
+
minutesAgo: (n) => `h\xE1 ${n} min`,
|
|
14735
|
+
hoursAgo: (n) => `h\xE1 ${n} h`,
|
|
14736
|
+
daysAgo: (n) => `h\xE1 ${n} d`
|
|
14583
14737
|
}
|
|
14584
14738
|
};
|
|
14585
|
-
function
|
|
14586
|
-
|
|
14587
|
-
|
|
14739
|
+
function describeDevice(s, copy) {
|
|
14740
|
+
if (s.deviceLabel) return normalizeDeviceLabel(s.deviceLabel);
|
|
14741
|
+
if (!s.userAgent) return copy.unknownDevice;
|
|
14742
|
+
return parseUserAgent(s.userAgent);
|
|
14743
|
+
}
|
|
14744
|
+
function normalizeDeviceLabel(label) {
|
|
14745
|
+
const parts = label.replace(/\s+/g, " ").split(/ (?:[—–-]|·) /);
|
|
14746
|
+
if (parts.length === 2 && parts[1] !== void 0) return `${parts[0]} \xB7 ${parts[1].toLowerCase()}`;
|
|
14747
|
+
return label;
|
|
14748
|
+
}
|
|
14749
|
+
function detectBrowser(ua) {
|
|
14750
|
+
if (/Edg\//.test(ua)) return "Edge";
|
|
14751
|
+
if (/OPR\//.test(ua)) return "Opera";
|
|
14752
|
+
if (/(Chrome|CriOS)\//.test(ua)) return "Chrome";
|
|
14753
|
+
if (/(Firefox|FxiOS)\//.test(ua)) return "Firefox";
|
|
14754
|
+
if (/Safari\//.test(ua)) return "Safari";
|
|
14755
|
+
return null;
|
|
14756
|
+
}
|
|
14757
|
+
function detectOS(ua) {
|
|
14758
|
+
if (/iPhone|iPad|iPod/.test(ua)) return "iOS";
|
|
14759
|
+
if (/Android/.test(ua)) return "Android";
|
|
14760
|
+
if (/Mac OS X/.test(ua)) return "macOS";
|
|
14761
|
+
if (/Windows NT/.test(ua)) return "Windows";
|
|
14762
|
+
if (/Linux/.test(ua)) return "Linux";
|
|
14763
|
+
return null;
|
|
14588
14764
|
}
|
|
14589
|
-
function
|
|
14590
|
-
const
|
|
14591
|
-
|
|
14592
|
-
|
|
14593
|
-
|
|
14594
|
-
|
|
14765
|
+
function parseUserAgent(ua) {
|
|
14766
|
+
const browser = detectBrowser(ua);
|
|
14767
|
+
const os = detectOS(ua);
|
|
14768
|
+
if (browser && os) return `${os} \xB7 ${browser.toLowerCase()}`;
|
|
14769
|
+
if (os) return os;
|
|
14770
|
+
if (browser) return browser;
|
|
14771
|
+
return ua.slice(0, 48);
|
|
14595
14772
|
}
|
|
14596
|
-
function
|
|
14597
|
-
if (
|
|
14598
|
-
|
|
14599
|
-
if (
|
|
14600
|
-
|
|
14601
|
-
return copy.
|
|
14773
|
+
function formatRelative(iso, copy) {
|
|
14774
|
+
if (!iso) return "\u2014";
|
|
14775
|
+
const ts = new Date(iso).getTime();
|
|
14776
|
+
if (!Number.isFinite(ts)) return "\u2014";
|
|
14777
|
+
const diffSec = Math.round((Date.now() - ts) / 1e3);
|
|
14778
|
+
if (diffSec < 0) return copy.justNow;
|
|
14779
|
+
if (diffSec < 60) return copy.secondsAgo(diffSec);
|
|
14780
|
+
const diffMin = Math.round(diffSec / 60);
|
|
14781
|
+
if (diffMin < 60) return copy.minutesAgo(diffMin);
|
|
14782
|
+
const diffHr = Math.round(diffMin / 60);
|
|
14783
|
+
if (diffHr < 24) return copy.hoursAgo(diffHr);
|
|
14784
|
+
const diffDay = Math.round(diffHr / 24);
|
|
14785
|
+
if (diffDay < 30) return copy.daysAgo(diffDay);
|
|
14786
|
+
return new Date(iso).toLocaleDateString(void 0, { month: "short", day: "numeric", year: "numeric" });
|
|
14602
14787
|
}
|
|
14603
|
-
function
|
|
14604
|
-
|
|
14605
|
-
|
|
14606
|
-
|
|
14607
|
-
|
|
14608
|
-
}
|
|
14609
|
-
|
|
14610
|
-
|
|
14611
|
-
return
|
|
14612
|
-
|
|
14613
|
-
|
|
14614
|
-
|
|
14615
|
-
|
|
14616
|
-
|
|
14617
|
-
|
|
14618
|
-
|
|
14619
|
-
|
|
14620
|
-
|
|
14621
|
-
|
|
14622
|
-
|
|
14623
|
-
|
|
14624
|
-
|
|
14625
|
-
|
|
14626
|
-
|
|
14627
|
-
|
|
14628
|
-
|
|
14629
|
-
|
|
14788
|
+
function shortIp(hash) {
|
|
14789
|
+
if (!hash) return "";
|
|
14790
|
+
return hash.slice(0, 8);
|
|
14791
|
+
}
|
|
14792
|
+
function deviceKind(session) {
|
|
14793
|
+
const value = `${session.deviceLabel ?? ""} ${session.userAgent ?? ""}`.toLowerCase();
|
|
14794
|
+
if (/ipad|tablet/.test(value)) return "tablet";
|
|
14795
|
+
if (/android|iphone|ipod|mobile|phone/.test(value)) return "phone";
|
|
14796
|
+
return "desktop";
|
|
14797
|
+
}
|
|
14798
|
+
function DeviceIcon({ kind, size = "small" }) {
|
|
14799
|
+
const dimensions = size === "large" ? 30 : 18;
|
|
14800
|
+
if (kind === "phone") {
|
|
14801
|
+
return /* @__PURE__ */ jsxs("svg", { width: dimensions, height: dimensions, viewBox: "0 0 24 24", fill: "none", "aria-hidden": true, children: [
|
|
14802
|
+
/* @__PURE__ */ jsx("rect", { x: "7", y: "2.5", width: "10", height: "19", rx: "2.5", stroke: "currentColor", strokeWidth: "1.8" }),
|
|
14803
|
+
/* @__PURE__ */ jsx("path", { d: "M10.5 5h3M11 18.5h2", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })
|
|
14804
|
+
] });
|
|
14805
|
+
}
|
|
14806
|
+
if (kind === "tablet") {
|
|
14807
|
+
return /* @__PURE__ */ jsxs("svg", { width: dimensions, height: dimensions, viewBox: "0 0 24 24", fill: "none", "aria-hidden": true, children: [
|
|
14808
|
+
/* @__PURE__ */ jsx("rect", { x: "4.5", y: "2.5", width: "15", height: "19", rx: "2", stroke: "currentColor", strokeWidth: "1.8" }),
|
|
14809
|
+
/* @__PURE__ */ jsx("path", { d: "M11 18.5h2", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })
|
|
14810
|
+
] });
|
|
14811
|
+
}
|
|
14812
|
+
return /* @__PURE__ */ jsxs("svg", { width: dimensions, height: dimensions, viewBox: "0 0 24 24", fill: "none", "aria-hidden": true, children: [
|
|
14813
|
+
/* @__PURE__ */ jsx("rect", { x: "3", y: "3.5", width: "18", height: "12", rx: "1.8", stroke: "currentColor", strokeWidth: "1.8" }),
|
|
14814
|
+
/* @__PURE__ */ jsx("path", { d: "M8 20.5h8M12 15.5v5", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round" })
|
|
14630
14815
|
] });
|
|
14631
14816
|
}
|
|
14817
|
+
function CheckIcon() {
|
|
14818
|
+
return /* @__PURE__ */ jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "m2.5 6.2 2.1 2.1L9.6 3.6", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
14819
|
+
}
|
|
14632
14820
|
function CloseIcon2() {
|
|
14633
14821
|
return /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "m3 3 8 8M11 3l-8 8", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round" }) });
|
|
14634
14822
|
}
|
|
14635
|
-
function
|
|
14636
|
-
return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: [
|
|
14637
|
-
/* @__PURE__ */ jsx("circle", { cx: "7", cy: "7", r: "7", fill: "currentColor" }),
|
|
14638
|
-
/* @__PURE__ */ jsx("path", { d: "M3.5 7l2.5 2.5 4.5-5", stroke: "white", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round" })
|
|
14639
|
-
] });
|
|
14640
|
-
}
|
|
14641
|
-
function CosignModalTemplate({
|
|
14823
|
+
function SessionsModalTemplate({
|
|
14642
14824
|
theme,
|
|
14643
14825
|
accentColor,
|
|
14644
14826
|
styleOverrides,
|
|
14645
|
-
|
|
14646
|
-
|
|
14647
|
-
|
|
14648
|
-
|
|
14649
|
-
|
|
14650
|
-
|
|
14651
|
-
|
|
14652
|
-
onLinkDevice,
|
|
14653
|
-
lastResolved,
|
|
14654
|
-
history = [],
|
|
14655
|
-
explorerUrlOf,
|
|
14656
|
-
closesIn = null,
|
|
14657
|
-
nextStep = null,
|
|
14658
|
-
language: languageProp,
|
|
14659
|
-
network,
|
|
14660
|
-
onSelect,
|
|
14661
|
-
onApprove,
|
|
14662
|
-
onReject,
|
|
14827
|
+
state,
|
|
14828
|
+
revokingFamilyId,
|
|
14829
|
+
signingOutEverywhere,
|
|
14830
|
+
revokeError,
|
|
14831
|
+
onRefresh,
|
|
14832
|
+
onRevoke,
|
|
14833
|
+
onLogoutEverywhere,
|
|
14663
14834
|
onClose,
|
|
14664
|
-
|
|
14665
|
-
onKeepOpen,
|
|
14666
|
-
onCloseAnyway
|
|
14835
|
+
language: languageProp
|
|
14667
14836
|
}) {
|
|
14668
14837
|
const language = useInheritedLanguage(languageProp);
|
|
14669
|
-
const copy =
|
|
14838
|
+
const copy = SESSIONS_COPY[language];
|
|
14670
14839
|
const cssVars = buildModalCssVars(theme, accentColor, styleOverrides);
|
|
14671
|
-
const
|
|
14672
|
-
const
|
|
14673
|
-
const
|
|
14674
|
-
const
|
|
14675
|
-
const
|
|
14676
|
-
{
|
|
14677
|
-
chain: request.network,
|
|
14678
|
-
network,
|
|
14679
|
-
operation: request.operation,
|
|
14680
|
-
summary: request.summary,
|
|
14681
|
-
details: request.details,
|
|
14682
|
-
signWith: request.account ?? request.signWith,
|
|
14683
|
-
raw: request.unsignedPayload,
|
|
14684
|
-
fallbackTitle: labelOf2(request, copy),
|
|
14685
|
-
...request.status === "PENDING" ? { extraRows: [{ label: copy.expiresIn, value: expiresIn(request, copy) }] } : {},
|
|
14686
|
-
appPaysFee: request.submit?.sponsored ?? request.appPaysFee,
|
|
14687
|
-
...request.submit?.hash ? { hash: { value: request.submit.hash, explorerUrl: explorerUrlOf?.(request) ?? null } } : {}
|
|
14688
|
-
},
|
|
14689
|
-
TX_REVIEW_COPY[language]
|
|
14690
|
-
);
|
|
14691
|
-
const review = current ? reviewOf(current) : null;
|
|
14692
|
-
const grouped = pending.length > 1;
|
|
14693
|
-
const shown = grouped ? null : current ?? (pending.length === 0 ? lastResolved : void 0) ?? null;
|
|
14694
|
-
const shownReview = shown ? shown === current ? review : reviewOf(shown) : null;
|
|
14695
|
-
const doneSteps = history.filter((r) => !(pending.length === 0 && r.id === lastResolved?.id));
|
|
14696
|
-
const heading = confirmingClose ? copy.closeTitle : grouped ? copy.manyPending(pending.length) : shownReview?.title ?? copy.title;
|
|
14697
|
-
const chip = current && !confirmingClose && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14698
|
-
!verification && !deviceNotLinked && /* @__PURE__ */ jsxs("span", { className: "pollar-cosign-chip", children: [
|
|
14699
|
-
/* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm", "aria-hidden": true }),
|
|
14700
|
-
copy.checking
|
|
14701
|
-
] }),
|
|
14702
|
-
verified && /* @__PURE__ */ jsxs(
|
|
14703
|
-
"button",
|
|
14704
|
-
{
|
|
14705
|
-
type: "button",
|
|
14706
|
-
className: "pollar-cosign-chip pollar-cosign-chip-ok",
|
|
14707
|
-
"aria-expanded": verifiedOpen,
|
|
14708
|
-
onClick: () => setVerifiedOpenFor(verifiedOpen ? null : current.id),
|
|
14709
|
-
children: [
|
|
14710
|
-
/* @__PURE__ */ jsx(VerifiedIcon, {}),
|
|
14711
|
-
copy.verified
|
|
14712
|
-
]
|
|
14713
|
-
}
|
|
14714
|
-
)
|
|
14715
|
-
] });
|
|
14840
|
+
const isLoading = state.step === "loading";
|
|
14841
|
+
const sessions = state.step === "loaded" ? state.sessions : [];
|
|
14842
|
+
const currentSession = sessions.find((s) => s.current);
|
|
14843
|
+
const otherSessions = sessions.filter((s) => !s.current);
|
|
14844
|
+
const otherCount = otherSessions.length;
|
|
14716
14845
|
return /* @__PURE__ */ jsxs(
|
|
14717
14846
|
"div",
|
|
14718
14847
|
{
|
|
14719
|
-
className: "pollar-modal-card pollar-
|
|
14848
|
+
className: "pollar-modal-card pollar-sessions-modal",
|
|
14720
14849
|
"data-theme": theme,
|
|
14721
14850
|
style: cssVars,
|
|
14722
14851
|
onClick: (e) => e.stopPropagation(),
|
|
14723
14852
|
children: [
|
|
14724
14853
|
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header", children: [
|
|
14725
|
-
/* @__PURE__ */
|
|
14726
|
-
|
|
14727
|
-
/* @__PURE__ */ jsx("span", { children: heading })
|
|
14728
|
-
] }),
|
|
14729
|
-
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header-actions", children: [
|
|
14730
|
-
!grouped && chip,
|
|
14731
|
-
!confirmingClose && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-modal-close", onClick: onClose, "aria-label": copy.close, title: copy.close, children: /* @__PURE__ */ jsx(CloseIcon2, {}) })
|
|
14732
|
-
] })
|
|
14733
|
-
] }),
|
|
14734
|
-
confirmingClose ? /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-leave", children: [
|
|
14735
|
-
/* @__PURE__ */ jsx("p", { className: "pollar-cosign-muted", children: copy.closeBody }),
|
|
14736
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-cosign-btn pollar-cosign-btn-primary", onClick: onKeepOpen, children: copy.backToSign }),
|
|
14737
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-cosign-text-btn", onClick: onCloseAnyway, children: copy.closeAnyway })
|
|
14738
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14739
|
-
doneSteps.map((r) => /* @__PURE__ */ jsx(StepRow, { request: r, review: reviewOf(r), copy, language }, r.id)),
|
|
14740
|
-
pending.length === 0 && (lastResolved && shownReview ? /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-detail", children: [
|
|
14741
|
-
/* @__PURE__ */ jsx(TxReview, { data: shownReview, language }, lastResolved.id),
|
|
14742
|
-
/* @__PURE__ */ jsxs("div", { className: `pollar-outcome${lastResolved.status === "APPROVED" ? "" : " pollar-outcome-bad"}`, children: [
|
|
14743
|
-
/* @__PURE__ */ jsxs("p", { className: "pollar-outcome-main", children: [
|
|
14744
|
-
/* @__PURE__ */ jsx(OutcomeIcon, { ok: lastResolved.status === "APPROVED" }),
|
|
14745
|
-
outcomeText(lastResolved, copy)
|
|
14746
|
-
] }),
|
|
14747
|
-
nextStep && /* @__PURE__ */ jsxs("p", { className: "pollar-outcome-note", children: [
|
|
14748
|
-
/* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm", "aria-hidden": true }),
|
|
14749
|
-
" ",
|
|
14750
|
-
copy.next(nextStep)
|
|
14751
|
-
] }),
|
|
14752
|
-
closesIn !== null && /* @__PURE__ */ jsx("p", { className: "pollar-outcome-note", children: copy.closingIn(closesIn) })
|
|
14753
|
-
] })
|
|
14754
|
-
] }) : /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-empty", children: [
|
|
14755
|
-
/* @__PURE__ */ jsx("p", { className: "pollar-cosign-muted", children: copy.nothingWaiting }),
|
|
14756
|
-
closesIn !== null && /* @__PURE__ */ jsx("p", { className: "pollar-cosign-muted pollar-cosign-closing", children: copy.closingIn(closesIn) })
|
|
14757
|
-
] })),
|
|
14758
|
-
grouped && /* @__PURE__ */ jsx("ul", { className: "pollar-cosign-list", children: pending.map((r) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
14759
|
-
"button",
|
|
14760
|
-
{
|
|
14761
|
-
type: "button",
|
|
14762
|
-
className: `pollar-cosign-item${current?.id === r.id ? " pollar-cosign-item-active" : ""}`,
|
|
14763
|
-
onClick: () => onSelect(r),
|
|
14764
|
-
children: [
|
|
14765
|
-
/* @__PURE__ */ jsxs("span", { className: "pollar-cosign-heading", children: [
|
|
14766
|
-
/* @__PURE__ */ jsx(TitleMark, { chain: r.network, asset: headlineAsset(reviewOf(r)) }),
|
|
14767
|
-
reviewOf(r).title
|
|
14768
|
-
] }),
|
|
14769
|
-
/* @__PURE__ */ jsx("span", { className: "pollar-cosign-muted", children: expiresIn(r, copy) })
|
|
14770
|
-
]
|
|
14771
|
-
}
|
|
14772
|
-
) }, r.id)) }),
|
|
14773
|
-
current && review && /* @__PURE__ */ jsxs("div", { className: `pollar-cosign-detail${grouped ? " pollar-cosign-detail-grouped" : ""}`, children: [
|
|
14774
|
-
grouped && /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-detail-head", children: [
|
|
14775
|
-
/* @__PURE__ */ jsx("p", { className: "pollar-cosign-detail-title", children: review.title }),
|
|
14776
|
-
chip
|
|
14777
|
-
] }),
|
|
14778
|
-
/* @__PURE__ */ jsx(
|
|
14779
|
-
TxReview,
|
|
14780
|
-
{
|
|
14781
|
-
data: review,
|
|
14782
|
-
language,
|
|
14783
|
-
detailsIntro: { title: copy.whyTitle, body: copy.whyBody },
|
|
14784
|
-
detailsAction: {
|
|
14785
|
-
label: busy === "rejecting" ? copy.rejecting : copy.rejectRequest,
|
|
14786
|
-
onClick: () => onReject(current),
|
|
14787
|
-
disabled: !!busy
|
|
14788
|
-
}
|
|
14789
|
-
},
|
|
14790
|
-
current.id
|
|
14791
|
-
),
|
|
14792
|
-
verified && verifiedOpen && /* @__PURE__ */ jsx("div", { className: "pollar-cosign-verify pollar-cosign-verify-ok", children: copy.checkedExact }),
|
|
14793
|
-
deviceNotLinked ? /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-verify pollar-cosign-verify-bad", children: [
|
|
14794
|
-
copy.deviceNotLinked,
|
|
14795
|
-
onLinkDevice && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-cosign-link", onClick: onLinkDevice, children: copy.linkDevice })
|
|
14796
|
-
] }) : verification && !verification.ok && /* @__PURE__ */ jsxs("div", { className: "pollar-cosign-verify pollar-cosign-verify-bad", children: [
|
|
14797
|
-
copy.notVerified,
|
|
14798
|
-
" ",
|
|
14799
|
-
verification.reason
|
|
14800
|
-
] }),
|
|
14801
|
-
error && /* @__PURE__ */ jsx("div", { className: "pollar-cosign-error", children: error }),
|
|
14854
|
+
/* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: copy.title }),
|
|
14855
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header-actions", children: [
|
|
14802
14856
|
/* @__PURE__ */ jsx(
|
|
14803
14857
|
"button",
|
|
14804
14858
|
{
|
|
14805
14859
|
type: "button",
|
|
14806
|
-
className: "pollar-
|
|
14807
|
-
|
|
14808
|
-
|
|
14809
|
-
|
|
14860
|
+
className: "pollar-modal-close",
|
|
14861
|
+
onClick: onRefresh,
|
|
14862
|
+
disabled: isLoading,
|
|
14863
|
+
"aria-label": copy.refresh,
|
|
14864
|
+
title: copy.refresh,
|
|
14865
|
+
children: /* @__PURE__ */ jsx(RefreshIcon, { spinning: isLoading })
|
|
14810
14866
|
}
|
|
14811
|
-
)
|
|
14867
|
+
),
|
|
14868
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-modal-close", onClick: onClose, "aria-label": copy.close, title: copy.close, children: /* @__PURE__ */ jsx(CloseIcon2, {}) })
|
|
14812
14869
|
] })
|
|
14813
14870
|
] }),
|
|
14871
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-sessions-list", children: [
|
|
14872
|
+
(state.step === "idle" || isLoading) && /* @__PURE__ */ jsxs("div", { className: "pollar-loading-block", children: [
|
|
14873
|
+
/* @__PURE__ */ jsx("div", { className: "pollar-spinner" }),
|
|
14874
|
+
/* @__PURE__ */ jsx("span", { children: copy.loading })
|
|
14875
|
+
] }),
|
|
14876
|
+
state.step === "error" && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: state.message }),
|
|
14877
|
+
state.step === "loaded" && sessions.length === 0 && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: copy.empty }),
|
|
14878
|
+
state.step === "loaded" && currentSession && /* @__PURE__ */ jsxs("div", { className: "pollar-sessions-current-card", children: [
|
|
14879
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-sessions-current-icon-wrap", children: [
|
|
14880
|
+
/* @__PURE__ */ jsx(DeviceIcon, { kind: deviceKind(currentSession), size: "large" }),
|
|
14881
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-current-check", children: /* @__PURE__ */ jsx(CheckIcon, {}) })
|
|
14882
|
+
] }),
|
|
14883
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-current-label", children: copy.thisDevice }),
|
|
14884
|
+
/* @__PURE__ */ jsx("strong", { className: "pollar-sessions-current-device", children: describeDevice(currentSession, copy) }),
|
|
14885
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-sessions-current-status", children: [
|
|
14886
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-status-dot" }),
|
|
14887
|
+
/* @__PURE__ */ jsx("span", { children: copy.activeNow }),
|
|
14888
|
+
currentSession.ipHash && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14889
|
+
/* @__PURE__ */ jsx("span", { children: "\xB7" }),
|
|
14890
|
+
/* @__PURE__ */ jsxs("span", { title: `ip-hash ${currentSession.ipHash}`, children: [
|
|
14891
|
+
"IP ",
|
|
14892
|
+
shortIp(currentSession.ipHash)
|
|
14893
|
+
] })
|
|
14894
|
+
] })
|
|
14895
|
+
] })
|
|
14896
|
+
] }),
|
|
14897
|
+
state.step === "loaded" && otherSessions.length > 0 && /* @__PURE__ */ jsxs("section", { className: "pollar-sessions-other-section", "aria-labelledby": "pollar-other-devices-heading", children: [
|
|
14898
|
+
/* @__PURE__ */ jsxs("h3", { id: "pollar-other-devices-heading", className: "pollar-sessions-section-title", children: [
|
|
14899
|
+
copy.otherDevices,
|
|
14900
|
+
" ",
|
|
14901
|
+
/* @__PURE__ */ jsx("span", { children: otherCount })
|
|
14902
|
+
] }),
|
|
14903
|
+
/* @__PURE__ */ jsx("div", { className: "pollar-sessions-grid", children: otherSessions.map((s) => {
|
|
14904
|
+
const isRevoking = revokingFamilyId === s.familyId;
|
|
14905
|
+
return /* @__PURE__ */ jsxs("div", { className: "pollar-sessions-item", children: [
|
|
14906
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-sessions-item-top", children: [
|
|
14907
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-item-icon", children: /* @__PURE__ */ jsx(DeviceIcon, { kind: deviceKind(s) }) }),
|
|
14908
|
+
/* @__PURE__ */ jsx(
|
|
14909
|
+
"button",
|
|
14910
|
+
{
|
|
14911
|
+
type: "button",
|
|
14912
|
+
className: "pollar-sessions-item-revoke",
|
|
14913
|
+
onClick: () => onRevoke(s.familyId),
|
|
14914
|
+
disabled: isRevoking || signingOutEverywhere,
|
|
14915
|
+
"aria-label": copy.signOutDevice(describeDevice(s, copy)),
|
|
14916
|
+
title: isRevoking ? copy.signingOut : copy.signOutThisDevice,
|
|
14917
|
+
children: isRevoking ? /* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm" }) : /* @__PURE__ */ jsx(CloseIcon2, {})
|
|
14918
|
+
}
|
|
14919
|
+
)
|
|
14920
|
+
] }),
|
|
14921
|
+
/* @__PURE__ */ jsx("strong", { className: "pollar-sessions-item-device", children: describeDevice(s, copy) }),
|
|
14922
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-sessions-item-meta", children: formatRelative(s.lastUsedAt ?? s.createdAt, copy) })
|
|
14923
|
+
] }, s.familyId);
|
|
14924
|
+
}) })
|
|
14925
|
+
] }),
|
|
14926
|
+
revokeError && /* @__PURE__ */ jsx("div", { className: "pollar-sessions-action-error", role: "alert", children: revokeError })
|
|
14927
|
+
] }),
|
|
14928
|
+
state.step === "loaded" && sessions.length > 0 && /* @__PURE__ */ jsx("div", { className: "pollar-sessions-actions", children: /* @__PURE__ */ jsx(
|
|
14929
|
+
"button",
|
|
14930
|
+
{
|
|
14931
|
+
className: "pollar-sessions-logout-all",
|
|
14932
|
+
onClick: onLogoutEverywhere,
|
|
14933
|
+
disabled: signingOutEverywhere || otherCount === 0,
|
|
14934
|
+
title: otherCount === 0 ? copy.noOtherDevices : void 0,
|
|
14935
|
+
children: signingOutEverywhere ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14936
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm pollar-spinner-current" }),
|
|
14937
|
+
copy.signingOut
|
|
14938
|
+
] }) : copy.signOutEverywhere
|
|
14939
|
+
}
|
|
14940
|
+
) }),
|
|
14814
14941
|
/* @__PURE__ */ jsx(PollarModalFooter, {})
|
|
14815
14942
|
]
|
|
14816
14943
|
}
|
|
14817
14944
|
);
|
|
14818
14945
|
}
|
|
14819
|
-
|
|
14820
|
-
|
|
14821
|
-
var NEXT_REQUEST_EVERY_MS = 2e3;
|
|
14822
|
-
function CosignModal({ nextStep = null, onClose }) {
|
|
14823
|
-
const { getClient, styles, network, openRecoveryModal } = usePollar();
|
|
14946
|
+
function SessionsModal({ onClose }) {
|
|
14947
|
+
const { getClient, styles, sessions } = usePollar();
|
|
14824
14948
|
const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
|
|
14825
|
-
const { pending, lastResolved, loaded, refresh, approve, reject, verify, inspectQuorum } = useCosign();
|
|
14826
14949
|
const language = useModalLanguage();
|
|
14827
|
-
const
|
|
14828
|
-
const [
|
|
14829
|
-
const [
|
|
14830
|
-
const [
|
|
14831
|
-
const
|
|
14832
|
-
|
|
14833
|
-
|
|
14834
|
-
useEffect(() => {
|
|
14835
|
-
let cancelled = false;
|
|
14836
|
-
inspectQuorum().then((q) => {
|
|
14837
|
-
if (cancelled || q.ok) return;
|
|
14838
|
-
if (q.code === "DEVICE_NOT_ENROLLED") setDeviceNotLinked(true);
|
|
14839
|
-
else setQuorumFailure(q.reason);
|
|
14840
|
-
}).catch(() => void 0);
|
|
14841
|
-
return () => {
|
|
14842
|
-
cancelled = true;
|
|
14843
|
-
};
|
|
14844
|
-
}, [inspectQuorum]);
|
|
14845
|
-
const current = pending.find((r) => r.id === selectedId) ?? pending[0] ?? null;
|
|
14846
|
-
const [history, setHistory] = useState([]);
|
|
14847
|
-
const resolvedBeforeOpen = useRef(lastResolved?.id);
|
|
14848
|
-
useEffect(() => {
|
|
14849
|
-
if (!lastResolved || lastResolved.id === resolvedBeforeOpen.current) return;
|
|
14850
|
-
setHistory((list) => [...list.filter((r) => r.id !== lastResolved.id), lastResolved]);
|
|
14851
|
-
}, [lastResolved]);
|
|
14852
|
-
const [askedToClose, setAskedToClose] = useState(false);
|
|
14853
|
-
const confirmingClose = askedToClose && pending.length > 0;
|
|
14854
|
-
const requestClose = () => pending.length > 0 ? setAskedToClose(true) : onClose();
|
|
14855
|
-
const currentRef = useRef(current);
|
|
14856
|
-
currentRef.current = current;
|
|
14857
|
-
const currentId = current?.id ?? null;
|
|
14950
|
+
const copy = SESSIONS_COPY[language];
|
|
14951
|
+
const [revokingFamilyId, setRevokingFamilyId] = useState(null);
|
|
14952
|
+
const [signingOutEverywhere, setSigningOutEverywhere] = useState(false);
|
|
14953
|
+
const [revokeError, setRevokeError] = useState(null);
|
|
14954
|
+
const load = useCallback(() => {
|
|
14955
|
+
void getClient().fetchSessions();
|
|
14956
|
+
}, [getClient]);
|
|
14858
14957
|
useEffect(() => {
|
|
14859
|
-
|
|
14860
|
-
|
|
14861
|
-
setVerification(null);
|
|
14862
|
-
setError(null);
|
|
14863
|
-
setApproveFailedFor(null);
|
|
14864
|
-
let cancelled = false;
|
|
14865
|
-
verify(request).then((v) => {
|
|
14866
|
-
if (!cancelled) setVerification(v);
|
|
14867
|
-
}).catch((err) => {
|
|
14868
|
-
if (!cancelled) setVerification({ ok: false, reason: err instanceof Error ? err.message : String(err) });
|
|
14869
|
-
});
|
|
14870
|
-
return () => {
|
|
14871
|
-
cancelled = true;
|
|
14872
|
-
};
|
|
14873
|
-
}, [currentId, verify]);
|
|
14958
|
+
load();
|
|
14959
|
+
}, [load]);
|
|
14874
14960
|
const onCloseRef = useRef(onClose);
|
|
14875
14961
|
onCloseRef.current = onClose;
|
|
14876
14962
|
useEffect(() => {
|
|
@@ -14878,87 +14964,45 @@ function CosignModal({ nextStep = null, onClose }) {
|
|
|
14878
14964
|
if (authState.step === "idle") onCloseRef.current();
|
|
14879
14965
|
});
|
|
14880
14966
|
}, [getClient]);
|
|
14881
|
-
const
|
|
14882
|
-
|
|
14883
|
-
|
|
14884
|
-
|
|
14885
|
-
useEffect(() => {
|
|
14886
|
-
if (!awaitingNext) return;
|
|
14887
|
-
const timer = setInterval(() => void refresh().catch(() => void 0), NEXT_REQUEST_EVERY_MS);
|
|
14888
|
-
return () => clearInterval(timer);
|
|
14889
|
-
}, [awaitingNext, refresh]);
|
|
14890
|
-
const [closesIn, setClosesIn] = useState(null);
|
|
14891
|
-
useEffect(() => {
|
|
14892
|
-
if (closeAfter === null) {
|
|
14893
|
-
setClosesIn(null);
|
|
14894
|
-
return;
|
|
14895
|
-
}
|
|
14896
|
-
let left = closeAfter;
|
|
14897
|
-
setClosesIn(left);
|
|
14898
|
-
const timer = setInterval(() => {
|
|
14899
|
-
left -= 1;
|
|
14900
|
-
if (left > 0) setClosesIn(left);
|
|
14901
|
-
else {
|
|
14902
|
-
clearInterval(timer);
|
|
14903
|
-
onCloseRef.current();
|
|
14904
|
-
}
|
|
14905
|
-
}, 1e3);
|
|
14906
|
-
return () => clearInterval(timer);
|
|
14907
|
-
}, [closeAfter, lastResolved?.id]);
|
|
14908
|
-
const run = useCallback(
|
|
14909
|
-
async (kind, request, action) => {
|
|
14910
|
-
setBusy(kind);
|
|
14911
|
-
setError(null);
|
|
14967
|
+
const handleRevoke = useCallback(
|
|
14968
|
+
async (familyId) => {
|
|
14969
|
+
setRevokingFamilyId(familyId);
|
|
14970
|
+
setRevokeError(null);
|
|
14912
14971
|
try {
|
|
14913
|
-
await
|
|
14914
|
-
} catch
|
|
14915
|
-
|
|
14916
|
-
setError(COSIGN_COPY[language].unreachable);
|
|
14917
|
-
void refresh().catch(() => void 0);
|
|
14918
|
-
return;
|
|
14919
|
-
}
|
|
14920
|
-
setError(
|
|
14921
|
-
transactionErrorMessage(isPollarApiError(err) ? err.code : null, err instanceof Error ? err.message : null, language)
|
|
14922
|
-
);
|
|
14923
|
-
if (kind === "approving" && !(isPollarApiError(err) && err.code === "SDK_COSIGN_GAS_PENDING"))
|
|
14924
|
-
setApproveFailedFor(request.id);
|
|
14972
|
+
await getClient().revokeSession(familyId);
|
|
14973
|
+
} catch {
|
|
14974
|
+
setRevokeError(copy.revokeFailed);
|
|
14925
14975
|
} finally {
|
|
14926
|
-
|
|
14976
|
+
setRevokingFamilyId(null);
|
|
14977
|
+
load();
|
|
14927
14978
|
}
|
|
14928
14979
|
},
|
|
14929
|
-
[
|
|
14980
|
+
[getClient, load, copy]
|
|
14930
14981
|
);
|
|
14931
|
-
|
|
14932
|
-
|
|
14982
|
+
const handleLogoutEverywhere = useCallback(async () => {
|
|
14983
|
+
setSigningOutEverywhere(true);
|
|
14984
|
+
try {
|
|
14985
|
+
await getClient().logoutEverywhere();
|
|
14986
|
+
onClose();
|
|
14987
|
+
} catch {
|
|
14988
|
+
setSigningOutEverywhere(false);
|
|
14989
|
+
}
|
|
14990
|
+
}, [getClient, onClose]);
|
|
14991
|
+
return /* @__PURE__ */ jsx(PollarOverlay, { style: overlayStyle, onClick: onClose, children: /* @__PURE__ */ jsx(
|
|
14992
|
+
SessionsModalTemplate,
|
|
14933
14993
|
{
|
|
14934
14994
|
theme,
|
|
14935
14995
|
accentColor,
|
|
14936
14996
|
styleOverrides,
|
|
14937
|
-
|
|
14938
|
-
|
|
14939
|
-
|
|
14940
|
-
|
|
14941
|
-
|
|
14942
|
-
|
|
14943
|
-
|
|
14944
|
-
|
|
14945
|
-
|
|
14946
|
-
openRecoveryModal();
|
|
14947
|
-
},
|
|
14948
|
-
...lastResolved ? { lastResolved } : {},
|
|
14949
|
-
closesIn,
|
|
14950
|
-
nextStep: awaitingNext ? nextStep : null,
|
|
14951
|
-
language,
|
|
14952
|
-
network,
|
|
14953
|
-
history,
|
|
14954
|
-
explorerUrlOf: (r) => r.submit?.hash ? explorerTxUrl(r.network, r.submit.hash, network) : null,
|
|
14955
|
-
onSelect: (r) => setSelectedId(r.id),
|
|
14956
|
-
onApprove: (r) => void run("approving", r, approve),
|
|
14957
|
-
onReject: (r) => void run("rejecting", r, reject),
|
|
14958
|
-
onClose: requestClose,
|
|
14959
|
-
confirmingClose,
|
|
14960
|
-
onKeepOpen: () => setAskedToClose(false),
|
|
14961
|
-
onCloseAnyway: onClose
|
|
14997
|
+
state: sessions,
|
|
14998
|
+
revokingFamilyId,
|
|
14999
|
+
signingOutEverywhere,
|
|
15000
|
+
revokeError,
|
|
15001
|
+
onRefresh: () => load(),
|
|
15002
|
+
onRevoke: (familyId) => void handleRevoke(familyId),
|
|
15003
|
+
onLogoutEverywhere: () => void handleLogoutEverywhere(),
|
|
15004
|
+
onClose,
|
|
15005
|
+
language
|
|
14962
15006
|
}
|
|
14963
15007
|
) });
|
|
14964
15008
|
}
|
|
@@ -15619,6 +15663,7 @@ function RecoveryModalTemplate(p) {
|
|
|
15619
15663
|
);
|
|
15620
15664
|
}
|
|
15621
15665
|
var APPROVAL_POLL_MS = 3e3;
|
|
15666
|
+
var RELOAD_AFTER_FAILURE_MS = 5e3;
|
|
15622
15667
|
var APPROVAL_WINDOW_MS = 15 * 6e4;
|
|
15623
15668
|
function errorText3(err, language) {
|
|
15624
15669
|
return cosignRefusalMessage(err, language) ?? transactionErrorMessage(isPollarApiError(err) ? err.code : null, err instanceof Error ? err.message : null, language);
|
|
@@ -15670,12 +15715,17 @@ function RecoveryModal({ onClose }) {
|
|
|
15670
15715
|
setError(null);
|
|
15671
15716
|
setNotice(null);
|
|
15672
15717
|
try {
|
|
15673
|
-
|
|
15674
|
-
|
|
15718
|
+
try {
|
|
15719
|
+
await action();
|
|
15720
|
+
} catch (err) {
|
|
15721
|
+
setError(errorText3(err, language));
|
|
15722
|
+
return;
|
|
15723
|
+
}
|
|
15724
|
+
await load().catch(() => {
|
|
15725
|
+
setTimeout(() => void load().catch(() => void 0), RELOAD_AFTER_FAILURE_MS);
|
|
15726
|
+
});
|
|
15675
15727
|
if (after?.notice) setNotice(after.notice);
|
|
15676
15728
|
if (after?.view) setView(after.view);
|
|
15677
|
-
} catch (err) {
|
|
15678
|
-
setError(errorText3(err, language));
|
|
15679
15729
|
} finally {
|
|
15680
15730
|
setBusy(null);
|
|
15681
15731
|
}
|
|
@@ -15699,10 +15749,10 @@ function RecoveryModal({ onClose }) {
|
|
|
15699
15749
|
setNotice(copy.deviceAdded);
|
|
15700
15750
|
return;
|
|
15701
15751
|
}
|
|
15702
|
-
const
|
|
15752
|
+
const stopPoll = startBackoffPoll(load, APPROVAL_POLL_MS);
|
|
15703
15753
|
const stop = setTimeout(() => setAwaitingApproval(false), APPROVAL_WINDOW_MS);
|
|
15704
15754
|
return () => {
|
|
15705
|
-
|
|
15755
|
+
stopPoll();
|
|
15706
15756
|
clearTimeout(stop);
|
|
15707
15757
|
};
|
|
15708
15758
|
}, [awaitingApproval, enrolled, load, copy]);
|
|
@@ -16911,12 +16961,17 @@ function PollarProvider({
|
|
|
16911
16961
|
const [sessionsModalOpen, setSessionsModalOpen] = useState(false);
|
|
16912
16962
|
const [cosignModalOpen, setCosignModalOpen] = useState(false);
|
|
16913
16963
|
const [cosignNextStep, setCosignNextStep] = useState(null);
|
|
16964
|
+
const [cosignHosts, setCosignHosts] = useState(0);
|
|
16965
|
+
const registerCosignHost = useCallback(() => {
|
|
16966
|
+
setCosignHosts((n) => n + 1);
|
|
16967
|
+
return () => setCosignHosts((n) => n - 1);
|
|
16968
|
+
}, []);
|
|
16914
16969
|
const [recoveryModalOpen, setRecoveryModalOpen] = useState(false);
|
|
16915
16970
|
const cosignPendingCount = useRef(0);
|
|
16916
16971
|
useEffect(() => {
|
|
16917
|
-
if (cosign.pending.length > cosignPendingCount.current) setCosignModalOpen(true);
|
|
16972
|
+
if (cosign.pending.length > cosignPendingCount.current && cosignHosts === 0) setCosignModalOpen(true);
|
|
16918
16973
|
cosignPendingCount.current = cosign.pending.length;
|
|
16919
|
-
}, [cosign.pending.length]);
|
|
16974
|
+
}, [cosign.pending.length, cosignHosts]);
|
|
16920
16975
|
useEffect(() => pollarClient.onCosignDeviceNotEnrolled(() => setRecoveryModalOpen(true)), [pollarClient]);
|
|
16921
16976
|
useEffect(() => pollarClient.onWalletRecoveryRequired(() => setRecoveryModalOpen(true)), [pollarClient]);
|
|
16922
16977
|
const [distributionRulesModalOpen, setDistributionRulesModalOpen] = useState(false);
|
|
@@ -16955,13 +17010,17 @@ function PollarProvider({
|
|
|
16955
17010
|
return;
|
|
16956
17011
|
}
|
|
16957
17012
|
let cancelled = false;
|
|
17013
|
+
let retry = null;
|
|
16958
17014
|
pollarClient.cosign.recovery.status().then((next) => {
|
|
16959
17015
|
if (!cancelled) setRecovery(next);
|
|
16960
|
-
}).catch(() => {
|
|
16961
|
-
if (
|
|
17016
|
+
}).catch((err) => {
|
|
17017
|
+
if (cancelled) return;
|
|
17018
|
+
if (isTransientFailure(err)) retry = setTimeout(() => setRecoveryTick((t) => t + 1), 5e3 + Math.random() * 5e3);
|
|
17019
|
+
else setRecovery(null);
|
|
16962
17020
|
});
|
|
16963
17021
|
return () => {
|
|
16964
17022
|
cancelled = true;
|
|
17023
|
+
if (retry) clearTimeout(retry);
|
|
16965
17024
|
};
|
|
16966
17025
|
}, [pollarClient, hasSession, walletAddress, recoveryTick]);
|
|
16967
17026
|
const recoveryLocked = !!recovery && recovery.required && !recovery.configured;
|
|
@@ -16976,13 +17035,18 @@ function PollarProvider({
|
|
|
16976
17035
|
return;
|
|
16977
17036
|
}
|
|
16978
17037
|
let cancelled = false;
|
|
17038
|
+
let retry = null;
|
|
16979
17039
|
pollarClient.cosign.custodyMigration().then((next) => {
|
|
16980
17040
|
if (!cancelled) setCustodyMigration(next);
|
|
16981
|
-
}).catch(() => {
|
|
16982
|
-
if (
|
|
17041
|
+
}).catch((err) => {
|
|
17042
|
+
if (cancelled) return;
|
|
17043
|
+
if (isTransientFailure(err))
|
|
17044
|
+
retry = setTimeout(() => setCustodyMigrationTick((t) => t + 1), 5e3 + Math.random() * 5e3);
|
|
17045
|
+
else setCustodyMigration(null);
|
|
16983
17046
|
});
|
|
16984
17047
|
return () => {
|
|
16985
17048
|
cancelled = true;
|
|
17049
|
+
if (retry) clearTimeout(retry);
|
|
16986
17050
|
};
|
|
16987
17051
|
}, [pollarClient, hasSession, walletAddress, custodyMigrationTick]);
|
|
16988
17052
|
const refreshWalletBalance = useCallback(() => pollarClient.refreshBalance(), [pollarClient, walletAddress]);
|
|
@@ -17105,6 +17169,7 @@ function PollarProvider({
|
|
|
17105
17169
|
refreshCustodyMigration,
|
|
17106
17170
|
confirmations,
|
|
17107
17171
|
registerConfirmationHost,
|
|
17172
|
+
registerCosignHost,
|
|
17108
17173
|
// distribution
|
|
17109
17174
|
openDistributionRulesModal: () => setDistributionRulesModalOpen(true),
|
|
17110
17175
|
// network
|
|
@@ -17145,6 +17210,7 @@ function PollarProvider({
|
|
|
17145
17210
|
cosign,
|
|
17146
17211
|
confirmations,
|
|
17147
17212
|
registerConfirmationHost,
|
|
17213
|
+
registerCosignHost,
|
|
17148
17214
|
walletBalance,
|
|
17149
17215
|
refreshWalletBalance,
|
|
17150
17216
|
enabledAssets,
|
|
@@ -17194,7 +17260,7 @@ function PollarProvider({
|
|
|
17194
17260
|
/* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setCardModalOpen(false), children: /* @__PURE__ */ jsx(CardModal, { onClose: () => setCardModalOpen(false), initial: cardModalOptions }) }, `${cardModalKey}:${walletAddress}`),
|
|
17195
17261
|
receiveModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setReceiveModalOpen(false), children: /* @__PURE__ */ jsx(ReceiveModal, { onClose: () => setReceiveModalOpen(false), initial: receiveSeed.options }) }, `receive:${receiveSeed.key}`),
|
|
17196
17262
|
sessionsModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSessionsModalOpen(false), children: /* @__PURE__ */ jsx(SessionsModal, { onClose: () => setSessionsModalOpen(false) }) }),
|
|
17197
|
-
cosignModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setCosignModalOpen(false), children: /* @__PURE__ */ jsx(CosignModal, { nextStep: cosignNextStep, onClose: () => setCosignModalOpen(false) }) }),
|
|
17263
|
+
cosignModalOpen && cosignHosts === 0 && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setCosignModalOpen(false), children: /* @__PURE__ */ jsx(CosignModal, { nextStep: cosignNextStep, onClose: () => setCosignModalOpen(false) }) }),
|
|
17198
17264
|
custodyMigration?.required && !custodyMigrationLater && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: refreshCustodyMigration, children: /* @__PURE__ */ jsx(
|
|
17199
17265
|
CustodyMigrationModal,
|
|
17200
17266
|
{
|