@pollar/react 0.12.1-rc.6 → 0.12.1-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -10
- package/dist/index.css +125 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +396 -248
- package/dist/index.d.ts +396 -248
- package/dist/index.js +886 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +887 -76
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { AUTH_ERROR_CODES, rampLegTitle, rampRequirementCopy, rampTrustlineAsset, rampWalletStep, rampResolutionText, describeRampAction, rampLegStatus, rampNextApproval, rampOrderStopped, rampOrderReceive, rampRailLabel, rampNoRouteText, rampFieldError, rampFieldValid, rampLegNote, rampStepTitle, rampStepStatusText, rampLegTimeLeft, rampOrderResolutionText, rampCountries, rampQuoteFields, isPollarApiError, transactionErrorMessage, WalletType, isPollarClient, PollarClient, isInteractiveAuthAdapter, isAuthEntryAdapterStep, completeAuthEntryStep, rampTrustlineErrorText, isPollarNetworkError, toBaseUnits, resolveLanguage, languageFromTag, localizedText, appUnavailableMessage, cosignRefusalMessage, fromBaseUnits, assertRampStellarSigner } from '@pollar/core';
|
|
3
|
-
import { createContext, forwardRef, useState, useCallback, useEffect, useMemo, useRef, useContext, Component } from 'react';
|
|
2
|
+
import { AUTH_ERROR_CODES, rampLegTitle, rampRequirementCopy, rampTrustlineAsset, rampWalletStep, rampResolutionText, describeRampAction, rampLegStatus, rampNextApproval, rampOrderStopped, rampOrderReceive, countryName, rampRailLabel, rampNoRouteText, rampFieldError, rampFieldValid, rampLegNote, rampStepTitle, rampStepStatusText, rampLegTimeLeft, rampOrderResolutionText, rampCountries, rampQuoteFields, isPollarApiError, transactionErrorMessage, WalletType, bridgeSourceChains, bridgeTargetChains, isBridgeSettled, isPollarClient, PollarClient, isInteractiveAuthAdapter, isAuthEntryAdapterStep, completeAuthEntryStep, rampTrustlineErrorText, isPollarNetworkError, toBaseUnits, resolveLanguage, languageFromTag, localizedText, appUnavailableMessage, cosignRefusalMessage, fromBaseUnits, assertRampStellarSigner } from '@pollar/core';
|
|
3
|
+
import { createContext, forwardRef, useState, useCallback, useEffect, useMemo, useRef, useContext, useSyncExternalStore, Component } from 'react';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { startAuthentication, startRegistration } from '@simplewebauthn/browser';
|
|
6
6
|
|
|
@@ -1203,9 +1203,18 @@ var COMMONS_COPY = {
|
|
|
1203
1203
|
|
|
1204
1204
|
// src/language-context.ts
|
|
1205
1205
|
var ModalLanguageContext = createContext(null);
|
|
1206
|
-
function useProviderLanguage(client, dashboard) {
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1206
|
+
function useProviderLanguage(client, dashboard, language) {
|
|
1207
|
+
const subscribe = useCallback(
|
|
1208
|
+
(onChange) => typeof client.onLocaleChange === "function" ? client.onLocaleChange(onChange) : () => {
|
|
1209
|
+
},
|
|
1210
|
+
[client]
|
|
1211
|
+
);
|
|
1212
|
+
const getLocale = () => typeof client.getLocale === "function" ? client.getLocale() : void 0;
|
|
1213
|
+
const locale = useSyncExternalStore(subscribe, getLocale, getLocale);
|
|
1214
|
+
return useMemo(
|
|
1215
|
+
() => resolveLanguage({ dashboard, code: [language, locale], device: deviceLanguageTag() }),
|
|
1216
|
+
[dashboard, language, locale]
|
|
1217
|
+
);
|
|
1209
1218
|
}
|
|
1210
1219
|
function useInheritedLanguage(language) {
|
|
1211
1220
|
const inherited = useContext(ModalLanguageContext);
|
|
@@ -1270,7 +1279,7 @@ var PollarModalFooter = ({ language: languageProp }) => {
|
|
|
1270
1279
|
/* @__PURE__ */ jsx("img", { src: LOGO_POLLAR_WORDMARK_ON_DARK, alt: "Pollar", className: "pollar-footer-logo pollar-logo-on-dark" }),
|
|
1271
1280
|
/* @__PURE__ */ jsxs("span", { className: "pollar-footer-version", children: [
|
|
1272
1281
|
"v",
|
|
1273
|
-
"0.12.1-rc.
|
|
1282
|
+
"0.12.1-rc.7"
|
|
1274
1283
|
] })
|
|
1275
1284
|
] });
|
|
1276
1285
|
};
|
|
@@ -1434,13 +1443,12 @@ function Toggle({ checked, onChange, disabled = false, busy = false, label }) {
|
|
|
1434
1443
|
);
|
|
1435
1444
|
}
|
|
1436
1445
|
function useModalLanguage(language) {
|
|
1437
|
-
const {
|
|
1438
|
-
const
|
|
1439
|
-
const locale = typeof client.getLocale === "function" ? client.getLocale() : void 0;
|
|
1446
|
+
const { styles } = usePollar();
|
|
1447
|
+
const provider = useContext(ModalLanguageContext);
|
|
1440
1448
|
const dashboard = styles?.language;
|
|
1441
1449
|
return useMemo(
|
|
1442
|
-
() => resolveLanguage({ dashboard, code: [language,
|
|
1443
|
-
[dashboard, language,
|
|
1450
|
+
() => resolveLanguage({ dashboard, code: [language, provider], device: deviceLanguageTag() }),
|
|
1451
|
+
[dashboard, language, provider]
|
|
1444
1452
|
);
|
|
1445
1453
|
}
|
|
1446
1454
|
|
|
@@ -3310,6 +3318,7 @@ var LOGIN_COPY = {
|
|
|
3310
3318
|
genericError: "Something went wrong. Please try again.",
|
|
3311
3319
|
codeLabel: "Enter the 6-digit code sent to",
|
|
3312
3320
|
yourEmail: "your email",
|
|
3321
|
+
codeDigit: (position, total) => `Digit ${position} of ${total}`,
|
|
3313
3322
|
codePlaceholder: "Enter verification code",
|
|
3314
3323
|
verifyCode: "Verify Code",
|
|
3315
3324
|
status: {
|
|
@@ -3347,6 +3356,7 @@ var LOGIN_COPY = {
|
|
|
3347
3356
|
genericError: "Algo sali\xF3 mal. Intenta de nuevo.",
|
|
3348
3357
|
codeLabel: "Ingresa el c\xF3digo de 6 d\xEDgitos que enviamos a",
|
|
3349
3358
|
yourEmail: "tu correo",
|
|
3359
|
+
codeDigit: (position, total) => `D\xEDgito ${position} de ${total}`,
|
|
3350
3360
|
codePlaceholder: "Ingresa el c\xF3digo de verificaci\xF3n",
|
|
3351
3361
|
verifyCode: "Verificar c\xF3digo",
|
|
3352
3362
|
status: {
|
|
@@ -3384,6 +3394,7 @@ var LOGIN_COPY = {
|
|
|
3384
3394
|
genericError: "Algo deu errado. Tente novamente.",
|
|
3385
3395
|
codeLabel: "Digite o c\xF3digo de 6 d\xEDgitos enviado para",
|
|
3386
3396
|
yourEmail: "seu e-mail",
|
|
3397
|
+
codeDigit: (position, total) => `D\xEDgito ${position} de ${total}`,
|
|
3387
3398
|
codePlaceholder: "Digite o c\xF3digo de verifica\xE7\xE3o",
|
|
3388
3399
|
verifyCode: "Verificar c\xF3digo",
|
|
3389
3400
|
status: {
|
|
@@ -3439,7 +3450,7 @@ function EmailCodeInput({ email, onSubmit, language }) {
|
|
|
3439
3450
|
type: "text",
|
|
3440
3451
|
inputMode: "numeric",
|
|
3441
3452
|
autoComplete: i === 0 ? "one-time-code" : "off",
|
|
3442
|
-
"aria-label":
|
|
3453
|
+
"aria-label": copy.codeDigit(i + 1, EMAIL_CODE_LENGTH),
|
|
3443
3454
|
value: digit,
|
|
3444
3455
|
className: "pollar-code-input",
|
|
3445
3456
|
onChange: (e) => apply(applyEmailCodeInput(digits, i, e.target.value, e.target.selectionStart)),
|
|
@@ -4953,11 +4964,11 @@ function RampWidgetTemplate({
|
|
|
4953
4964
|
className: "pollar-ramp-input",
|
|
4954
4965
|
value: country,
|
|
4955
4966
|
onChange: (e) => onCountryChange(e.target.value),
|
|
4956
|
-
children: countries.map((c) => /* @__PURE__ */ jsxs("option", { value: c.
|
|
4957
|
-
flagEmoji(c.
|
|
4967
|
+
children: countries.map((c) => ({ code: c.country, name: countryName(c.country, language) })).sort((a, b) => a.name.localeCompare(b.name, language)).map((c) => /* @__PURE__ */ jsxs("option", { value: c.code, children: [
|
|
4968
|
+
flagEmoji(c.code),
|
|
4958
4969
|
" ",
|
|
4959
|
-
c.
|
|
4960
|
-
] }, c.
|
|
4970
|
+
c.name
|
|
4971
|
+
] }, c.code))
|
|
4961
4972
|
}
|
|
4962
4973
|
)
|
|
4963
4974
|
] }),
|
|
@@ -5861,6 +5872,24 @@ function routeKey(quote) {
|
|
|
5861
5872
|
return quote.legs.map((leg) => `${leg.kind}:${node(leg.from)}>${node(leg.to)}`).join("|");
|
|
5862
5873
|
}
|
|
5863
5874
|
var DECIMAL = /^\d+(\.\d+)?$/;
|
|
5875
|
+
function seededSelection(routes, seed) {
|
|
5876
|
+
const countries = rampCountries(routes);
|
|
5877
|
+
const wanted = seed.country?.trim().toUpperCase();
|
|
5878
|
+
const country = wanted ? countries.find((c) => c.country === wanted) : countries[0];
|
|
5879
|
+
if (!country) return null;
|
|
5880
|
+
const fiat = country.fiats.find((f) => f.currency === seed.fiat?.trim().toUpperCase()) ?? null;
|
|
5881
|
+
const resolvedFiat = fiat ?? country.fiats[0];
|
|
5882
|
+
const asset = routes.find(
|
|
5883
|
+
(r) => r.fiat.country === country.country && resolvedFiat !== void 0 && fiatKey(r.fiat) === fiatKey(resolvedFiat) && r.asset.code.toUpperCase() === seed.asset?.trim().toUpperCase()
|
|
5884
|
+
)?.asset;
|
|
5885
|
+
const amount = seed.amount?.trim() ?? "";
|
|
5886
|
+
return {
|
|
5887
|
+
country: country.country,
|
|
5888
|
+
fiatChoice: fiat ? fiatKey(fiat) : "",
|
|
5889
|
+
assetChoice: asset ? assetKey3(asset) : "",
|
|
5890
|
+
amount: DECIMAL.test(amount) ? amount : ""
|
|
5891
|
+
};
|
|
5892
|
+
}
|
|
5864
5893
|
async function signLegWithWallet(client, orderId, actionId, copy) {
|
|
5865
5894
|
const lent = [];
|
|
5866
5895
|
const lend = (chain, encoding, handler) => {
|
|
@@ -5895,7 +5924,7 @@ async function signLegWithWallet(client, orderId, actionId, copy) {
|
|
|
5895
5924
|
for (const release of lent) release();
|
|
5896
5925
|
}
|
|
5897
5926
|
}
|
|
5898
|
-
function RampWidget({ onClose, language: languageProp }) {
|
|
5927
|
+
function RampWidget({ onClose, language: languageProp, initial }) {
|
|
5899
5928
|
const {
|
|
5900
5929
|
getClient,
|
|
5901
5930
|
styles,
|
|
@@ -5914,7 +5943,10 @@ function RampWidget({ onClose, language: languageProp }) {
|
|
|
5914
5943
|
const copy = RAMP_COPY[language];
|
|
5915
5944
|
const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
|
|
5916
5945
|
const [step, setStep] = useState("input");
|
|
5917
|
-
const [direction, setDirection] = useState("ONRAMP");
|
|
5946
|
+
const [direction, setDirection] = useState(initial?.direction === "sell" ? "OFFRAMP" : "ONRAMP");
|
|
5947
|
+
const seedRef = useRef(
|
|
5948
|
+
initial ? { direction: initial.direction === "sell" ? "OFFRAMP" : "ONRAMP", options: initial } : null
|
|
5949
|
+
);
|
|
5918
5950
|
const [routes, setRoutes] = useState([]);
|
|
5919
5951
|
const [routesLoading, setRoutesLoading] = useState(true);
|
|
5920
5952
|
const [country, setCountry] = useState("");
|
|
@@ -5968,6 +6000,16 @@ function RampWidget({ onClose, language: languageProp }) {
|
|
|
5968
6000
|
try {
|
|
5969
6001
|
const { routes: found } = await client.getRampRoutes(next);
|
|
5970
6002
|
setRoutes(found);
|
|
6003
|
+
const seed = seedRef.current?.direction === next ? seedRef.current.options : null;
|
|
6004
|
+
if (seed) seedRef.current = null;
|
|
6005
|
+
const seeded = seed ? seededSelection(found, seed) : null;
|
|
6006
|
+
if (seeded) {
|
|
6007
|
+
setCountry(seeded.country);
|
|
6008
|
+
setFiatChoice(seeded.fiatChoice);
|
|
6009
|
+
setAssetChoice(seeded.assetChoice);
|
|
6010
|
+
setAmount(seeded.amount);
|
|
6011
|
+
return;
|
|
6012
|
+
}
|
|
5971
6013
|
const first = rampCountries(found)[0]?.country ?? "";
|
|
5972
6014
|
setCountry((current) => found.some((r) => r.fiat.country === current) ? current : first);
|
|
5973
6015
|
} catch (error) {
|
|
@@ -6052,6 +6094,7 @@ function RampWidget({ onClose, language: languageProp }) {
|
|
|
6052
6094
|
void resumeRoute(awaitingAccount.routeKey);
|
|
6053
6095
|
}, [awaitingAccount, resolvedRequest]);
|
|
6054
6096
|
function handleDirectionChange(next) {
|
|
6097
|
+
seedRef.current = null;
|
|
6055
6098
|
setDirection(next);
|
|
6056
6099
|
setErrorMsg(null);
|
|
6057
6100
|
setAwaitingAccount(null);
|
|
@@ -6231,6 +6274,7 @@ function RampWidget({ onClose, language: languageProp }) {
|
|
|
6231
6274
|
setErrorMsg(null);
|
|
6232
6275
|
try {
|
|
6233
6276
|
const found = await client.getRampOrder(id);
|
|
6277
|
+
seedRef.current = null;
|
|
6234
6278
|
setDirection(found.direction);
|
|
6235
6279
|
setOrder(found);
|
|
6236
6280
|
setStep("status");
|
|
@@ -6483,6 +6527,37 @@ function walletNotReadyReason(wallet, chain, language = "en") {
|
|
|
6483
6527
|
}
|
|
6484
6528
|
return null;
|
|
6485
6529
|
}
|
|
6530
|
+
function seededAmount(amount) {
|
|
6531
|
+
const value = amount?.trim() ?? "";
|
|
6532
|
+
return /^\d+(\.\d+)?$/.test(value) ? value : "";
|
|
6533
|
+
}
|
|
6534
|
+
function byCode(options, code) {
|
|
6535
|
+
const wanted = code?.trim().toUpperCase();
|
|
6536
|
+
return wanted ? options.find((o) => o.code.toUpperCase() === wanted) : void 0;
|
|
6537
|
+
}
|
|
6538
|
+
function oneOf(allowed, value) {
|
|
6539
|
+
return value !== void 0 && allowed.includes(value) ? value : void 0;
|
|
6540
|
+
}
|
|
6541
|
+
function useSuccessReport(transaction, active, onSuccess) {
|
|
6542
|
+
const reported = useRef(null);
|
|
6543
|
+
const hash = active && transaction.step === "success" ? transaction.hash : null;
|
|
6544
|
+
useEffect(() => {
|
|
6545
|
+
if (!hash || reported.current === hash) return;
|
|
6546
|
+
reported.current = hash;
|
|
6547
|
+
onSuccess?.({ hash });
|
|
6548
|
+
}, [hash, onSuccess]);
|
|
6549
|
+
}
|
|
6550
|
+
function useModalOptions() {
|
|
6551
|
+
const [state, setState] = useState({ options: void 0, key: 0 });
|
|
6552
|
+
const seeded = useRef(false);
|
|
6553
|
+
const open = useCallback((options) => {
|
|
6554
|
+
const given = options !== void 0 && Object.keys(options).length > 0;
|
|
6555
|
+
const remount = given || seeded.current;
|
|
6556
|
+
seeded.current = given;
|
|
6557
|
+
setState((current) => ({ options: given ? options : void 0, key: remount ? current.key + 1 : current.key }));
|
|
6558
|
+
}, []);
|
|
6559
|
+
return [state, open];
|
|
6560
|
+
}
|
|
6486
6561
|
|
|
6487
6562
|
// src/lib/qr-code/index.tsx
|
|
6488
6563
|
var import_ErrorCorrectLevel = __toESM(require_ErrorCorrectLevel());
|
|
@@ -6709,7 +6784,7 @@ function ReceiveModalTemplate({
|
|
|
6709
6784
|
}
|
|
6710
6785
|
);
|
|
6711
6786
|
}
|
|
6712
|
-
function ReceiveModal({ onClose }) {
|
|
6787
|
+
function ReceiveModal({ onClose, initial }) {
|
|
6713
6788
|
const { wallet, wallets, styles, recoveryLocked, openRecoveryModal } = usePollar();
|
|
6714
6789
|
const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
|
|
6715
6790
|
const language = useModalLanguage();
|
|
@@ -6718,8 +6793,8 @@ function ReceiveModal({ onClose }) {
|
|
|
6718
6793
|
const { chains } = useChains();
|
|
6719
6794
|
const [selectedChain, setSelectedChain] = useState(null);
|
|
6720
6795
|
useEffect(() => {
|
|
6721
|
-
if (selectedChain === null && chains.length > 0) setSelectedChain(chains[0]);
|
|
6722
|
-
}, [chains, selectedChain]);
|
|
6796
|
+
if (selectedChain === null && chains.length > 0) setSelectedChain(oneOf(chains, initial?.chain) ?? chains[0]);
|
|
6797
|
+
}, [chains, selectedChain, initial?.chain]);
|
|
6723
6798
|
const walletAddress = addressForChain(wallets, selectedChain);
|
|
6724
6799
|
const notReadyReason = walletNotReadyReason(wallet, selectedChain, language);
|
|
6725
6800
|
useEffect(
|
|
@@ -7966,7 +8041,7 @@ function assetParam(record) {
|
|
|
7966
8041
|
}
|
|
7967
8042
|
return { type: "credit_alphanum12", code: record.code, issuer: record.issuer };
|
|
7968
8043
|
}
|
|
7969
|
-
function SendModal({ onClose }) {
|
|
8044
|
+
function SendModal({ onClose, initial }) {
|
|
7970
8045
|
const {
|
|
7971
8046
|
walletBalance,
|
|
7972
8047
|
refreshWalletBalance,
|
|
@@ -7986,10 +8061,13 @@ function SendModal({ onClose }) {
|
|
|
7986
8061
|
const [step, setStep] = useState("form");
|
|
7987
8062
|
const [createsAccount, setCreatesAccount] = useState(false);
|
|
7988
8063
|
const [checkingDestination, setCheckingDestination] = useState(false);
|
|
7989
|
-
const [amount, setAmount] = useState(
|
|
7990
|
-
const [destination, setDestination] = useState("");
|
|
7991
|
-
const [memo, setMemo] = useState("");
|
|
7992
|
-
const [memoType, setMemoType] = useState(
|
|
8064
|
+
const [amount, setAmount] = useState(() => seededAmount(initial?.amount));
|
|
8065
|
+
const [destination, setDestination] = useState(() => initial?.destination?.trim() ?? "");
|
|
8066
|
+
const [memo, setMemo] = useState(() => initial?.memo ?? "");
|
|
8067
|
+
const [memoType, setMemoType] = useState(
|
|
8068
|
+
() => oneOf(["text", "id", "hash"], initial?.memoType) ?? "text"
|
|
8069
|
+
);
|
|
8070
|
+
const assetSeed = useRef(initial?.asset);
|
|
7993
8071
|
const [selectedAsset, setSelectedAsset] = useState(null);
|
|
7994
8072
|
const [showXdr, setShowXdr] = useState(false);
|
|
7995
8073
|
const [copied, setCopied] = useState(false);
|
|
@@ -7998,8 +8076,8 @@ function SendModal({ onClose }) {
|
|
|
7998
8076
|
const { chains } = useChains();
|
|
7999
8077
|
const [selectedChain, setSelectedChain] = useState(null);
|
|
8000
8078
|
useEffect(() => {
|
|
8001
|
-
if (selectedChain === null && chains.length > 0) setSelectedChain(chains[0]);
|
|
8002
|
-
}, [chains, selectedChain]);
|
|
8079
|
+
if (selectedChain === null && chains.length > 0) setSelectedChain(oneOf(chains, initial?.chain) ?? chains[0]);
|
|
8080
|
+
}, [chains, selectedChain, initial?.chain]);
|
|
8003
8081
|
const canSendOnChain = selectedChain === "STELLAR" || selectedChain === "SOLANA" || selectedChain === "POLYGON";
|
|
8004
8082
|
const notReadyReason = walletNotReadyReason(wallet, selectedChain, language);
|
|
8005
8083
|
const isBaseUnitChain = selectedChain === "SOLANA" || selectedChain === "POLYGON";
|
|
@@ -8026,9 +8104,13 @@ function SendModal({ onClose }) {
|
|
|
8026
8104
|
setSelectedAsset(sortedAssets[0] ?? null);
|
|
8027
8105
|
return;
|
|
8028
8106
|
}
|
|
8029
|
-
if (!selectedAsset && sortedAssets.length > 0)
|
|
8107
|
+
if (!selectedAsset && sortedAssets.length > 0) {
|
|
8108
|
+
setSelectedAsset(byCode(sortedAssets, assetSeed.current) ?? sortedAssets[0]);
|
|
8109
|
+
assetSeed.current = void 0;
|
|
8110
|
+
}
|
|
8030
8111
|
}, [sortedAssets, selectedAsset, selectedChain]);
|
|
8031
8112
|
const hash = transaction.step === "success" ? transaction.hash : null;
|
|
8113
|
+
useSuccessReport(transaction, step === "tx", initial?.onSuccess);
|
|
8032
8114
|
const buildData = "buildData" in transaction ? transaction.buildData : null;
|
|
8033
8115
|
const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : buildData ? "public" : network === "testnet" ? "testnet" : "public";
|
|
8034
8116
|
const explorerUrl = !hash ? null : selectedChain === "SOLANA" ? `https://explorer.solana.com/tx/${hash}${explorerNetwork === "testnet" ? "?cluster=devnet" : ""}` : selectedChain === "POLYGON" ? `https://${explorerNetwork === "testnet" ? "amoy." : ""}polygonscan.com/tx/${hash}` : `https://stellar.expert/explorer/${explorerNetwork}/tx/${hash}`;
|
|
@@ -8848,7 +8930,7 @@ function fromBaseUnits3(units, decimals) {
|
|
|
8848
8930
|
function catalogRef(code, issuer) {
|
|
8849
8931
|
return code.length <= 4 ? { type: "credit_alphanum4", code, issuer } : { type: "credit_alphanum12", code, issuer };
|
|
8850
8932
|
}
|
|
8851
|
-
function SwapModal({ onClose }) {
|
|
8933
|
+
function SwapModal({ onClose, initial }) {
|
|
8852
8934
|
const {
|
|
8853
8935
|
getSwapConfig,
|
|
8854
8936
|
getSwapTokens,
|
|
@@ -8869,13 +8951,15 @@ function SwapModal({ onClose }) {
|
|
|
8869
8951
|
const language = useModalLanguage();
|
|
8870
8952
|
const copy = SWAP_COPY[language];
|
|
8871
8953
|
const walletType = wallet?.custody === "external" ? wallet.provider : null;
|
|
8872
|
-
const [chain, setChain] = useState("STELLAR");
|
|
8954
|
+
const [chain, setChain] = useState(() => oneOf(["STELLAR", "SOLANA"], initial?.chain) ?? "STELLAR");
|
|
8955
|
+
const sellSeed = useRef(initial?.sell);
|
|
8956
|
+
const buySeed = useRef(initial?.buy);
|
|
8873
8957
|
const smartUnsupported = chain === "STELLAR" && wallet?.custody === "smart";
|
|
8874
8958
|
const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
|
|
8875
8959
|
const [step, setStep] = useState("form");
|
|
8876
8960
|
const [selectedSell, setSelectedSell] = useState(null);
|
|
8877
8961
|
const [selectedBuy, setSelectedBuy] = useState(null);
|
|
8878
|
-
const [amount, setAmount] = useState(
|
|
8962
|
+
const [amount, setAmount] = useState(() => seededAmount(initial?.amount));
|
|
8879
8963
|
const [provider, setProvider] = useState("auto");
|
|
8880
8964
|
const [venues, setVenues] = useState(null);
|
|
8881
8965
|
const [solanaVenues, setSolanaVenues] = useState(null);
|
|
@@ -8990,12 +9074,24 @@ function SwapModal({ onClose }) {
|
|
|
8990
9074
|
);
|
|
8991
9075
|
useEffect(() => {
|
|
8992
9076
|
if (sellOptions.length === 0) return;
|
|
9077
|
+
const seeded = byCode(sellOptions, sellSeed.current);
|
|
9078
|
+
if (seeded) {
|
|
9079
|
+
sellSeed.current = void 0;
|
|
9080
|
+
setSelectedSell(seeded);
|
|
9081
|
+
return;
|
|
9082
|
+
}
|
|
8993
9083
|
if (!selectedSell || !sellOptions.some((o) => optKey(o) === optKey(selectedSell))) {
|
|
8994
9084
|
setSelectedSell(sellOptions[0]);
|
|
8995
9085
|
}
|
|
8996
9086
|
}, [sellOptions, selectedSell]);
|
|
8997
9087
|
useEffect(() => {
|
|
8998
9088
|
if (buyOptions.length === 0) return;
|
|
9089
|
+
const seeded = byCode(buyOptions, buySeed.current);
|
|
9090
|
+
if (seeded) {
|
|
9091
|
+
buySeed.current = void 0;
|
|
9092
|
+
setSelectedBuy(seeded);
|
|
9093
|
+
return;
|
|
9094
|
+
}
|
|
8999
9095
|
if (!selectedBuy || !buyOptions.some((o) => optKey(o) === optKey(selectedBuy))) {
|
|
9000
9096
|
setSelectedBuy(buyOptions[0]);
|
|
9001
9097
|
}
|
|
@@ -9007,6 +9103,7 @@ function SwapModal({ onClose }) {
|
|
|
9007
9103
|
if (i.length !== 56 || !i.startsWith("G")) return copy.issuerFormat;
|
|
9008
9104
|
const opt = { ref: catalogRef(c, i), code: c, issuer: i, enabledInApp: false };
|
|
9009
9105
|
setCustomTokens((prev) => prev.some((o) => optKey(o) === optKey(opt)) ? prev : [...prev, opt]);
|
|
9106
|
+
buySeed.current = void 0;
|
|
9010
9107
|
setSelectedBuy(opt);
|
|
9011
9108
|
return null;
|
|
9012
9109
|
}
|
|
@@ -9039,6 +9136,8 @@ function SwapModal({ onClose }) {
|
|
|
9039
9136
|
if (chains.length > 0 && !chains.includes(chain)) setChain(chains[0]);
|
|
9040
9137
|
}, [chains, chain]);
|
|
9041
9138
|
function handleChainChange(next) {
|
|
9139
|
+
sellSeed.current = void 0;
|
|
9140
|
+
buySeed.current = void 0;
|
|
9042
9141
|
setChain(next);
|
|
9043
9142
|
setSelectedSell(null);
|
|
9044
9143
|
setSelectedBuy(null);
|
|
@@ -9111,6 +9210,7 @@ function SwapModal({ onClose }) {
|
|
|
9111
9210
|
copy
|
|
9112
9211
|
]);
|
|
9113
9212
|
const hash = transaction.step === "success" ? transaction.hash : null;
|
|
9213
|
+
useSuccessReport(transaction, step === "tx", initial?.onSuccess);
|
|
9114
9214
|
const buildData = "buildData" in transaction ? transaction.buildData : null;
|
|
9115
9215
|
const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : buildData ? "public" : network === "testnet" ? "testnet" : "public";
|
|
9116
9216
|
const explorerUrl = !hash ? null : chain === "SOLANA" ? `https://solscan.io/tx/${hash}${network === "testnet" ? "?cluster=devnet" : ""}` : `https://stellar.expert/explorer/${explorerNetwork}/tx/${hash}`;
|
|
@@ -9173,6 +9273,8 @@ function SwapModal({ onClose }) {
|
|
|
9173
9273
|
}
|
|
9174
9274
|
function handleReverse() {
|
|
9175
9275
|
if (!selectedSell || !selectedBuy) return;
|
|
9276
|
+
sellSeed.current = void 0;
|
|
9277
|
+
buySeed.current = void 0;
|
|
9176
9278
|
const previousSell = selectedSell;
|
|
9177
9279
|
setSelectedSell(selectedBuy);
|
|
9178
9280
|
setSelectedBuy(previousSell);
|
|
@@ -9230,8 +9332,14 @@ function SwapModal({ onClose }) {
|
|
|
9230
9332
|
onClose,
|
|
9231
9333
|
onBack: handleBack,
|
|
9232
9334
|
onRefresh: handleRefresh,
|
|
9233
|
-
onSelectSell:
|
|
9234
|
-
|
|
9335
|
+
onSelectSell: (option) => {
|
|
9336
|
+
sellSeed.current = void 0;
|
|
9337
|
+
setSelectedSell(option);
|
|
9338
|
+
},
|
|
9339
|
+
onSelectBuy: (option) => {
|
|
9340
|
+
buySeed.current = void 0;
|
|
9341
|
+
setSelectedBuy(option);
|
|
9342
|
+
},
|
|
9235
9343
|
onReverse: handleReverse,
|
|
9236
9344
|
onMax: handleMax,
|
|
9237
9345
|
onAddCustomToken: addCustomToken,
|
|
@@ -9247,6 +9355,621 @@ function SwapModal({ onClose }) {
|
|
|
9247
9355
|
) });
|
|
9248
9356
|
}
|
|
9249
9357
|
|
|
9358
|
+
// src/components/bridge-modal/bridge-copy.ts
|
|
9359
|
+
var BRIDGE_COPY = {
|
|
9360
|
+
en: {
|
|
9361
|
+
title: "Move USDC between networks",
|
|
9362
|
+
close: "Close",
|
|
9363
|
+
back: "Back",
|
|
9364
|
+
loading: "Loading\u2026",
|
|
9365
|
+
mainnetOnly: "Moving USDC between networks works on mainnet only.",
|
|
9366
|
+
noDirections: "You need a wallet on at least two networks of this app to move USDC between them.",
|
|
9367
|
+
from: "From",
|
|
9368
|
+
to: "To",
|
|
9369
|
+
amount: "Amount (USDC)",
|
|
9370
|
+
balance: "Balance",
|
|
9371
|
+
max: "Max",
|
|
9372
|
+
youReceive: "You receive",
|
|
9373
|
+
fee: "Fee",
|
|
9374
|
+
noFee: "No fee",
|
|
9375
|
+
eta: "Estimated time",
|
|
9376
|
+
etaValue: "about {minutes} min",
|
|
9377
|
+
signingInternal: "Your wallet sends it right away.",
|
|
9378
|
+
signingCosigned: "You approve it on your device.",
|
|
9379
|
+
signingExternal: "You sign it in your wallet.",
|
|
9380
|
+
quoting: "Getting a quote\u2026",
|
|
9381
|
+
bridgeButton: "Move USDC",
|
|
9382
|
+
starting: "Starting\u2026",
|
|
9383
|
+
invalidAmount: "Enter an amount with up to 6 decimals.",
|
|
9384
|
+
overBalance: "The amount is more than your balance.",
|
|
9385
|
+
statusTitle: {
|
|
9386
|
+
PENDING: "Sending",
|
|
9387
|
+
AWAITING_ACTION: "Your approval is needed",
|
|
9388
|
+
BURNED: "On its way",
|
|
9389
|
+
ATTESTED: "Arriving",
|
|
9390
|
+
COMPLETED: "Done",
|
|
9391
|
+
FAILED: "It did not go through",
|
|
9392
|
+
HELD: "Under review"
|
|
9393
|
+
},
|
|
9394
|
+
statusBody: {
|
|
9395
|
+
PENDING: "Your USDC is leaving your {from} wallet.",
|
|
9396
|
+
AWAITING_ACTION: "Approve the step below to continue.",
|
|
9397
|
+
BURNED: "Circle is confirming the transfer. This takes a few minutes.",
|
|
9398
|
+
ATTESTED: "Your USDC is being delivered to your {to} wallet.",
|
|
9399
|
+
COMPLETED: "{amount} USDC arrived in your {to} wallet.",
|
|
9400
|
+
FAILED: "Nothing left your wallet. You can try again.",
|
|
9401
|
+
HELD: "Your USDC left your {from} wallet but did not arrive yet. Our team is on it; no action is needed from you."
|
|
9402
|
+
},
|
|
9403
|
+
steps: { burn: "Leaves {from}", attest: "Confirmed by Circle", mint: "Arrives on {to}" },
|
|
9404
|
+
authorize: "Authorize",
|
|
9405
|
+
waitingWallet: "Waiting for your wallet\u2026",
|
|
9406
|
+
approveOnDevice: "Approve on your device",
|
|
9407
|
+
viewBurn: "View on {chain}",
|
|
9408
|
+
viewMint: "View on {chain}",
|
|
9409
|
+
done: "Done",
|
|
9410
|
+
newBridge: "Move more",
|
|
9411
|
+
pollTrouble: "We could not refresh the status. Retrying\u2026",
|
|
9412
|
+
errors: {
|
|
9413
|
+
mainnetOnly: "Moving USDC between networks works on mainnet only.",
|
|
9414
|
+
chainNotEnabled: "This app does not use one of these networks.",
|
|
9415
|
+
noGasWallet: "This app cannot pay the network fees for this move right now.",
|
|
9416
|
+
noWallet: (chain) => `You do not have a wallet on ${chain} yet.`,
|
|
9417
|
+
noTrustline: "Your Stellar wallet needs to accept USDC first.",
|
|
9418
|
+
connectSolanaWallet: "Connect the Solana wallet this move leaves from to sign.",
|
|
9419
|
+
unsupportedWallet: "This wallet cannot move USDC between networks.",
|
|
9420
|
+
credits: "This app cannot cover this operation right now.",
|
|
9421
|
+
actionChanged: "The step changed. Review it and authorize again.",
|
|
9422
|
+
connectStellarWallet: "Connect your Stellar wallet to sign.",
|
|
9423
|
+
walletChanged: "The connected wallet changed. Try again.",
|
|
9424
|
+
signingCancelled: "The signature was cancelled.",
|
|
9425
|
+
generic: "Something went wrong. Try again."
|
|
9426
|
+
}
|
|
9427
|
+
},
|
|
9428
|
+
es: {
|
|
9429
|
+
title: "Mover USDC entre redes",
|
|
9430
|
+
close: "Cerrar",
|
|
9431
|
+
back: "Volver",
|
|
9432
|
+
loading: "Cargando\u2026",
|
|
9433
|
+
mainnetOnly: "Mover USDC entre redes solo funciona en mainnet.",
|
|
9434
|
+
noDirections: "Necesitas una wallet en al menos dos redes de esta app para mover USDC entre ellas.",
|
|
9435
|
+
from: "Desde",
|
|
9436
|
+
to: "Hacia",
|
|
9437
|
+
amount: "Monto (USDC)",
|
|
9438
|
+
balance: "Saldo",
|
|
9439
|
+
max: "M\xE1x",
|
|
9440
|
+
youReceive: "Recibes",
|
|
9441
|
+
fee: "Comisi\xF3n",
|
|
9442
|
+
noFee: "Sin comisi\xF3n",
|
|
9443
|
+
eta: "Tiempo estimado",
|
|
9444
|
+
etaValue: "unos {minutes} min",
|
|
9445
|
+
signingInternal: "Tu wallet lo env\xEDa de inmediato.",
|
|
9446
|
+
signingCosigned: "Lo apruebas en tu dispositivo.",
|
|
9447
|
+
signingExternal: "Lo firmas en tu wallet.",
|
|
9448
|
+
quoting: "Cotizando\u2026",
|
|
9449
|
+
bridgeButton: "Mover USDC",
|
|
9450
|
+
starting: "Iniciando\u2026",
|
|
9451
|
+
invalidAmount: "Ingresa un monto con hasta 6 decimales.",
|
|
9452
|
+
overBalance: "El monto es mayor que tu saldo.",
|
|
9453
|
+
statusTitle: {
|
|
9454
|
+
PENDING: "Enviando",
|
|
9455
|
+
AWAITING_ACTION: "Falta tu aprobaci\xF3n",
|
|
9456
|
+
BURNED: "En camino",
|
|
9457
|
+
ATTESTED: "Llegando",
|
|
9458
|
+
COMPLETED: "Listo",
|
|
9459
|
+
FAILED: "No se complet\xF3",
|
|
9460
|
+
HELD: "En revisi\xF3n"
|
|
9461
|
+
},
|
|
9462
|
+
statusBody: {
|
|
9463
|
+
PENDING: "Tu USDC est\xE1 saliendo de tu wallet de {from}.",
|
|
9464
|
+
AWAITING_ACTION: "Aprueba el paso de abajo para continuar.",
|
|
9465
|
+
BURNED: "Circle est\xE1 confirmando la transferencia. Tarda unos minutos.",
|
|
9466
|
+
ATTESTED: "Tu USDC se est\xE1 entregando en tu wallet de {to}.",
|
|
9467
|
+
COMPLETED: "Llegaron {amount} USDC a tu wallet de {to}.",
|
|
9468
|
+
FAILED: "No sali\xF3 nada de tu wallet. Puedes intentarlo de nuevo.",
|
|
9469
|
+
HELD: "Tu USDC sali\xF3 de tu wallet de {from} pero todav\xEDa no lleg\xF3. Nuestro equipo ya lo est\xE1 revisando; no tienes que hacer nada."
|
|
9470
|
+
},
|
|
9471
|
+
steps: { burn: "Sale de {from}", attest: "Confirmado por Circle", mint: "Llega a {to}" },
|
|
9472
|
+
authorize: "Autorizar",
|
|
9473
|
+
waitingWallet: "Esperando a tu wallet\u2026",
|
|
9474
|
+
approveOnDevice: "Aprobar en tu dispositivo",
|
|
9475
|
+
viewBurn: "Ver en {chain}",
|
|
9476
|
+
viewMint: "Ver en {chain}",
|
|
9477
|
+
done: "Listo",
|
|
9478
|
+
newBridge: "Mover m\xE1s",
|
|
9479
|
+
pollTrouble: "No pudimos actualizar el estado. Reintentando\u2026",
|
|
9480
|
+
errors: {
|
|
9481
|
+
mainnetOnly: "Mover USDC entre redes solo funciona en mainnet.",
|
|
9482
|
+
chainNotEnabled: "Esta app no usa una de estas redes.",
|
|
9483
|
+
noGasWallet: "Esta app no puede pagar ahora las comisiones de red de este movimiento.",
|
|
9484
|
+
noWallet: (chain) => `Todav\xEDa no tienes una wallet en ${chain}.`,
|
|
9485
|
+
noTrustline: "Tu wallet de Stellar primero tiene que aceptar USDC.",
|
|
9486
|
+
connectSolanaWallet: "Conecta la wallet de Solana desde la que sale este movimiento para firmar.",
|
|
9487
|
+
unsupportedWallet: "Esta wallet no puede mover USDC entre redes.",
|
|
9488
|
+
credits: "Esta app no puede cubrir esta operaci\xF3n ahora.",
|
|
9489
|
+
actionChanged: "El paso cambi\xF3. Rev\xEDsalo y autoriza de nuevo.",
|
|
9490
|
+
connectStellarWallet: "Conecta tu wallet de Stellar para firmar.",
|
|
9491
|
+
walletChanged: "Cambi\xF3 la wallet conectada. Int\xE9ntalo de nuevo.",
|
|
9492
|
+
signingCancelled: "Se cancel\xF3 la firma.",
|
|
9493
|
+
generic: "Algo sali\xF3 mal. Int\xE9ntalo de nuevo."
|
|
9494
|
+
}
|
|
9495
|
+
},
|
|
9496
|
+
pt: {
|
|
9497
|
+
title: "Mover USDC entre redes",
|
|
9498
|
+
close: "Fechar",
|
|
9499
|
+
back: "Voltar",
|
|
9500
|
+
loading: "Carregando\u2026",
|
|
9501
|
+
mainnetOnly: "Mover USDC entre redes funciona s\xF3 na mainnet.",
|
|
9502
|
+
noDirections: "Voc\xEA precisa de uma carteira em pelo menos duas redes deste app para mover USDC entre elas.",
|
|
9503
|
+
from: "De",
|
|
9504
|
+
to: "Para",
|
|
9505
|
+
amount: "Valor (USDC)",
|
|
9506
|
+
balance: "Saldo",
|
|
9507
|
+
max: "M\xE1x",
|
|
9508
|
+
youReceive: "Voc\xEA recebe",
|
|
9509
|
+
fee: "Taxa",
|
|
9510
|
+
noFee: "Sem taxa",
|
|
9511
|
+
eta: "Tempo estimado",
|
|
9512
|
+
etaValue: "cerca de {minutes} min",
|
|
9513
|
+
signingInternal: "Sua carteira envia na hora.",
|
|
9514
|
+
signingCosigned: "Voc\xEA aprova no seu dispositivo.",
|
|
9515
|
+
signingExternal: "Voc\xEA assina na sua carteira.",
|
|
9516
|
+
quoting: "Cotando\u2026",
|
|
9517
|
+
bridgeButton: "Mover USDC",
|
|
9518
|
+
starting: "Iniciando\u2026",
|
|
9519
|
+
invalidAmount: "Informe um valor com at\xE9 6 casas decimais.",
|
|
9520
|
+
overBalance: "O valor \xE9 maior que o seu saldo.",
|
|
9521
|
+
statusTitle: {
|
|
9522
|
+
PENDING: "Enviando",
|
|
9523
|
+
AWAITING_ACTION: "Falta a sua aprova\xE7\xE3o",
|
|
9524
|
+
BURNED: "A caminho",
|
|
9525
|
+
ATTESTED: "Chegando",
|
|
9526
|
+
COMPLETED: "Pronto",
|
|
9527
|
+
FAILED: "N\xE3o foi conclu\xEDdo",
|
|
9528
|
+
HELD: "Em an\xE1lise"
|
|
9529
|
+
},
|
|
9530
|
+
statusBody: {
|
|
9531
|
+
PENDING: "Seu USDC est\xE1 saindo da sua carteira na {from}.",
|
|
9532
|
+
AWAITING_ACTION: "Aprove o passo abaixo para continuar.",
|
|
9533
|
+
BURNED: "A Circle est\xE1 confirmando a transfer\xEAncia. Leva alguns minutos.",
|
|
9534
|
+
ATTESTED: "Seu USDC est\xE1 sendo entregue na sua carteira na {to}.",
|
|
9535
|
+
COMPLETED: "{amount} USDC chegaram na sua carteira na {to}.",
|
|
9536
|
+
FAILED: "Nada saiu da sua carteira. Voc\xEA pode tentar de novo.",
|
|
9537
|
+
HELD: "Seu USDC saiu da sua carteira na {from} mas ainda n\xE3o chegou. Nossa equipe j\xE1 est\xE1 cuidando disso; voc\xEA n\xE3o precisa fazer nada."
|
|
9538
|
+
},
|
|
9539
|
+
steps: { burn: "Sai da {from}", attest: "Confirmado pela Circle", mint: "Chega na {to}" },
|
|
9540
|
+
authorize: "Autorizar",
|
|
9541
|
+
waitingWallet: "Aguardando sua carteira\u2026",
|
|
9542
|
+
approveOnDevice: "Aprovar no dispositivo",
|
|
9543
|
+
viewBurn: "Ver na {chain}",
|
|
9544
|
+
viewMint: "Ver na {chain}",
|
|
9545
|
+
done: "Pronto",
|
|
9546
|
+
newBridge: "Mover mais",
|
|
9547
|
+
pollTrouble: "N\xE3o conseguimos atualizar o status. Tentando de novo\u2026",
|
|
9548
|
+
errors: {
|
|
9549
|
+
mainnetOnly: "Mover USDC entre redes funciona s\xF3 na mainnet.",
|
|
9550
|
+
chainNotEnabled: "Este app n\xE3o usa uma dessas redes.",
|
|
9551
|
+
noGasWallet: "Este app n\xE3o consegue pagar agora as taxas de rede deste movimento.",
|
|
9552
|
+
noWallet: (chain) => `Voc\xEA ainda n\xE3o tem uma carteira na ${chain}.`,
|
|
9553
|
+
noTrustline: "Sua carteira Stellar precisa aceitar USDC primeiro.",
|
|
9554
|
+
connectSolanaWallet: "Conecte a carteira Solana de onde sai este movimento para assinar.",
|
|
9555
|
+
unsupportedWallet: "Esta carteira n\xE3o pode mover USDC entre redes.",
|
|
9556
|
+
credits: "Este app n\xE3o consegue cobrir esta opera\xE7\xE3o agora.",
|
|
9557
|
+
actionChanged: "O passo mudou. Revise e autorize de novo.",
|
|
9558
|
+
connectStellarWallet: "Conecte sua carteira Stellar para assinar.",
|
|
9559
|
+
walletChanged: "A carteira conectada mudou. Tente de novo.",
|
|
9560
|
+
signingCancelled: "A assinatura foi cancelada.",
|
|
9561
|
+
generic: "Algo deu errado. Tente de novo."
|
|
9562
|
+
}
|
|
9563
|
+
}
|
|
9564
|
+
};
|
|
9565
|
+
var BRIDGE_CHAIN_LABEL = {
|
|
9566
|
+
STELLAR: "Stellar",
|
|
9567
|
+
SOLANA: "Solana",
|
|
9568
|
+
POLYGON: "Polygon"
|
|
9569
|
+
};
|
|
9570
|
+
var EXPLORER = {
|
|
9571
|
+
STELLAR: (hash) => `https://stellar.expert/explorer/public/tx/${hash}`,
|
|
9572
|
+
SOLANA: (hash) => `https://solscan.io/tx/${hash}`,
|
|
9573
|
+
POLYGON: (hash) => `https://polygonscan.com/tx/${hash}`
|
|
9574
|
+
};
|
|
9575
|
+
var fill = (text, values) => text.replace(/\{(\w+)\}/g, (_, key) => values[key] ?? `{${key}}`);
|
|
9576
|
+
function ChainPicker({
|
|
9577
|
+
label,
|
|
9578
|
+
value,
|
|
9579
|
+
options,
|
|
9580
|
+
onChange,
|
|
9581
|
+
disabled
|
|
9582
|
+
}) {
|
|
9583
|
+
return /* @__PURE__ */ jsxs("label", { className: "pollar-bridge-field", children: [
|
|
9584
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-bridge-label", children: label }),
|
|
9585
|
+
/* @__PURE__ */ jsx(
|
|
9586
|
+
"select",
|
|
9587
|
+
{
|
|
9588
|
+
className: "pollar-input",
|
|
9589
|
+
value: value ?? "",
|
|
9590
|
+
disabled: disabled || options.length === 0,
|
|
9591
|
+
onChange: (event) => onChange(event.target.value),
|
|
9592
|
+
children: options.map((chain) => /* @__PURE__ */ jsx("option", { value: chain, children: BRIDGE_CHAIN_LABEL[chain] }, chain))
|
|
9593
|
+
}
|
|
9594
|
+
)
|
|
9595
|
+
] });
|
|
9596
|
+
}
|
|
9597
|
+
function Progress({ transfer, labels }) {
|
|
9598
|
+
const reached = {
|
|
9599
|
+
burn: !!transfer.burnTxHash,
|
|
9600
|
+
attest: transfer.status === "ATTESTED" || transfer.status === "COMPLETED" || !!transfer.mintTxHash,
|
|
9601
|
+
mint: transfer.status === "COMPLETED"
|
|
9602
|
+
};
|
|
9603
|
+
return /* @__PURE__ */ jsx("ol", { className: "pollar-bridge-steps", children: ["burn", "attest", "mint"].map((key) => /* @__PURE__ */ jsxs("li", { className: reached[key] ? "pollar-bridge-step pollar-bridge-step-done" : "pollar-bridge-step", children: [
|
|
9604
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-bridge-step-dot", "aria-hidden": true }),
|
|
9605
|
+
labels[key]
|
|
9606
|
+
] }, key)) });
|
|
9607
|
+
}
|
|
9608
|
+
function BridgeModalTemplate(props) {
|
|
9609
|
+
const language = useInheritedLanguage(props.language);
|
|
9610
|
+
const copy = BRIDGE_COPY[language];
|
|
9611
|
+
const cssVars = buildModalCssVars(props.theme, props.accentColor, props.styleOverrides);
|
|
9612
|
+
const { transfer, quote } = props;
|
|
9613
|
+
const busy = props.submitting || props.quoting;
|
|
9614
|
+
const toName = props.toChain ? BRIDGE_CHAIN_LABEL[props.toChain] : "";
|
|
9615
|
+
const signingNote = quote?.signing === "EXTERNAL" ? copy.signingExternal : quote?.signing === "COSIGNED" || quote?.signing === "SELF_CUSTODY" ? copy.signingCosigned : copy.signingInternal;
|
|
9616
|
+
return /* @__PURE__ */ jsxs(
|
|
9617
|
+
"div",
|
|
9618
|
+
{
|
|
9619
|
+
className: "pollar-modal-card pollar-bridge-modal",
|
|
9620
|
+
"data-theme": props.theme,
|
|
9621
|
+
style: cssVars,
|
|
9622
|
+
onClick: (event) => event.stopPropagation(),
|
|
9623
|
+
children: [
|
|
9624
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header", children: [
|
|
9625
|
+
/* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: copy.title }),
|
|
9626
|
+
/* @__PURE__ */ jsx("div", { className: "pollar-modal-header-actions", children: /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-modal-close", onClick: props.onClose, "aria-label": copy.close, children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M2 2l12 12M14 2L2 14", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) }) })
|
|
9627
|
+
] }),
|
|
9628
|
+
props.step === "loading" && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: copy.loading }),
|
|
9629
|
+
props.step === "unavailable" && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: props.unavailableReason === "mainnet_only" ? copy.mainnetOnly : copy.noDirections }),
|
|
9630
|
+
props.step === "form" && /* @__PURE__ */ jsxs("div", { className: "pollar-bridge-form", children: [
|
|
9631
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-bridge-chains", children: [
|
|
9632
|
+
/* @__PURE__ */ jsx(
|
|
9633
|
+
ChainPicker,
|
|
9634
|
+
{
|
|
9635
|
+
label: copy.from,
|
|
9636
|
+
value: props.fromChain,
|
|
9637
|
+
options: props.sources,
|
|
9638
|
+
onChange: props.onFromChange,
|
|
9639
|
+
disabled: busy
|
|
9640
|
+
}
|
|
9641
|
+
),
|
|
9642
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-bridge-arrow", "aria-hidden": true, children: "\u2192" }),
|
|
9643
|
+
/* @__PURE__ */ jsx(
|
|
9644
|
+
ChainPicker,
|
|
9645
|
+
{
|
|
9646
|
+
label: copy.to,
|
|
9647
|
+
value: props.toChain,
|
|
9648
|
+
options: props.targets,
|
|
9649
|
+
onChange: props.onToChange,
|
|
9650
|
+
disabled: busy
|
|
9651
|
+
}
|
|
9652
|
+
)
|
|
9653
|
+
] }),
|
|
9654
|
+
/* @__PURE__ */ jsxs("label", { className: "pollar-bridge-field", children: [
|
|
9655
|
+
/* @__PURE__ */ jsxs("span", { className: "pollar-bridge-label-row", children: [
|
|
9656
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-bridge-label", children: copy.amount }),
|
|
9657
|
+
/* @__PURE__ */ jsxs("span", { className: "pollar-bridge-balance", children: [
|
|
9658
|
+
copy.balance,
|
|
9659
|
+
" ",
|
|
9660
|
+
props.balance ?? "\u2014",
|
|
9661
|
+
props.balance !== null && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-bridge-max", onClick: props.onMax, disabled: busy, children: copy.max })
|
|
9662
|
+
] })
|
|
9663
|
+
] }),
|
|
9664
|
+
/* @__PURE__ */ jsx(
|
|
9665
|
+
"input",
|
|
9666
|
+
{
|
|
9667
|
+
className: "pollar-input",
|
|
9668
|
+
type: "text",
|
|
9669
|
+
inputMode: "decimal",
|
|
9670
|
+
placeholder: "0.00",
|
|
9671
|
+
value: props.amount,
|
|
9672
|
+
disabled: props.submitting,
|
|
9673
|
+
onChange: (event) => props.onAmountChange(event.target.value)
|
|
9674
|
+
}
|
|
9675
|
+
)
|
|
9676
|
+
] }),
|
|
9677
|
+
props.quoting && /* @__PURE__ */ jsx("div", { className: "pollar-bridge-note", children: copy.quoting }),
|
|
9678
|
+
quote && !props.quoting && /* @__PURE__ */ jsxs("dl", { className: "pollar-bridge-quote", children: [
|
|
9679
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
9680
|
+
/* @__PURE__ */ jsx("dt", { children: copy.youReceive }),
|
|
9681
|
+
/* @__PURE__ */ jsxs("dd", { children: [
|
|
9682
|
+
quote.amountOut,
|
|
9683
|
+
" USDC \xB7 ",
|
|
9684
|
+
toName
|
|
9685
|
+
] })
|
|
9686
|
+
] }),
|
|
9687
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
9688
|
+
/* @__PURE__ */ jsx("dt", { children: copy.fee }),
|
|
9689
|
+
/* @__PURE__ */ jsx("dd", { children: quote.fee ? `${quote.fee.amount} USD` : copy.noFee })
|
|
9690
|
+
] }),
|
|
9691
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
9692
|
+
/* @__PURE__ */ jsx("dt", { children: copy.eta }),
|
|
9693
|
+
/* @__PURE__ */ jsx("dd", { children: fill(copy.etaValue, { minutes: String(Math.max(1, Math.round(quote.etaSeconds / 60))) }) })
|
|
9694
|
+
] }),
|
|
9695
|
+
/* @__PURE__ */ jsx("p", { className: "pollar-bridge-note", children: signingNote })
|
|
9696
|
+
] }),
|
|
9697
|
+
props.formError && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: props.formError }),
|
|
9698
|
+
/* @__PURE__ */ jsx("div", { className: "pollar-modal-actions", children: /* @__PURE__ */ jsx(
|
|
9699
|
+
"button",
|
|
9700
|
+
{
|
|
9701
|
+
type: "button",
|
|
9702
|
+
className: "pollar-btn-primary",
|
|
9703
|
+
disabled: !props.canSubmit || props.submitting,
|
|
9704
|
+
onClick: props.onSubmit,
|
|
9705
|
+
children: props.submitting ? copy.starting : copy.bridgeButton
|
|
9706
|
+
}
|
|
9707
|
+
) })
|
|
9708
|
+
] }),
|
|
9709
|
+
props.step === "transfer" && transfer && /* @__PURE__ */ jsxs("div", { className: "pollar-bridge-transfer", children: [
|
|
9710
|
+
/* @__PURE__ */ jsxs("div", { className: `pollar-bridge-status pollar-bridge-status-${transfer.status.toLowerCase()}`, children: [
|
|
9711
|
+
/* @__PURE__ */ jsx("strong", { children: copy.statusTitle[transfer.status] }),
|
|
9712
|
+
/* @__PURE__ */ jsx("p", { children: fill(copy.statusBody[transfer.status], {
|
|
9713
|
+
from: BRIDGE_CHAIN_LABEL[transfer.fromChain],
|
|
9714
|
+
to: BRIDGE_CHAIN_LABEL[transfer.toChain],
|
|
9715
|
+
amount: transfer.amountOut ?? transfer.amount
|
|
9716
|
+
}) })
|
|
9717
|
+
] }),
|
|
9718
|
+
/* @__PURE__ */ jsx(
|
|
9719
|
+
Progress,
|
|
9720
|
+
{
|
|
9721
|
+
transfer,
|
|
9722
|
+
labels: {
|
|
9723
|
+
burn: fill(copy.steps.burn, { from: BRIDGE_CHAIN_LABEL[transfer.fromChain] }),
|
|
9724
|
+
attest: copy.steps.attest,
|
|
9725
|
+
mint: fill(copy.steps.mint, { to: BRIDGE_CHAIN_LABEL[transfer.toChain] })
|
|
9726
|
+
}
|
|
9727
|
+
}
|
|
9728
|
+
),
|
|
9729
|
+
transfer.pendingAction?.kind === "SIGNATURE" && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", disabled: props.signing, onClick: props.onAuthorize, children: props.signing ? copy.waitingWallet : copy.authorize }),
|
|
9730
|
+
transfer.pendingAction?.kind === "COSIGN_APPROVAL" && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: props.onApprove, children: copy.approveOnDevice }),
|
|
9731
|
+
props.actionError && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: props.actionError }),
|
|
9732
|
+
props.pollTrouble && /* @__PURE__ */ jsx("div", { className: "pollar-bridge-note", children: copy.pollTrouble }),
|
|
9733
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-bridge-links", children: [
|
|
9734
|
+
transfer.burnTxHash && /* @__PURE__ */ jsx("a", { href: EXPLORER[transfer.fromChain](transfer.burnTxHash), target: "_blank", rel: "noopener noreferrer", children: fill(copy.viewBurn, { chain: BRIDGE_CHAIN_LABEL[transfer.fromChain] }) }),
|
|
9735
|
+
transfer.mintTxHash && /* @__PURE__ */ jsx("a", { href: EXPLORER[transfer.toChain](transfer.mintTxHash), target: "_blank", rel: "noopener noreferrer", children: fill(copy.viewMint, { chain: BRIDGE_CHAIN_LABEL[transfer.toChain] }) })
|
|
9736
|
+
] }),
|
|
9737
|
+
(transfer.status === "COMPLETED" || transfer.status === "FAILED") && /* @__PURE__ */ jsxs("div", { className: "pollar-modal-actions", children: [
|
|
9738
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-secondary", onClick: props.onNewBridge, children: copy.newBridge }),
|
|
9739
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: props.onClose, children: copy.done })
|
|
9740
|
+
] })
|
|
9741
|
+
] }),
|
|
9742
|
+
/* @__PURE__ */ jsx(PollarModalFooter, {})
|
|
9743
|
+
]
|
|
9744
|
+
}
|
|
9745
|
+
);
|
|
9746
|
+
}
|
|
9747
|
+
var AMOUNT = /^(?:0|[1-9]\d{0,11})(?:\.\d{1,6})?$/;
|
|
9748
|
+
var QUOTE_DEBOUNCE_MS2 = 400;
|
|
9749
|
+
function errorText(error, copy) {
|
|
9750
|
+
if (!isPollarApiError(error)) return copy.errors.generic;
|
|
9751
|
+
const reason = typeof error.body.reason === "string" ? error.body.reason : null;
|
|
9752
|
+
const chain = typeof error.body.chain === "string" ? BRIDGE_CHAIN_LABEL[error.body.chain] ?? "" : "";
|
|
9753
|
+
switch (error.code) {
|
|
9754
|
+
case "SDK_BRIDGE_UNAVAILABLE":
|
|
9755
|
+
if (reason === "mainnet_only") return copy.errors.mainnetOnly;
|
|
9756
|
+
if (reason === "chain_not_enabled") return copy.errors.chainNotEnabled;
|
|
9757
|
+
return copy.errors.noGasWallet;
|
|
9758
|
+
case "SDK_BRIDGE_WALLET_NOT_READY":
|
|
9759
|
+
if (reason === "no_usdc_trustline") return copy.errors.noTrustline;
|
|
9760
|
+
if (reason === "no_wallet") return copy.errors.noWallet(chain);
|
|
9761
|
+
return copy.errors.unsupportedWallet;
|
|
9762
|
+
case "SDK_CREDITS_INSUFFICIENT":
|
|
9763
|
+
case "SDK_BILLING_OVERDUE":
|
|
9764
|
+
return copy.errors.credits;
|
|
9765
|
+
case "SDK_BRIDGE_ACTION_CHANGED":
|
|
9766
|
+
return copy.errors.actionChanged;
|
|
9767
|
+
default:
|
|
9768
|
+
return copy.errors.generic;
|
|
9769
|
+
}
|
|
9770
|
+
}
|
|
9771
|
+
function solanaBurnSigner(client, copy) {
|
|
9772
|
+
return async (action) => {
|
|
9773
|
+
const payload = JSON.parse(action.payload.value);
|
|
9774
|
+
const solanaWallet = () => client.getWallets().find((w) => w.chain === "SOLANA" && w.custody === "external");
|
|
9775
|
+
const wallet = solanaWallet();
|
|
9776
|
+
if (!wallet || payload.from !== wallet.address || !payload.unsignedTransaction)
|
|
9777
|
+
throw new Error(copy.errors.connectSolanaWallet);
|
|
9778
|
+
const signed = await client.signSolanaTransaction(payload.unsignedTransaction);
|
|
9779
|
+
if (solanaWallet()?.address !== wallet.address) throw new Error(copy.errors.walletChanged);
|
|
9780
|
+
return signed;
|
|
9781
|
+
};
|
|
9782
|
+
}
|
|
9783
|
+
async function signStepWithWallet(client, transferId, actionId, copy) {
|
|
9784
|
+
const lent = [];
|
|
9785
|
+
const lend = (chain, encoding, handler) => {
|
|
9786
|
+
try {
|
|
9787
|
+
lent.push(client.registerRampSigningHandler(chain, encoding, handler));
|
|
9788
|
+
} catch {
|
|
9789
|
+
}
|
|
9790
|
+
};
|
|
9791
|
+
lend("SOLANA", "solana-cctp-json", solanaBurnSigner(client, copy));
|
|
9792
|
+
lend("STELLAR", "xdr", async (action) => {
|
|
9793
|
+
const wallet = client.getWallet();
|
|
9794
|
+
if (!wallet) throw new Error(copy.errors.connectStellarWallet);
|
|
9795
|
+
assertRampStellarSigner(action, wallet.address);
|
|
9796
|
+
const outcome = await client.signTx(action.payload.value);
|
|
9797
|
+
if (client.getWallet()?.address !== wallet.address) throw new Error(copy.errors.walletChanged);
|
|
9798
|
+
if (outcome.status === "signed") return outcome.signedXdr;
|
|
9799
|
+
throw new Error(
|
|
9800
|
+
outcome.status === "error" ? outcome.message ?? outcome.details ?? copy.errors.signingCancelled : copy.errors.signingCancelled
|
|
9801
|
+
);
|
|
9802
|
+
});
|
|
9803
|
+
try {
|
|
9804
|
+
return await client.signBridgeStep(transferId, actionId);
|
|
9805
|
+
} finally {
|
|
9806
|
+
for (const release of lent) release();
|
|
9807
|
+
}
|
|
9808
|
+
}
|
|
9809
|
+
function newIntentKey() {
|
|
9810
|
+
return typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
9811
|
+
}
|
|
9812
|
+
function BridgeModal({ onClose, initial }) {
|
|
9813
|
+
const { getClient, styles, walletBalance, refreshWalletBalance, openCosignModal } = usePollar();
|
|
9814
|
+
const language = useModalLanguage();
|
|
9815
|
+
const copy = BRIDGE_COPY[language];
|
|
9816
|
+
const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
|
|
9817
|
+
const client = getClient();
|
|
9818
|
+
const [config, setConfig] = useState(null);
|
|
9819
|
+
const [configError, setConfigError] = useState(null);
|
|
9820
|
+
const [fromChain, setFromChain] = useState(null);
|
|
9821
|
+
const [toChain, setToChain] = useState(null);
|
|
9822
|
+
const [amount, setAmount] = useState(() => seededAmount(initial?.amount));
|
|
9823
|
+
const [quote, setQuote] = useState(null);
|
|
9824
|
+
const [quoting, setQuoting] = useState(false);
|
|
9825
|
+
const [quoteError, setQuoteError] = useState(null);
|
|
9826
|
+
const [submitting, setSubmitting] = useState(false);
|
|
9827
|
+
const [transfer, setTransfer] = useState(null);
|
|
9828
|
+
const [signing, setSigning] = useState(false);
|
|
9829
|
+
const [actionError, setActionError] = useState(null);
|
|
9830
|
+
const [pollTrouble, setPollTrouble] = useState(false);
|
|
9831
|
+
const intentKey = useRef(newIntentKey());
|
|
9832
|
+
useEffect(() => {
|
|
9833
|
+
let cancelled = false;
|
|
9834
|
+
client.getBridgeConfig().then((loaded) => {
|
|
9835
|
+
if (cancelled) return;
|
|
9836
|
+
setConfig(loaded);
|
|
9837
|
+
const sources2 = bridgeSourceChains(loaded);
|
|
9838
|
+
const from = oneOf(sources2, initial?.fromChain) ?? sources2[0] ?? null;
|
|
9839
|
+
const targets2 = from ? bridgeTargetChains(loaded, from) : [];
|
|
9840
|
+
setFromChain(from);
|
|
9841
|
+
setToChain(oneOf(targets2, initial?.toChain) ?? targets2[0] ?? null);
|
|
9842
|
+
}).catch((error) => !cancelled && setConfigError(errorText(error, copy)));
|
|
9843
|
+
return () => {
|
|
9844
|
+
cancelled = true;
|
|
9845
|
+
};
|
|
9846
|
+
}, [client]);
|
|
9847
|
+
const sources = useMemo(() => config ? bridgeSourceChains(config) : [], [config]);
|
|
9848
|
+
const targets = useMemo(() => config && fromChain ? bridgeTargetChains(config, fromChain) : [], [config, fromChain]);
|
|
9849
|
+
const balance = useMemo(() => {
|
|
9850
|
+
if (walletBalance.step !== "loaded" || !fromChain) return null;
|
|
9851
|
+
const usdc = walletBalance.data.balances.find((b) => (b.chain ?? "STELLAR") === fromChain && b.code === "USDC");
|
|
9852
|
+
return usdc ? usdc.available ?? usdc.balance : "0";
|
|
9853
|
+
}, [walletBalance, fromChain]);
|
|
9854
|
+
const amountValid = AMOUNT.test(amount) && Number(amount) > 0;
|
|
9855
|
+
const overBalance = amountValid && balance !== null && Number(amount) > Number(balance);
|
|
9856
|
+
const formError = configError ?? quoteError ?? (amount && !amountValid ? copy.invalidAmount : null) ?? (overBalance ? copy.overBalance : null);
|
|
9857
|
+
useEffect(() => {
|
|
9858
|
+
setQuote(null);
|
|
9859
|
+
setQuoteError(null);
|
|
9860
|
+
if (!fromChain || !toChain || !amountValid) return;
|
|
9861
|
+
let cancelled = false;
|
|
9862
|
+
const timer = setTimeout(() => {
|
|
9863
|
+
setQuoting(true);
|
|
9864
|
+
client.quoteBridge({ fromChain, toChain, amount }).then((next) => !cancelled && setQuote(next)).catch((error) => !cancelled && setQuoteError(errorText(error, copy))).finally(() => !cancelled && setQuoting(false));
|
|
9865
|
+
}, QUOTE_DEBOUNCE_MS2);
|
|
9866
|
+
return () => {
|
|
9867
|
+
cancelled = true;
|
|
9868
|
+
clearTimeout(timer);
|
|
9869
|
+
};
|
|
9870
|
+
}, [client, fromChain, toChain, amount, amountValid]);
|
|
9871
|
+
useEffect(() => {
|
|
9872
|
+
if (!transfer || isBridgeSettled(transfer)) return;
|
|
9873
|
+
const controller = new AbortController();
|
|
9874
|
+
client.pollBridgeTransfer(transfer.id, {
|
|
9875
|
+
signal: controller.signal,
|
|
9876
|
+
onUpdate: (next) => {
|
|
9877
|
+
setPollTrouble(false);
|
|
9878
|
+
setTransfer(next);
|
|
9879
|
+
},
|
|
9880
|
+
onError: () => setPollTrouble(true),
|
|
9881
|
+
// A co-signed step moves once the device approves: keep reading through it.
|
|
9882
|
+
until: (next) => next.status === "AWAITING_ACTION" && next.pendingAction?.kind === "SIGNATURE"
|
|
9883
|
+
}).then((settled) => {
|
|
9884
|
+
if (settled.status === "COMPLETED") void refreshWalletBalance();
|
|
9885
|
+
}).catch(() => {
|
|
9886
|
+
});
|
|
9887
|
+
return () => controller.abort();
|
|
9888
|
+
}, [client, transfer?.id, transfer?.pendingAction?.actionId]);
|
|
9889
|
+
const reported = useRef(null);
|
|
9890
|
+
const onSuccess = initial?.onSuccess;
|
|
9891
|
+
useEffect(() => {
|
|
9892
|
+
if (transfer?.status !== "COMPLETED" || reported.current === transfer.id) return;
|
|
9893
|
+
reported.current = transfer.id;
|
|
9894
|
+
onSuccess?.(transfer);
|
|
9895
|
+
}, [transfer, onSuccess]);
|
|
9896
|
+
async function submit() {
|
|
9897
|
+
if (!fromChain || !toChain || !amountValid || overBalance) return;
|
|
9898
|
+
setSubmitting(true);
|
|
9899
|
+
setQuoteError(null);
|
|
9900
|
+
try {
|
|
9901
|
+
const started = await client.bridge({ fromChain, toChain, amount, idempotencyKey: intentKey.current });
|
|
9902
|
+
setTransfer(started);
|
|
9903
|
+
} catch (error) {
|
|
9904
|
+
setQuoteError(errorText(error, copy));
|
|
9905
|
+
} finally {
|
|
9906
|
+
setSubmitting(false);
|
|
9907
|
+
}
|
|
9908
|
+
}
|
|
9909
|
+
async function authorize() {
|
|
9910
|
+
const action = transfer?.pendingAction;
|
|
9911
|
+
if (!transfer || action?.kind !== "SIGNATURE") return;
|
|
9912
|
+
setSigning(true);
|
|
9913
|
+
setActionError(null);
|
|
9914
|
+
try {
|
|
9915
|
+
setTransfer(await signStepWithWallet(client, transfer.id, action.actionId, copy));
|
|
9916
|
+
} catch (error) {
|
|
9917
|
+
setActionError(error instanceof Error && !isPollarApiError(error) ? error.message : errorText(error, copy));
|
|
9918
|
+
client.getBridgeTransfer(transfer.id).then(setTransfer).catch(() => {
|
|
9919
|
+
});
|
|
9920
|
+
} finally {
|
|
9921
|
+
setSigning(false);
|
|
9922
|
+
}
|
|
9923
|
+
}
|
|
9924
|
+
function newBridge() {
|
|
9925
|
+
intentKey.current = newIntentKey();
|
|
9926
|
+
setTransfer(null);
|
|
9927
|
+
setAmount("");
|
|
9928
|
+
setActionError(null);
|
|
9929
|
+
void refreshWalletBalance();
|
|
9930
|
+
}
|
|
9931
|
+
const step = transfer ? "transfer" : !config && !configError ? "loading" : config && (!config.available || sources.length === 0) ? "unavailable" : "form";
|
|
9932
|
+
return /* @__PURE__ */ jsx("div", { className: "pollar-overlay", style: overlayStyle, onClick: onClose, children: /* @__PURE__ */ jsx(
|
|
9933
|
+
BridgeModalTemplate,
|
|
9934
|
+
{
|
|
9935
|
+
theme,
|
|
9936
|
+
accentColor,
|
|
9937
|
+
styleOverrides,
|
|
9938
|
+
step,
|
|
9939
|
+
unavailableReason: config?.reason === "mainnet_only" ? "mainnet_only" : config ? "no_directions" : null,
|
|
9940
|
+
sources,
|
|
9941
|
+
targets,
|
|
9942
|
+
fromChain,
|
|
9943
|
+
toChain,
|
|
9944
|
+
onFromChange: (chain) => {
|
|
9945
|
+
setFromChain(chain);
|
|
9946
|
+
const next = config ? bridgeTargetChains(config, chain) : [];
|
|
9947
|
+
if (!toChain || !next.includes(toChain)) setToChain(next[0] ?? null);
|
|
9948
|
+
},
|
|
9949
|
+
onToChange: setToChain,
|
|
9950
|
+
amount,
|
|
9951
|
+
onAmountChange: (value) => setAmount(value.replace(",", ".").trim()),
|
|
9952
|
+
balance,
|
|
9953
|
+
onMax: () => balance !== null && setAmount(balance.replace(/(\.\d{6})\d+$/, "$1")),
|
|
9954
|
+
quote,
|
|
9955
|
+
quoting,
|
|
9956
|
+
formError,
|
|
9957
|
+
canSubmit: !!quote && !quoting && amountValid && !overBalance,
|
|
9958
|
+
submitting,
|
|
9959
|
+
onSubmit: () => void submit(),
|
|
9960
|
+
transfer,
|
|
9961
|
+
signing,
|
|
9962
|
+
onAuthorize: () => void authorize(),
|
|
9963
|
+
onApprove: openCosignModal,
|
|
9964
|
+
actionError,
|
|
9965
|
+
pollTrouble,
|
|
9966
|
+
onNewBridge: newBridge,
|
|
9967
|
+
onClose,
|
|
9968
|
+
language
|
|
9969
|
+
}
|
|
9970
|
+
) });
|
|
9971
|
+
}
|
|
9972
|
+
|
|
9250
9973
|
// src/components/earn-modal/earn-copy.ts
|
|
9251
9974
|
var EARN_COPY = {
|
|
9252
9975
|
en: {
|
|
@@ -9372,7 +10095,7 @@ function formatAmount3(value) {
|
|
|
9372
10095
|
const n = parseFloat(value);
|
|
9373
10096
|
return isNaN(n) ? value : n.toLocaleString(void 0, { maximumFractionDigits: 7 });
|
|
9374
10097
|
}
|
|
9375
|
-
function EarnModal({ onClose }) {
|
|
10098
|
+
function EarnModal({ onClose, initial }) {
|
|
9376
10099
|
const {
|
|
9377
10100
|
getEarnProviders,
|
|
9378
10101
|
getEarnOpportunities,
|
|
@@ -9393,13 +10116,15 @@ function EarnModal({ onClose }) {
|
|
|
9393
10116
|
const smartUnsupported = wallet?.custody === "smart";
|
|
9394
10117
|
const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
|
|
9395
10118
|
const [step, setStep] = useState("form");
|
|
9396
|
-
const [tab, setTab] = useState(
|
|
10119
|
+
const [tab, setTab] = useState(
|
|
10120
|
+
() => oneOf(["deposit", "withdraw"], initial?.tab) ?? "deposit"
|
|
10121
|
+
);
|
|
9397
10122
|
const [providers, setProviders] = useState(null);
|
|
9398
10123
|
const [provider, setProvider] = useState(null);
|
|
9399
10124
|
const [opportunities, setOpportunities] = useState([]);
|
|
9400
|
-
const [opportunityId, setOpportunityId] = useState("");
|
|
10125
|
+
const [opportunityId, setOpportunityId] = useState(() => initial?.opportunityId ?? "");
|
|
9401
10126
|
const [position, setPosition] = useState(null);
|
|
9402
|
-
const [amount, setAmount] = useState(
|
|
10127
|
+
const [amount, setAmount] = useState(() => seededAmount(initial?.amount));
|
|
9403
10128
|
const [loadingOpps, setLoadingOpps] = useState(false);
|
|
9404
10129
|
const [formError, setFormError] = useState("");
|
|
9405
10130
|
const [refreshing, setRefreshing] = useState(false);
|
|
@@ -9410,9 +10135,9 @@ function EarnModal({ onClose }) {
|
|
|
9410
10135
|
setProviders(null);
|
|
9411
10136
|
return getEarnProviders().then((ps) => {
|
|
9412
10137
|
setProviders(ps);
|
|
9413
|
-
setProvider((cur) => cur ?? ps[0] ?? null);
|
|
10138
|
+
setProvider((cur) => cur ?? oneOf(ps, initial?.provider) ?? ps[0] ?? null);
|
|
9414
10139
|
}).catch(() => setProviders([]));
|
|
9415
|
-
}, [getEarnProviders]);
|
|
10140
|
+
}, [getEarnProviders, initial?.provider]);
|
|
9416
10141
|
useEffect(() => {
|
|
9417
10142
|
void loadProviders();
|
|
9418
10143
|
}, [loadProviders]);
|
|
@@ -9474,6 +10199,7 @@ function EarnModal({ onClose }) {
|
|
|
9474
10199
|
})();
|
|
9475
10200
|
const depositNeedsTrustline = tab === "deposit" && !smartUnsupported && !!selectedOpportunity?.asset.issuer && !depositAssetRecord?.trustlineEstablished;
|
|
9476
10201
|
const hash = transaction.step === "success" ? transaction.hash : null;
|
|
10202
|
+
useSuccessReport(transaction, step === "tx", initial?.onSuccess);
|
|
9477
10203
|
const buildData = "buildData" in transaction ? transaction.buildData : null;
|
|
9478
10204
|
const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : buildData ? "public" : network === "testnet" ? "testnet" : "public";
|
|
9479
10205
|
const explorerUrl = hash ? `https://stellar.expert/explorer/${explorerNetwork}/tx/${hash}` : null;
|
|
@@ -9894,7 +10620,15 @@ var CARD_COPY = {
|
|
|
9894
10620
|
chain: (id) => `chain ${id}`,
|
|
9895
10621
|
sendOnly: (tokens, network) => `Send only ${tokens} on ${network}; anything else can be lost.`,
|
|
9896
10622
|
noDeposit: "The provider returned no deposit address.",
|
|
9897
|
-
hideDeposit: "Hide the deposit address"
|
|
10623
|
+
hideDeposit: "Hide the deposit address",
|
|
10624
|
+
fundingProblem: {
|
|
10625
|
+
noGas: "Your wallet does not have enough to pay the network fee.",
|
|
10626
|
+
sponsorNoGas: "The network fee cannot be covered right now. Please try again later.",
|
|
10627
|
+
noBalance: "Your wallet does not have enough USDC for this amount.",
|
|
10628
|
+
notPaid: "The payment was not sent.",
|
|
10629
|
+
failed: "The payment could not be completed. Please try again.",
|
|
10630
|
+
delayed: "Taking longer than usual. We are following up with the card provider."
|
|
10631
|
+
}
|
|
9898
10632
|
},
|
|
9899
10633
|
es: {
|
|
9900
10634
|
funding: {
|
|
@@ -10052,7 +10786,15 @@ var CARD_COPY = {
|
|
|
10052
10786
|
chain: (id) => `cadena ${id}`,
|
|
10053
10787
|
sendOnly: (tokens, network) => `Env\xEDa solo ${tokens} en ${network}; cualquier otra cosa puede perderse.`,
|
|
10054
10788
|
noDeposit: "El proveedor no devolvi\xF3 ninguna direcci\xF3n de dep\xF3sito.",
|
|
10055
|
-
hideDeposit: "Ocultar la direcci\xF3n de dep\xF3sito"
|
|
10789
|
+
hideDeposit: "Ocultar la direcci\xF3n de dep\xF3sito",
|
|
10790
|
+
fundingProblem: {
|
|
10791
|
+
noGas: "Tu wallet no tiene saldo suficiente para pagar la comisi\xF3n de red.",
|
|
10792
|
+
sponsorNoGas: "Ahora no se puede cubrir la comisi\xF3n de red. Intenta de nuevo m\xE1s tarde.",
|
|
10793
|
+
noBalance: "Tu wallet no tiene suficiente USDC para este monto.",
|
|
10794
|
+
notPaid: "El pago no se envi\xF3.",
|
|
10795
|
+
failed: "No se pudo completar el pago. Intenta de nuevo.",
|
|
10796
|
+
delayed: "Est\xE1 tardando m\xE1s de lo normal. Estamos haciendo seguimiento con el emisor de la tarjeta."
|
|
10797
|
+
}
|
|
10056
10798
|
},
|
|
10057
10799
|
pt: {
|
|
10058
10800
|
funding: {
|
|
@@ -10210,9 +10952,28 @@ var CARD_COPY = {
|
|
|
10210
10952
|
chain: (id) => `rede ${id}`,
|
|
10211
10953
|
sendOnly: (tokens, network) => `Envie apenas ${tokens} na ${network}; qualquer outra coisa pode ser perdida.`,
|
|
10212
10954
|
noDeposit: "O provedor n\xE3o retornou nenhum endere\xE7o de dep\xF3sito.",
|
|
10213
|
-
hideDeposit: "Ocultar o endere\xE7o de dep\xF3sito"
|
|
10955
|
+
hideDeposit: "Ocultar o endere\xE7o de dep\xF3sito",
|
|
10956
|
+
fundingProblem: {
|
|
10957
|
+
noGas: "Sua carteira n\xE3o tem saldo suficiente para pagar a taxa de rede.",
|
|
10958
|
+
sponsorNoGas: "A taxa de rede n\xE3o pode ser coberta agora. Tente novamente mais tarde.",
|
|
10959
|
+
noBalance: "Sua carteira n\xE3o tem USDC suficiente para este valor.",
|
|
10960
|
+
notPaid: "O pagamento n\xE3o foi enviado.",
|
|
10961
|
+
failed: "N\xE3o foi poss\xEDvel concluir o pagamento. Tente novamente.",
|
|
10962
|
+
delayed: "Est\xE1 demorando mais que o normal. Estamos acompanhando com o emissor do cart\xE3o."
|
|
10963
|
+
}
|
|
10214
10964
|
}
|
|
10215
10965
|
};
|
|
10966
|
+
var CREDIT_DELAYED = "provider_credit_delayed";
|
|
10967
|
+
function fundingProblemText(error, copy) {
|
|
10968
|
+
const raw = error ?? "";
|
|
10969
|
+
if (/^TX_INSUFFICIENT_BALANCE|needed \(fee/.test(raw)) {
|
|
10970
|
+
if (/sponsor/i.test(raw)) return copy.fundingProblem.sponsorNoGas;
|
|
10971
|
+
return /token balance/i.test(raw) ? copy.fundingProblem.noBalance : copy.fundingProblem.noGas;
|
|
10972
|
+
}
|
|
10973
|
+
if (/insufficient_usdc/.test(raw)) return copy.fundingProblem.noBalance;
|
|
10974
|
+
if (/^(payment_not_received|cosign_rejected|cosign_expired)/.test(raw)) return copy.fundingProblem.notPaid;
|
|
10975
|
+
return copy.fundingProblem.failed;
|
|
10976
|
+
}
|
|
10216
10977
|
|
|
10217
10978
|
// src/components/card-modal/card-kyc.ts
|
|
10218
10979
|
var nonEmpty = (value) => typeof value === "string" && !!value.trim();
|
|
@@ -10297,10 +11058,20 @@ function money(amount, currency, language) {
|
|
|
10297
11058
|
function groupPan(pan) {
|
|
10298
11059
|
return pan.replace(/\s+/g, "").replace(/(.{4})/g, "$1 ").trim();
|
|
10299
11060
|
}
|
|
10300
|
-
function
|
|
11061
|
+
function errorText2(e, fallback, copy) {
|
|
10301
11062
|
if (isPollarApiError(e)) {
|
|
10302
11063
|
const known = copy.errors[e.code];
|
|
10303
11064
|
if (known) return known;
|
|
11065
|
+
if (e.code === "SDK_CARDS_FUNDING_WALLET_NOT_READY") {
|
|
11066
|
+
const { reason, code, message: message2 } = e.body;
|
|
11067
|
+
if (reason === "insufficient_usdc") return copy.fundingProblem.noBalance;
|
|
11068
|
+
if (reason === "build_failed" || reason === "payment_rejected") {
|
|
11069
|
+
return fundingProblemText(
|
|
11070
|
+
`${typeof code === "string" ? code : ""}: ${typeof message2 === "string" ? message2 : ""}`,
|
|
11071
|
+
copy
|
|
11072
|
+
);
|
|
11073
|
+
}
|
|
11074
|
+
}
|
|
10304
11075
|
const providerMessage = e.body.providerMessage;
|
|
10305
11076
|
if (typeof providerMessage === "string" && providerMessage) return providerMessage;
|
|
10306
11077
|
const message = e.body.message;
|
|
@@ -10309,7 +11080,7 @@ function errorText(e, fallback, copy) {
|
|
|
10309
11080
|
}
|
|
10310
11081
|
return e instanceof Error && e.message ? e.message : fallback;
|
|
10311
11082
|
}
|
|
10312
|
-
function CardModal({ onClose }) {
|
|
11083
|
+
function CardModal({ onClose, initial }) {
|
|
10313
11084
|
const { getClient, styles, wallet } = usePollar();
|
|
10314
11085
|
const language = useModalLanguage();
|
|
10315
11086
|
const copy = CARD_COPY[language];
|
|
@@ -10325,9 +11096,10 @@ function CardModal({ onClose }) {
|
|
|
10325
11096
|
const [transactions, setTransactions] = useState(null);
|
|
10326
11097
|
const [deposit, setDeposit] = useState(null);
|
|
10327
11098
|
const [fundings, setFundings] = useState(null);
|
|
10328
|
-
const [fundAmount, setFundAmount] = useState(
|
|
11099
|
+
const [fundAmount, setFundAmount] = useState(() => seededAmount(initial?.amount));
|
|
10329
11100
|
const fundKey = useRef(null);
|
|
10330
|
-
const [fundChain, setFundChain] = useState(null);
|
|
11101
|
+
const [fundChain, setFundChain] = useState(initial?.chain ?? null);
|
|
11102
|
+
const fundPanelSeed = useRef(initial?.panel === "fund");
|
|
10331
11103
|
const [showManual, setShowManual] = useState(false);
|
|
10332
11104
|
const [occupations, setOccupations] = useState([]);
|
|
10333
11105
|
const [kyc, setKyc] = useState(emptyKyc);
|
|
@@ -10341,7 +11113,7 @@ function CardModal({ onClose }) {
|
|
|
10341
11113
|
const provider = providers?.[0] ?? null;
|
|
10342
11114
|
const fundingAsset = provider?.fundingAssets[0] ?? "USDC";
|
|
10343
11115
|
const fundChains = useChains().chains.filter(isFundingChain);
|
|
10344
|
-
const selectedFundChain = fundChain ?? fundChains[0] ?? "STELLAR";
|
|
11116
|
+
const selectedFundChain = (fundChain && fundChains.includes(fundChain) ? fundChain : null) ?? fundChains[0] ?? "STELLAR";
|
|
10345
11117
|
const fundAvailable = useWalletAvailable(panel === "fund" ? { chain: selectedFundChain, code: fundingAsset } : null);
|
|
10346
11118
|
const card = cards?.[0] ?? null;
|
|
10347
11119
|
const expiry = card?.expMonth && card.expYear ? `${card.expMonth}/${card.expYear.slice(-2)}` : null;
|
|
@@ -10389,7 +11161,7 @@ function CardModal({ onClose }) {
|
|
|
10389
11161
|
} catch (e) {
|
|
10390
11162
|
if (!cancelled) {
|
|
10391
11163
|
setProviders((cur) => cur ?? []);
|
|
10392
|
-
setError(
|
|
11164
|
+
setError(errorText2(e, copy.failed.load, copy));
|
|
10393
11165
|
}
|
|
10394
11166
|
}
|
|
10395
11167
|
})();
|
|
@@ -10438,7 +11210,7 @@ function CardModal({ onClose }) {
|
|
|
10438
11210
|
} catch (e) {
|
|
10439
11211
|
const step = requiredCardStep(e);
|
|
10440
11212
|
if (step) openStep(step);
|
|
10441
|
-
else setError(
|
|
11213
|
+
else setError(errorText2(e, fallback, copy));
|
|
10442
11214
|
} finally {
|
|
10443
11215
|
setBusy(null);
|
|
10444
11216
|
}
|
|
@@ -10505,6 +11277,11 @@ function CardModal({ onClose }) {
|
|
|
10505
11277
|
},
|
|
10506
11278
|
copy.failed.loadFundings
|
|
10507
11279
|
);
|
|
11280
|
+
useEffect(() => {
|
|
11281
|
+
if (!card || !fundPanelSeed.current) return;
|
|
11282
|
+
fundPanelSeed.current = false;
|
|
11283
|
+
void openFund();
|
|
11284
|
+
}, [card]);
|
|
10508
11285
|
const fund = () => run(
|
|
10509
11286
|
"fund-send",
|
|
10510
11287
|
async () => {
|
|
@@ -10527,6 +11304,7 @@ function CardModal({ onClose }) {
|
|
|
10527
11304
|
}
|
|
10528
11305
|
setFundings((cur) => [outcome.funding, ...(cur ?? []).filter((f) => f.id !== outcome.funding.id)]);
|
|
10529
11306
|
setFundAmount("");
|
|
11307
|
+
initial?.onFunded?.(outcome.funding);
|
|
10530
11308
|
},
|
|
10531
11309
|
copy.failed.fund
|
|
10532
11310
|
);
|
|
@@ -10943,12 +11721,13 @@ function CardModal({ onClose }) {
|
|
|
10943
11721
|
] }),
|
|
10944
11722
|
inflight && step > 0 && /* @__PURE__ */ jsxs("span", { className: "pollar-card-tx-meta", role: "status", children: [
|
|
10945
11723
|
copy.stepOf(step, steps.length),
|
|
10946
|
-
" \xB7
|
|
10947
|
-
|
|
11724
|
+
" \xB7",
|
|
11725
|
+
" ",
|
|
11726
|
+
f.error === CREDIT_DELAYED ? copy.fundingProblem.delayed : state?.hint
|
|
10948
11727
|
] }),
|
|
10949
11728
|
/* @__PURE__ */ jsxs("span", { className: "pollar-card-tx-meta", children: [
|
|
10950
11729
|
new Date(f.createdAt).toLocaleString(),
|
|
10951
|
-
f.status === "FAILED"
|
|
11730
|
+
f.status === "FAILED" ? ` \xB7 ${fundingProblemText(f.error, copy)}` : ""
|
|
10952
11731
|
] })
|
|
10953
11732
|
] }),
|
|
10954
11733
|
/* @__PURE__ */ jsx("div", { className: "pollar-card-tx-amount", "data-direction": f.status === "CREDITED" ? "credit" : void 0, children: money(f.amount, "USD", language) })
|
|
@@ -11752,7 +12531,8 @@ function CosignModal({ nextStep = null, onClose }) {
|
|
|
11752
12531
|
setError(
|
|
11753
12532
|
transactionErrorMessage(isPollarApiError(err) ? err.code : null, err instanceof Error ? err.message : null, language)
|
|
11754
12533
|
);
|
|
11755
|
-
if (kind === "approving")
|
|
12534
|
+
if (kind === "approving" && !(isPollarApiError(err) && err.code === "SDK_COSIGN_GAS_PENDING"))
|
|
12535
|
+
setApproveFailedFor(request.id);
|
|
11756
12536
|
} finally {
|
|
11757
12537
|
setBusy(null);
|
|
11758
12538
|
}
|
|
@@ -12404,7 +13184,7 @@ function RecoveryModalTemplate(p) {
|
|
|
12404
13184
|
}
|
|
12405
13185
|
);
|
|
12406
13186
|
}
|
|
12407
|
-
function
|
|
13187
|
+
function errorText3(err, language) {
|
|
12408
13188
|
return cosignRefusalMessage(err, language) ?? transactionErrorMessage(isPollarApiError(err) ? err.code : null, err instanceof Error ? err.message : null, language);
|
|
12409
13189
|
}
|
|
12410
13190
|
function RecoveryModal({ onClose }) {
|
|
@@ -12437,7 +13217,7 @@ function RecoveryModal({ onClose }) {
|
|
|
12437
13217
|
refreshRecovery();
|
|
12438
13218
|
}, [getClient, refreshRecovery]);
|
|
12439
13219
|
useEffect(() => {
|
|
12440
|
-
load().catch((err) => setError(
|
|
13220
|
+
load().catch((err) => setError(errorText3(err, language)));
|
|
12441
13221
|
}, [load]);
|
|
12442
13222
|
const onCloseRef = useRef(onClose);
|
|
12443
13223
|
onCloseRef.current = onClose;
|
|
@@ -12458,7 +13238,7 @@ function RecoveryModal({ onClose }) {
|
|
|
12458
13238
|
if (after?.notice) setNotice(after.notice);
|
|
12459
13239
|
if (after?.view) setView(after.view);
|
|
12460
13240
|
} catch (err) {
|
|
12461
|
-
setError(
|
|
13241
|
+
setError(errorText3(err, language));
|
|
12462
13242
|
} finally {
|
|
12463
13243
|
setBusy(null);
|
|
12464
13244
|
}
|
|
@@ -13099,7 +13879,7 @@ function TxHistoryModalTemplate({
|
|
|
13099
13879
|
);
|
|
13100
13880
|
}
|
|
13101
13881
|
var PAGE_SIZE2 = 10;
|
|
13102
|
-
function TxHistoryModal({ onClose }) {
|
|
13882
|
+
function TxHistoryModal({ onClose, initial }) {
|
|
13103
13883
|
const { getClient, styles, txHistory, wallets } = usePollar();
|
|
13104
13884
|
const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
|
|
13105
13885
|
const language = useModalLanguage();
|
|
@@ -13107,8 +13887,8 @@ function TxHistoryModal({ onClose }) {
|
|
|
13107
13887
|
const { chains } = useChains();
|
|
13108
13888
|
const [selectedChain, setSelectedChain] = useState(null);
|
|
13109
13889
|
useEffect(() => {
|
|
13110
|
-
if (selectedChain === null && chains.length > 0) setSelectedChain(chains[0]);
|
|
13111
|
-
}, [chains, selectedChain]);
|
|
13890
|
+
if (selectedChain === null && chains.length > 0) setSelectedChain(oneOf(chains, initial?.chain) ?? chains[0]);
|
|
13891
|
+
}, [chains, selectedChain, initial?.chain]);
|
|
13112
13892
|
const walletAddress = addressForChain(wallets, selectedChain);
|
|
13113
13893
|
const load = useCallback(
|
|
13114
13894
|
(nextOffset, chain) => {
|
|
@@ -13486,6 +14266,7 @@ var PollarContext = createContext(null);
|
|
|
13486
14266
|
var clientByConfig = /* @__PURE__ */ new WeakMap();
|
|
13487
14267
|
function PollarProvider({
|
|
13488
14268
|
client,
|
|
14269
|
+
language,
|
|
13489
14270
|
appConfig: appConfigProp,
|
|
13490
14271
|
adapters,
|
|
13491
14272
|
onStorageDegrade,
|
|
@@ -13647,6 +14428,13 @@ function PollarProvider({
|
|
|
13647
14428
|
const [kycModalOpen, setKycModalOpen] = useState(false);
|
|
13648
14429
|
const [kycModalOptions, setKycModalOptions] = useState({});
|
|
13649
14430
|
const [rampModalOpen, setRampModalOpen] = useState(false);
|
|
14431
|
+
const [rampSeed, seedRamp] = useModalOptions();
|
|
14432
|
+
const [receiveSeed, seedReceive] = useModalOptions();
|
|
14433
|
+
const [txHistorySeed, seedTxHistory] = useModalOptions();
|
|
14434
|
+
const [sendModalOptions, setSendModalOptions] = useState(void 0);
|
|
14435
|
+
const [swapModalOptions, setSwapModalOptions] = useState(void 0);
|
|
14436
|
+
const [earnModalOptions, setEarnModalOptions] = useState(void 0);
|
|
14437
|
+
const [cardModalOptions, setCardModalOptions] = useState(void 0);
|
|
13650
14438
|
const [txHistoryModalOpen, setTxHistoryModalOpen] = useState(false);
|
|
13651
14439
|
const [walletBalanceModalOpen, setWalletBalanceModalOpen] = useState(false);
|
|
13652
14440
|
const [enabledAssetsModalOpen, setEnabledAssetsModalOpen] = useState(false);
|
|
@@ -13655,6 +14443,9 @@ function PollarProvider({
|
|
|
13655
14443
|
const [earnModalOpen, setEarnModalOpen] = useState(false);
|
|
13656
14444
|
const [sendModalKey, setSendModalKey] = useState(0);
|
|
13657
14445
|
const [swapModalKey, setSwapModalKey] = useState(0);
|
|
14446
|
+
const [bridgeModalOpen, setBridgeModalOpen] = useState(false);
|
|
14447
|
+
const [bridgeModalKey, setBridgeModalKey] = useState(0);
|
|
14448
|
+
const [bridgeModalOptions, setBridgeModalOptions] = useState(void 0);
|
|
13658
14449
|
const [earnModalKey, setEarnModalKey] = useState(0);
|
|
13659
14450
|
const [cardModalOpen, setCardModalOpen] = useState(false);
|
|
13660
14451
|
const [cardModalKey, setCardModalKey] = useState(0);
|
|
@@ -13680,6 +14471,7 @@ function PollarProvider({
|
|
|
13680
14471
|
setEnabledAssetsModalOpen(false);
|
|
13681
14472
|
setSendModalOpen(false);
|
|
13682
14473
|
setSwapModalOpen(false);
|
|
14474
|
+
setBridgeModalOpen(false);
|
|
13683
14475
|
setEarnModalOpen(false);
|
|
13684
14476
|
setCardModalOpen(false);
|
|
13685
14477
|
setReceiveModalOpen(false);
|
|
@@ -13763,7 +14555,10 @@ function PollarProvider({
|
|
|
13763
14555
|
openTxModal: () => setTransactionModalOpen(true),
|
|
13764
14556
|
// tx history
|
|
13765
14557
|
txHistory,
|
|
13766
|
-
openTxHistoryModal: () =>
|
|
14558
|
+
openTxHistoryModal: (options) => {
|
|
14559
|
+
seedTxHistory(options);
|
|
14560
|
+
setTxHistoryModalOpen(true);
|
|
14561
|
+
},
|
|
13767
14562
|
// wallet balance
|
|
13768
14563
|
walletBalance,
|
|
13769
14564
|
refreshWalletBalance,
|
|
@@ -13774,12 +14569,16 @@ function PollarProvider({
|
|
|
13774
14569
|
setTrustline: (asset, opts) => pollarClient.setTrustline(asset, opts),
|
|
13775
14570
|
openEnabledAssetsModal: () => setEnabledAssetsModalOpen(true),
|
|
13776
14571
|
// send / receive
|
|
13777
|
-
openSendModal: () => {
|
|
14572
|
+
openSendModal: (options) => {
|
|
14573
|
+
setSendModalOptions(options);
|
|
13778
14574
|
pollarClient.resetTransactionState();
|
|
13779
14575
|
setSendModalKey((k) => k + 1);
|
|
13780
14576
|
setSendModalOpen(true);
|
|
13781
14577
|
},
|
|
13782
|
-
openReceiveModal: () =>
|
|
14578
|
+
openReceiveModal: (options) => {
|
|
14579
|
+
seedReceive(options);
|
|
14580
|
+
setReceiveModalOpen(true);
|
|
14581
|
+
},
|
|
13783
14582
|
// swap
|
|
13784
14583
|
getSwapConfig: () => pollarClient.getSwapConfig(),
|
|
13785
14584
|
getSwapTokens: () => pollarClient.getSwapTokens(),
|
|
@@ -13788,24 +14587,32 @@ function PollarProvider({
|
|
|
13788
14587
|
getSolanaSwapConfig: () => pollarClient.getSolanaSwapConfig(),
|
|
13789
14588
|
getSolanaSwapQuote: (params) => pollarClient.getSolanaSwapQuote(params),
|
|
13790
14589
|
swapSolana: (quote, opts) => pollarClient.swapSolana(quote, opts),
|
|
13791
|
-
openSwapModal: () => {
|
|
14590
|
+
openSwapModal: (options) => {
|
|
14591
|
+
setSwapModalOptions(options);
|
|
13792
14592
|
pollarClient.resetTransactionState();
|
|
13793
14593
|
setSwapModalKey((k) => k + 1);
|
|
13794
14594
|
setSwapModalOpen(true);
|
|
13795
14595
|
},
|
|
14596
|
+
openBridgeModal: (options) => {
|
|
14597
|
+
setBridgeModalOptions(options);
|
|
14598
|
+
setBridgeModalKey((k) => k + 1);
|
|
14599
|
+
setBridgeModalOpen(true);
|
|
14600
|
+
},
|
|
13796
14601
|
// earn
|
|
13797
14602
|
getEarnProviders: () => pollarClient.getEarnProviders(),
|
|
13798
14603
|
getEarnOpportunities: (provider) => pollarClient.getEarnOpportunities(provider),
|
|
13799
14604
|
getEarnPosition: (params) => pollarClient.getEarnPosition(params),
|
|
13800
14605
|
earnDeposit: (params) => pollarClient.earnDeposit(params),
|
|
13801
14606
|
earnWithdraw: (params) => pollarClient.earnWithdraw(params),
|
|
13802
|
-
openEarnModal: () => {
|
|
14607
|
+
openEarnModal: (options) => {
|
|
14608
|
+
setEarnModalOptions(options);
|
|
13803
14609
|
pollarClient.resetTransactionState();
|
|
13804
14610
|
setEarnModalKey((k) => k + 1);
|
|
13805
14611
|
setEarnModalOpen(true);
|
|
13806
14612
|
},
|
|
13807
14613
|
// cards
|
|
13808
|
-
openCardModal: () => {
|
|
14614
|
+
openCardModal: (options) => {
|
|
14615
|
+
setCardModalOptions(options);
|
|
13809
14616
|
setCardModalKey((k) => k + 1);
|
|
13810
14617
|
setCardModalOpen(true);
|
|
13811
14618
|
},
|
|
@@ -13834,7 +14641,10 @@ function PollarProvider({
|
|
|
13834
14641
|
setKycModalOpen(true);
|
|
13835
14642
|
},
|
|
13836
14643
|
// ramp
|
|
13837
|
-
openRampModal: () =>
|
|
14644
|
+
openRampModal: (options) => {
|
|
14645
|
+
seedRamp(options);
|
|
14646
|
+
setRampModalOpen(true);
|
|
14647
|
+
},
|
|
13838
14648
|
// config
|
|
13839
14649
|
appConfig: resolvedConfig,
|
|
13840
14650
|
styles,
|
|
@@ -13869,7 +14679,7 @@ function PollarProvider({
|
|
|
13869
14679
|
retryConfig,
|
|
13870
14680
|
adapters
|
|
13871
14681
|
]);
|
|
13872
|
-
const modalLanguage = useProviderLanguage(pollarClient, contextValue.styles?.language);
|
|
14682
|
+
const modalLanguage = useProviderLanguage(pollarClient, contextValue.styles?.language, language);
|
|
13873
14683
|
return /* @__PURE__ */ jsx(PollarContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs(ModalLanguageContext.Provider, { value: modalLanguage, children: [
|
|
13874
14684
|
children,
|
|
13875
14685
|
loginModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setLoginModalOpen(false), children: /* @__PURE__ */ jsx(LoginModal, { onClose: () => setLoginModalOpen(false) }) }),
|
|
@@ -13896,16 +14706,17 @@ function PollarProvider({
|
|
|
13896
14706
|
...kycModalOptions.onApproved !== void 0 && { onApproved: kycModalOptions.onApproved }
|
|
13897
14707
|
}
|
|
13898
14708
|
) }),
|
|
13899
|
-
rampModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setRampModalOpen(false), children: /* @__PURE__ */ jsx(RampWidget, { onClose: () => setRampModalOpen(false) }) }),
|
|
13900
|
-
txHistoryModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setTxHistoryModalOpen(false), children: /* @__PURE__ */ jsx(TxHistoryModal, { onClose: () => setTxHistoryModalOpen(false) }) }),
|
|
14709
|
+
rampModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setRampModalOpen(false), children: /* @__PURE__ */ jsx(RampWidget, { onClose: () => setRampModalOpen(false), initial: rampSeed.options }) }, `ramp:${rampSeed.key}`),
|
|
14710
|
+
txHistoryModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setTxHistoryModalOpen(false), children: /* @__PURE__ */ jsx(TxHistoryModal, { onClose: () => setTxHistoryModalOpen(false), initial: txHistorySeed.options }) }, `history:${txHistorySeed.key}`),
|
|
13901
14711
|
walletBalanceModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setWalletBalanceModalOpen(false), children: /* @__PURE__ */ jsx(WalletBalanceModal, { onClose: () => setWalletBalanceModalOpen(false) }) }),
|
|
13902
14712
|
enabledAssetsModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setEnabledAssetsModalOpen(false), children: /* @__PURE__ */ jsx(EnabledAssetsModal, { onClose: () => setEnabledAssetsModalOpen(false) }) }),
|
|
13903
|
-
sendModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSendModalOpen(false), children: /* @__PURE__ */ jsx(SendModal, { onClose: () => setSendModalOpen(false) }) }, sendModalKey),
|
|
13904
|
-
swapModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSwapModalOpen(false), children: /* @__PURE__ */ jsx(SwapModal, { onClose: () => setSwapModalOpen(false) }) }, swapModalKey),
|
|
13905
|
-
|
|
14713
|
+
sendModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSendModalOpen(false), children: /* @__PURE__ */ jsx(SendModal, { onClose: () => setSendModalOpen(false), initial: sendModalOptions }) }, `send:${sendModalKey}`),
|
|
14714
|
+
swapModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSwapModalOpen(false), children: /* @__PURE__ */ jsx(SwapModal, { onClose: () => setSwapModalOpen(false), initial: swapModalOptions }) }, `swap:${swapModalKey}`),
|
|
14715
|
+
bridgeModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setBridgeModalOpen(false), children: /* @__PURE__ */ jsx(BridgeModal, { onClose: () => setBridgeModalOpen(false), initial: bridgeModalOptions }) }, bridgeModalKey),
|
|
14716
|
+
earnModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setEarnModalOpen(false), children: /* @__PURE__ */ jsx(EarnModal, { onClose: () => setEarnModalOpen(false), initial: earnModalOptions }) }, `earn:${earnModalKey}`),
|
|
13906
14717
|
cardModalOpen && // Keyed by the wallet too: a different user, or signing in with it open, starts it from scratch.
|
|
13907
|
-
/* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setCardModalOpen(false), children: /* @__PURE__ */ jsx(CardModal, { onClose: () => setCardModalOpen(false) }) }, `${cardModalKey}:${walletAddress}`),
|
|
13908
|
-
receiveModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setReceiveModalOpen(false), children: /* @__PURE__ */ jsx(ReceiveModal, { onClose: () => setReceiveModalOpen(false) }) }),
|
|
14718
|
+
/* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setCardModalOpen(false), children: /* @__PURE__ */ jsx(CardModal, { onClose: () => setCardModalOpen(false), initial: cardModalOptions }) }, `${cardModalKey}:${walletAddress}`),
|
|
14719
|
+
receiveModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setReceiveModalOpen(false), children: /* @__PURE__ */ jsx(ReceiveModal, { onClose: () => setReceiveModalOpen(false), initial: receiveSeed.options }) }, `receive:${receiveSeed.key}`),
|
|
13909
14720
|
sessionsModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setSessionsModalOpen(false), children: /* @__PURE__ */ jsx(SessionsModal, { onClose: () => setSessionsModalOpen(false) }) }),
|
|
13910
14721
|
cosignModalOpen && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: () => setCosignModalOpen(false), children: /* @__PURE__ */ jsx(CosignModal, { nextStep: cosignNextStep, onClose: () => setCosignModalOpen(false) }) }),
|
|
13911
14722
|
custodyMigration?.required && !custodyMigrationLater && /* @__PURE__ */ jsx(ModalErrorBoundary, { onClose: refreshCustodyMigration, children: /* @__PURE__ */ jsx(
|
|
@@ -14719,6 +15530,6 @@ function WalletButton() {
|
|
|
14719
15530
|
);
|
|
14720
15531
|
}
|
|
14721
15532
|
|
|
14722
|
-
export { CardModal, ChainSelect, CosignModal, CosignModalTemplate, CustodyMigrationModal, CustodyMigrationModalTemplate, DistributionRulesModal, DistributionRulesModalTemplate, EarnModal, EnabledAssetsModal, EnabledAssetsModalTemplate, KycModal, KycModalTemplate, KycStatus, LoginModalTemplate, PollarProvider, ProviderRegistrationModal, RampWidget, RampWidgetTemplate, ReceiveModal, ReceiveModalTemplate, RecoveryModal, RecoveryModalTemplate, RegistryCheckModal, RejectedRouteDisplay, RequirementFormModal, RouteDisplay, SendModal, SendModalTemplate, SessionsModal, SessionsModalTemplate, SwapModal, SwapModalTemplate, TransactionModalTemplate, TxHistoryModalTemplate, TxStatusView, WalletBalanceModal, WalletBalanceModalTemplate, WalletButton, WalletButtonTemplate, addressForChain, browserPasskeyCeremony, browserPasskeySigner, browserRecoveryPasskey, buildModalCssVars, chainsOf, createPollarAdapterHook, modalChrome, readableTextOn, resolveChain, useChains, useCosign, usePollar, walletNotReadyReason };
|
|
15533
|
+
export { BridgeModal, BridgeModalTemplate, CardModal, ChainSelect, CosignModal, CosignModalTemplate, CustodyMigrationModal, CustodyMigrationModalTemplate, DistributionRulesModal, DistributionRulesModalTemplate, EarnModal, EnabledAssetsModal, EnabledAssetsModalTemplate, KycModal, KycModalTemplate, KycStatus, LoginModalTemplate, PollarProvider, ProviderRegistrationModal, RampWidget, RampWidgetTemplate, ReceiveModal, ReceiveModalTemplate, RecoveryModal, RecoveryModalTemplate, RegistryCheckModal, RejectedRouteDisplay, RequirementFormModal, RouteDisplay, SendModal, SendModalTemplate, SessionsModal, SessionsModalTemplate, SwapModal, SwapModalTemplate, TransactionModalTemplate, TxHistoryModalTemplate, TxStatusView, WalletBalanceModal, WalletBalanceModalTemplate, WalletButton, WalletButtonTemplate, addressForChain, browserPasskeyCeremony, browserPasskeySigner, browserRecoveryPasskey, buildModalCssVars, chainsOf, createPollarAdapterHook, modalChrome, readableTextOn, resolveChain, useChains, useCosign, usePollar, walletNotReadyReason };
|
|
14723
15534
|
//# sourceMappingURL=index.mjs.map
|
|
14724
15535
|
//# sourceMappingURL=index.mjs.map
|