@pollar/react 0.12.1-rc.5 → 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/dist/index.js CHANGED
@@ -1205,9 +1205,18 @@ var COMMONS_COPY = {
1205
1205
 
1206
1206
  // src/language-context.ts
1207
1207
  var ModalLanguageContext = react.createContext(null);
1208
- function useProviderLanguage(client, dashboard) {
1209
- const locale = typeof client.getLocale === "function" ? client.getLocale() : void 0;
1210
- return react.useMemo(() => core.resolveLanguage({ dashboard, code: [locale], device: deviceLanguageTag() }), [dashboard, locale]);
1208
+ function useProviderLanguage(client, dashboard, language) {
1209
+ const subscribe = react.useCallback(
1210
+ (onChange) => typeof client.onLocaleChange === "function" ? client.onLocaleChange(onChange) : () => {
1211
+ },
1212
+ [client]
1213
+ );
1214
+ const getLocale = () => typeof client.getLocale === "function" ? client.getLocale() : void 0;
1215
+ const locale = react.useSyncExternalStore(subscribe, getLocale, getLocale);
1216
+ return react.useMemo(
1217
+ () => core.resolveLanguage({ dashboard, code: [language, locale], device: deviceLanguageTag() }),
1218
+ [dashboard, language, locale]
1219
+ );
1211
1220
  }
1212
1221
  function useInheritedLanguage(language) {
1213
1222
  const inherited = react.useContext(ModalLanguageContext);
@@ -1272,7 +1281,7 @@ var PollarModalFooter = ({ language: languageProp }) => {
1272
1281
  /* @__PURE__ */ jsxRuntime.jsx("img", { src: LOGO_POLLAR_WORDMARK_ON_DARK, alt: "Pollar", className: "pollar-footer-logo pollar-logo-on-dark" }),
1273
1282
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "pollar-footer-version", children: [
1274
1283
  "v",
1275
- "0.12.1-rc.5"
1284
+ "0.12.1-rc.7"
1276
1285
  ] })
1277
1286
  ] });
1278
1287
  };
@@ -1436,13 +1445,12 @@ function Toggle({ checked, onChange, disabled = false, busy = false, label }) {
1436
1445
  );
1437
1446
  }
1438
1447
  function useModalLanguage(language) {
1439
- const { getClient, styles } = usePollar();
1440
- const client = getClient();
1441
- const locale = typeof client.getLocale === "function" ? client.getLocale() : void 0;
1448
+ const { styles } = usePollar();
1449
+ const provider = react.useContext(ModalLanguageContext);
1442
1450
  const dashboard = styles?.language;
1443
1451
  return react.useMemo(
1444
- () => core.resolveLanguage({ dashboard, code: [language, locale], device: deviceLanguageTag() }),
1445
- [dashboard, language, locale]
1452
+ () => core.resolveLanguage({ dashboard, code: [language, provider], device: deviceLanguageTag() }),
1453
+ [dashboard, language, provider]
1446
1454
  );
1447
1455
  }
1448
1456
 
@@ -3312,6 +3320,7 @@ var LOGIN_COPY = {
3312
3320
  genericError: "Something went wrong. Please try again.",
3313
3321
  codeLabel: "Enter the 6-digit code sent to",
3314
3322
  yourEmail: "your email",
3323
+ codeDigit: (position, total) => `Digit ${position} of ${total}`,
3315
3324
  codePlaceholder: "Enter verification code",
3316
3325
  verifyCode: "Verify Code",
3317
3326
  status: {
@@ -3349,6 +3358,7 @@ var LOGIN_COPY = {
3349
3358
  genericError: "Algo sali\xF3 mal. Intenta de nuevo.",
3350
3359
  codeLabel: "Ingresa el c\xF3digo de 6 d\xEDgitos que enviamos a",
3351
3360
  yourEmail: "tu correo",
3361
+ codeDigit: (position, total) => `D\xEDgito ${position} de ${total}`,
3352
3362
  codePlaceholder: "Ingresa el c\xF3digo de verificaci\xF3n",
3353
3363
  verifyCode: "Verificar c\xF3digo",
3354
3364
  status: {
@@ -3386,6 +3396,7 @@ var LOGIN_COPY = {
3386
3396
  genericError: "Algo deu errado. Tente novamente.",
3387
3397
  codeLabel: "Digite o c\xF3digo de 6 d\xEDgitos enviado para",
3388
3398
  yourEmail: "seu e-mail",
3399
+ codeDigit: (position, total) => `D\xEDgito ${position} de ${total}`,
3389
3400
  codePlaceholder: "Digite o c\xF3digo de verifica\xE7\xE3o",
3390
3401
  verifyCode: "Verificar c\xF3digo",
3391
3402
  status: {
@@ -3441,7 +3452,7 @@ function EmailCodeInput({ email, onSubmit, language }) {
3441
3452
  type: "text",
3442
3453
  inputMode: "numeric",
3443
3454
  autoComplete: i === 0 ? "one-time-code" : "off",
3444
- "aria-label": `Digit ${i + 1} of ${EMAIL_CODE_LENGTH}`,
3455
+ "aria-label": copy.codeDigit(i + 1, EMAIL_CODE_LENGTH),
3445
3456
  value: digit,
3446
3457
  className: "pollar-code-input",
3447
3458
  onChange: (e) => apply(applyEmailCodeInput(digits, i, e.target.value, e.target.selectionStart)),
@@ -4955,11 +4966,11 @@ function RampWidgetTemplate({
4955
4966
  className: "pollar-ramp-input",
4956
4967
  value: country,
4957
4968
  onChange: (e) => onCountryChange(e.target.value),
4958
- children: countries.map((c) => /* @__PURE__ */ jsxRuntime.jsxs("option", { value: c.country, children: [
4959
- flagEmoji(c.country),
4969
+ children: countries.map((c) => ({ code: c.country, name: core.countryName(c.country, language) })).sort((a, b) => a.name.localeCompare(b.name, language)).map((c) => /* @__PURE__ */ jsxRuntime.jsxs("option", { value: c.code, children: [
4970
+ flagEmoji(c.code),
4960
4971
  " ",
4961
- c.country
4962
- ] }, c.country))
4972
+ c.name
4973
+ ] }, c.code))
4963
4974
  }
4964
4975
  )
4965
4976
  ] }),
@@ -5863,6 +5874,24 @@ function routeKey(quote) {
5863
5874
  return quote.legs.map((leg) => `${leg.kind}:${node(leg.from)}>${node(leg.to)}`).join("|");
5864
5875
  }
5865
5876
  var DECIMAL = /^\d+(\.\d+)?$/;
5877
+ function seededSelection(routes, seed) {
5878
+ const countries = core.rampCountries(routes);
5879
+ const wanted = seed.country?.trim().toUpperCase();
5880
+ const country = wanted ? countries.find((c) => c.country === wanted) : countries[0];
5881
+ if (!country) return null;
5882
+ const fiat = country.fiats.find((f) => f.currency === seed.fiat?.trim().toUpperCase()) ?? null;
5883
+ const resolvedFiat = fiat ?? country.fiats[0];
5884
+ const asset = routes.find(
5885
+ (r) => r.fiat.country === country.country && resolvedFiat !== void 0 && fiatKey(r.fiat) === fiatKey(resolvedFiat) && r.asset.code.toUpperCase() === seed.asset?.trim().toUpperCase()
5886
+ )?.asset;
5887
+ const amount = seed.amount?.trim() ?? "";
5888
+ return {
5889
+ country: country.country,
5890
+ fiatChoice: fiat ? fiatKey(fiat) : "",
5891
+ assetChoice: asset ? assetKey3(asset) : "",
5892
+ amount: DECIMAL.test(amount) ? amount : ""
5893
+ };
5894
+ }
5866
5895
  async function signLegWithWallet(client, orderId, actionId, copy) {
5867
5896
  const lent = [];
5868
5897
  const lend = (chain, encoding, handler) => {
@@ -5897,7 +5926,7 @@ async function signLegWithWallet(client, orderId, actionId, copy) {
5897
5926
  for (const release of lent) release();
5898
5927
  }
5899
5928
  }
5900
- function RampWidget({ onClose, language: languageProp }) {
5929
+ function RampWidget({ onClose, language: languageProp, initial }) {
5901
5930
  const {
5902
5931
  getClient,
5903
5932
  styles,
@@ -5916,7 +5945,10 @@ function RampWidget({ onClose, language: languageProp }) {
5916
5945
  const copy = RAMP_COPY[language];
5917
5946
  const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
5918
5947
  const [step, setStep] = react.useState("input");
5919
- const [direction, setDirection] = react.useState("ONRAMP");
5948
+ const [direction, setDirection] = react.useState(initial?.direction === "sell" ? "OFFRAMP" : "ONRAMP");
5949
+ const seedRef = react.useRef(
5950
+ initial ? { direction: initial.direction === "sell" ? "OFFRAMP" : "ONRAMP", options: initial } : null
5951
+ );
5920
5952
  const [routes, setRoutes] = react.useState([]);
5921
5953
  const [routesLoading, setRoutesLoading] = react.useState(true);
5922
5954
  const [country, setCountry] = react.useState("");
@@ -5970,6 +6002,16 @@ function RampWidget({ onClose, language: languageProp }) {
5970
6002
  try {
5971
6003
  const { routes: found } = await client.getRampRoutes(next);
5972
6004
  setRoutes(found);
6005
+ const seed = seedRef.current?.direction === next ? seedRef.current.options : null;
6006
+ if (seed) seedRef.current = null;
6007
+ const seeded = seed ? seededSelection(found, seed) : null;
6008
+ if (seeded) {
6009
+ setCountry(seeded.country);
6010
+ setFiatChoice(seeded.fiatChoice);
6011
+ setAssetChoice(seeded.assetChoice);
6012
+ setAmount(seeded.amount);
6013
+ return;
6014
+ }
5973
6015
  const first = core.rampCountries(found)[0]?.country ?? "";
5974
6016
  setCountry((current) => found.some((r) => r.fiat.country === current) ? current : first);
5975
6017
  } catch (error) {
@@ -6054,6 +6096,7 @@ function RampWidget({ onClose, language: languageProp }) {
6054
6096
  void resumeRoute(awaitingAccount.routeKey);
6055
6097
  }, [awaitingAccount, resolvedRequest]);
6056
6098
  function handleDirectionChange(next) {
6099
+ seedRef.current = null;
6057
6100
  setDirection(next);
6058
6101
  setErrorMsg(null);
6059
6102
  setAwaitingAccount(null);
@@ -6233,6 +6276,7 @@ function RampWidget({ onClose, language: languageProp }) {
6233
6276
  setErrorMsg(null);
6234
6277
  try {
6235
6278
  const found = await client.getRampOrder(id);
6279
+ seedRef.current = null;
6236
6280
  setDirection(found.direction);
6237
6281
  setOrder(found);
6238
6282
  setStep("status");
@@ -6485,6 +6529,37 @@ function walletNotReadyReason(wallet, chain, language = "en") {
6485
6529
  }
6486
6530
  return null;
6487
6531
  }
6532
+ function seededAmount(amount) {
6533
+ const value = amount?.trim() ?? "";
6534
+ return /^\d+(\.\d+)?$/.test(value) ? value : "";
6535
+ }
6536
+ function byCode(options, code) {
6537
+ const wanted = code?.trim().toUpperCase();
6538
+ return wanted ? options.find((o) => o.code.toUpperCase() === wanted) : void 0;
6539
+ }
6540
+ function oneOf(allowed, value) {
6541
+ return value !== void 0 && allowed.includes(value) ? value : void 0;
6542
+ }
6543
+ function useSuccessReport(transaction, active, onSuccess) {
6544
+ const reported = react.useRef(null);
6545
+ const hash = active && transaction.step === "success" ? transaction.hash : null;
6546
+ react.useEffect(() => {
6547
+ if (!hash || reported.current === hash) return;
6548
+ reported.current = hash;
6549
+ onSuccess?.({ hash });
6550
+ }, [hash, onSuccess]);
6551
+ }
6552
+ function useModalOptions() {
6553
+ const [state, setState] = react.useState({ options: void 0, key: 0 });
6554
+ const seeded = react.useRef(false);
6555
+ const open = react.useCallback((options) => {
6556
+ const given = options !== void 0 && Object.keys(options).length > 0;
6557
+ const remount = given || seeded.current;
6558
+ seeded.current = given;
6559
+ setState((current) => ({ options: given ? options : void 0, key: remount ? current.key + 1 : current.key }));
6560
+ }, []);
6561
+ return [state, open];
6562
+ }
6488
6563
 
6489
6564
  // src/lib/qr-code/index.tsx
6490
6565
  var import_ErrorCorrectLevel = __toESM(require_ErrorCorrectLevel());
@@ -6711,7 +6786,7 @@ function ReceiveModalTemplate({
6711
6786
  }
6712
6787
  );
6713
6788
  }
6714
- function ReceiveModal({ onClose }) {
6789
+ function ReceiveModal({ onClose, initial }) {
6715
6790
  const { wallet, wallets, styles, recoveryLocked, openRecoveryModal } = usePollar();
6716
6791
  const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
6717
6792
  const language = useModalLanguage();
@@ -6720,8 +6795,8 @@ function ReceiveModal({ onClose }) {
6720
6795
  const { chains } = useChains();
6721
6796
  const [selectedChain, setSelectedChain] = react.useState(null);
6722
6797
  react.useEffect(() => {
6723
- if (selectedChain === null && chains.length > 0) setSelectedChain(chains[0]);
6724
- }, [chains, selectedChain]);
6798
+ if (selectedChain === null && chains.length > 0) setSelectedChain(oneOf(chains, initial?.chain) ?? chains[0]);
6799
+ }, [chains, selectedChain, initial?.chain]);
6725
6800
  const walletAddress = addressForChain(wallets, selectedChain);
6726
6801
  const notReadyReason = walletNotReadyReason(wallet, selectedChain, language);
6727
6802
  react.useEffect(
@@ -7968,7 +8043,7 @@ function assetParam(record) {
7968
8043
  }
7969
8044
  return { type: "credit_alphanum12", code: record.code, issuer: record.issuer };
7970
8045
  }
7971
- function SendModal({ onClose }) {
8046
+ function SendModal({ onClose, initial }) {
7972
8047
  const {
7973
8048
  walletBalance,
7974
8049
  refreshWalletBalance,
@@ -7988,10 +8063,13 @@ function SendModal({ onClose }) {
7988
8063
  const [step, setStep] = react.useState("form");
7989
8064
  const [createsAccount, setCreatesAccount] = react.useState(false);
7990
8065
  const [checkingDestination, setCheckingDestination] = react.useState(false);
7991
- const [amount, setAmount] = react.useState("");
7992
- const [destination, setDestination] = react.useState("");
7993
- const [memo, setMemo] = react.useState("");
7994
- const [memoType, setMemoType] = react.useState("text");
8066
+ const [amount, setAmount] = react.useState(() => seededAmount(initial?.amount));
8067
+ const [destination, setDestination] = react.useState(() => initial?.destination?.trim() ?? "");
8068
+ const [memo, setMemo] = react.useState(() => initial?.memo ?? "");
8069
+ const [memoType, setMemoType] = react.useState(
8070
+ () => oneOf(["text", "id", "hash"], initial?.memoType) ?? "text"
8071
+ );
8072
+ const assetSeed = react.useRef(initial?.asset);
7995
8073
  const [selectedAsset, setSelectedAsset] = react.useState(null);
7996
8074
  const [showXdr, setShowXdr] = react.useState(false);
7997
8075
  const [copied, setCopied] = react.useState(false);
@@ -8000,8 +8078,8 @@ function SendModal({ onClose }) {
8000
8078
  const { chains } = useChains();
8001
8079
  const [selectedChain, setSelectedChain] = react.useState(null);
8002
8080
  react.useEffect(() => {
8003
- if (selectedChain === null && chains.length > 0) setSelectedChain(chains[0]);
8004
- }, [chains, selectedChain]);
8081
+ if (selectedChain === null && chains.length > 0) setSelectedChain(oneOf(chains, initial?.chain) ?? chains[0]);
8082
+ }, [chains, selectedChain, initial?.chain]);
8005
8083
  const canSendOnChain = selectedChain === "STELLAR" || selectedChain === "SOLANA" || selectedChain === "POLYGON";
8006
8084
  const notReadyReason = walletNotReadyReason(wallet, selectedChain, language);
8007
8085
  const isBaseUnitChain = selectedChain === "SOLANA" || selectedChain === "POLYGON";
@@ -8028,9 +8106,13 @@ function SendModal({ onClose }) {
8028
8106
  setSelectedAsset(sortedAssets[0] ?? null);
8029
8107
  return;
8030
8108
  }
8031
- if (!selectedAsset && sortedAssets.length > 0) setSelectedAsset(sortedAssets[0]);
8109
+ if (!selectedAsset && sortedAssets.length > 0) {
8110
+ setSelectedAsset(byCode(sortedAssets, assetSeed.current) ?? sortedAssets[0]);
8111
+ assetSeed.current = void 0;
8112
+ }
8032
8113
  }, [sortedAssets, selectedAsset, selectedChain]);
8033
8114
  const hash = transaction.step === "success" ? transaction.hash : null;
8115
+ useSuccessReport(transaction, step === "tx", initial?.onSuccess);
8034
8116
  const buildData = "buildData" in transaction ? transaction.buildData : null;
8035
8117
  const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : buildData ? "public" : network === "testnet" ? "testnet" : "public";
8036
8118
  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}`;
@@ -8850,7 +8932,7 @@ function fromBaseUnits3(units, decimals) {
8850
8932
  function catalogRef(code, issuer) {
8851
8933
  return code.length <= 4 ? { type: "credit_alphanum4", code, issuer } : { type: "credit_alphanum12", code, issuer };
8852
8934
  }
8853
- function SwapModal({ onClose }) {
8935
+ function SwapModal({ onClose, initial }) {
8854
8936
  const {
8855
8937
  getSwapConfig,
8856
8938
  getSwapTokens,
@@ -8871,13 +8953,15 @@ function SwapModal({ onClose }) {
8871
8953
  const language = useModalLanguage();
8872
8954
  const copy = SWAP_COPY[language];
8873
8955
  const walletType = wallet?.custody === "external" ? wallet.provider : null;
8874
- const [chain, setChain] = react.useState("STELLAR");
8956
+ const [chain, setChain] = react.useState(() => oneOf(["STELLAR", "SOLANA"], initial?.chain) ?? "STELLAR");
8957
+ const sellSeed = react.useRef(initial?.sell);
8958
+ const buySeed = react.useRef(initial?.buy);
8875
8959
  const smartUnsupported = chain === "STELLAR" && wallet?.custody === "smart";
8876
8960
  const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
8877
8961
  const [step, setStep] = react.useState("form");
8878
8962
  const [selectedSell, setSelectedSell] = react.useState(null);
8879
8963
  const [selectedBuy, setSelectedBuy] = react.useState(null);
8880
- const [amount, setAmount] = react.useState("");
8964
+ const [amount, setAmount] = react.useState(() => seededAmount(initial?.amount));
8881
8965
  const [provider, setProvider] = react.useState("auto");
8882
8966
  const [venues, setVenues] = react.useState(null);
8883
8967
  const [solanaVenues, setSolanaVenues] = react.useState(null);
@@ -8992,12 +9076,24 @@ function SwapModal({ onClose }) {
8992
9076
  );
8993
9077
  react.useEffect(() => {
8994
9078
  if (sellOptions.length === 0) return;
9079
+ const seeded = byCode(sellOptions, sellSeed.current);
9080
+ if (seeded) {
9081
+ sellSeed.current = void 0;
9082
+ setSelectedSell(seeded);
9083
+ return;
9084
+ }
8995
9085
  if (!selectedSell || !sellOptions.some((o) => optKey(o) === optKey(selectedSell))) {
8996
9086
  setSelectedSell(sellOptions[0]);
8997
9087
  }
8998
9088
  }, [sellOptions, selectedSell]);
8999
9089
  react.useEffect(() => {
9000
9090
  if (buyOptions.length === 0) return;
9091
+ const seeded = byCode(buyOptions, buySeed.current);
9092
+ if (seeded) {
9093
+ buySeed.current = void 0;
9094
+ setSelectedBuy(seeded);
9095
+ return;
9096
+ }
9001
9097
  if (!selectedBuy || !buyOptions.some((o) => optKey(o) === optKey(selectedBuy))) {
9002
9098
  setSelectedBuy(buyOptions[0]);
9003
9099
  }
@@ -9009,6 +9105,7 @@ function SwapModal({ onClose }) {
9009
9105
  if (i.length !== 56 || !i.startsWith("G")) return copy.issuerFormat;
9010
9106
  const opt = { ref: catalogRef(c, i), code: c, issuer: i, enabledInApp: false };
9011
9107
  setCustomTokens((prev) => prev.some((o) => optKey(o) === optKey(opt)) ? prev : [...prev, opt]);
9108
+ buySeed.current = void 0;
9012
9109
  setSelectedBuy(opt);
9013
9110
  return null;
9014
9111
  }
@@ -9041,6 +9138,8 @@ function SwapModal({ onClose }) {
9041
9138
  if (chains.length > 0 && !chains.includes(chain)) setChain(chains[0]);
9042
9139
  }, [chains, chain]);
9043
9140
  function handleChainChange(next) {
9141
+ sellSeed.current = void 0;
9142
+ buySeed.current = void 0;
9044
9143
  setChain(next);
9045
9144
  setSelectedSell(null);
9046
9145
  setSelectedBuy(null);
@@ -9113,6 +9212,7 @@ function SwapModal({ onClose }) {
9113
9212
  copy
9114
9213
  ]);
9115
9214
  const hash = transaction.step === "success" ? transaction.hash : null;
9215
+ useSuccessReport(transaction, step === "tx", initial?.onSuccess);
9116
9216
  const buildData = "buildData" in transaction ? transaction.buildData : null;
9117
9217
  const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : buildData ? "public" : network === "testnet" ? "testnet" : "public";
9118
9218
  const explorerUrl = !hash ? null : chain === "SOLANA" ? `https://solscan.io/tx/${hash}${network === "testnet" ? "?cluster=devnet" : ""}` : `https://stellar.expert/explorer/${explorerNetwork}/tx/${hash}`;
@@ -9175,6 +9275,8 @@ function SwapModal({ onClose }) {
9175
9275
  }
9176
9276
  function handleReverse() {
9177
9277
  if (!selectedSell || !selectedBuy) return;
9278
+ sellSeed.current = void 0;
9279
+ buySeed.current = void 0;
9178
9280
  const previousSell = selectedSell;
9179
9281
  setSelectedSell(selectedBuy);
9180
9282
  setSelectedBuy(previousSell);
@@ -9232,8 +9334,14 @@ function SwapModal({ onClose }) {
9232
9334
  onClose,
9233
9335
  onBack: handleBack,
9234
9336
  onRefresh: handleRefresh,
9235
- onSelectSell: setSelectedSell,
9236
- onSelectBuy: setSelectedBuy,
9337
+ onSelectSell: (option) => {
9338
+ sellSeed.current = void 0;
9339
+ setSelectedSell(option);
9340
+ },
9341
+ onSelectBuy: (option) => {
9342
+ buySeed.current = void 0;
9343
+ setSelectedBuy(option);
9344
+ },
9237
9345
  onReverse: handleReverse,
9238
9346
  onMax: handleMax,
9239
9347
  onAddCustomToken: addCustomToken,
@@ -9249,6 +9357,621 @@ function SwapModal({ onClose }) {
9249
9357
  ) });
9250
9358
  }
9251
9359
 
9360
+ // src/components/bridge-modal/bridge-copy.ts
9361
+ var BRIDGE_COPY = {
9362
+ en: {
9363
+ title: "Move USDC between networks",
9364
+ close: "Close",
9365
+ back: "Back",
9366
+ loading: "Loading\u2026",
9367
+ mainnetOnly: "Moving USDC between networks works on mainnet only.",
9368
+ noDirections: "You need a wallet on at least two networks of this app to move USDC between them.",
9369
+ from: "From",
9370
+ to: "To",
9371
+ amount: "Amount (USDC)",
9372
+ balance: "Balance",
9373
+ max: "Max",
9374
+ youReceive: "You receive",
9375
+ fee: "Fee",
9376
+ noFee: "No fee",
9377
+ eta: "Estimated time",
9378
+ etaValue: "about {minutes} min",
9379
+ signingInternal: "Your wallet sends it right away.",
9380
+ signingCosigned: "You approve it on your device.",
9381
+ signingExternal: "You sign it in your wallet.",
9382
+ quoting: "Getting a quote\u2026",
9383
+ bridgeButton: "Move USDC",
9384
+ starting: "Starting\u2026",
9385
+ invalidAmount: "Enter an amount with up to 6 decimals.",
9386
+ overBalance: "The amount is more than your balance.",
9387
+ statusTitle: {
9388
+ PENDING: "Sending",
9389
+ AWAITING_ACTION: "Your approval is needed",
9390
+ BURNED: "On its way",
9391
+ ATTESTED: "Arriving",
9392
+ COMPLETED: "Done",
9393
+ FAILED: "It did not go through",
9394
+ HELD: "Under review"
9395
+ },
9396
+ statusBody: {
9397
+ PENDING: "Your USDC is leaving your {from} wallet.",
9398
+ AWAITING_ACTION: "Approve the step below to continue.",
9399
+ BURNED: "Circle is confirming the transfer. This takes a few minutes.",
9400
+ ATTESTED: "Your USDC is being delivered to your {to} wallet.",
9401
+ COMPLETED: "{amount} USDC arrived in your {to} wallet.",
9402
+ FAILED: "Nothing left your wallet. You can try again.",
9403
+ HELD: "Your USDC left your {from} wallet but did not arrive yet. Our team is on it; no action is needed from you."
9404
+ },
9405
+ steps: { burn: "Leaves {from}", attest: "Confirmed by Circle", mint: "Arrives on {to}" },
9406
+ authorize: "Authorize",
9407
+ waitingWallet: "Waiting for your wallet\u2026",
9408
+ approveOnDevice: "Approve on your device",
9409
+ viewBurn: "View on {chain}",
9410
+ viewMint: "View on {chain}",
9411
+ done: "Done",
9412
+ newBridge: "Move more",
9413
+ pollTrouble: "We could not refresh the status. Retrying\u2026",
9414
+ errors: {
9415
+ mainnetOnly: "Moving USDC between networks works on mainnet only.",
9416
+ chainNotEnabled: "This app does not use one of these networks.",
9417
+ noGasWallet: "This app cannot pay the network fees for this move right now.",
9418
+ noWallet: (chain) => `You do not have a wallet on ${chain} yet.`,
9419
+ noTrustline: "Your Stellar wallet needs to accept USDC first.",
9420
+ connectSolanaWallet: "Connect the Solana wallet this move leaves from to sign.",
9421
+ unsupportedWallet: "This wallet cannot move USDC between networks.",
9422
+ credits: "This app cannot cover this operation right now.",
9423
+ actionChanged: "The step changed. Review it and authorize again.",
9424
+ connectStellarWallet: "Connect your Stellar wallet to sign.",
9425
+ walletChanged: "The connected wallet changed. Try again.",
9426
+ signingCancelled: "The signature was cancelled.",
9427
+ generic: "Something went wrong. Try again."
9428
+ }
9429
+ },
9430
+ es: {
9431
+ title: "Mover USDC entre redes",
9432
+ close: "Cerrar",
9433
+ back: "Volver",
9434
+ loading: "Cargando\u2026",
9435
+ mainnetOnly: "Mover USDC entre redes solo funciona en mainnet.",
9436
+ noDirections: "Necesitas una wallet en al menos dos redes de esta app para mover USDC entre ellas.",
9437
+ from: "Desde",
9438
+ to: "Hacia",
9439
+ amount: "Monto (USDC)",
9440
+ balance: "Saldo",
9441
+ max: "M\xE1x",
9442
+ youReceive: "Recibes",
9443
+ fee: "Comisi\xF3n",
9444
+ noFee: "Sin comisi\xF3n",
9445
+ eta: "Tiempo estimado",
9446
+ etaValue: "unos {minutes} min",
9447
+ signingInternal: "Tu wallet lo env\xEDa de inmediato.",
9448
+ signingCosigned: "Lo apruebas en tu dispositivo.",
9449
+ signingExternal: "Lo firmas en tu wallet.",
9450
+ quoting: "Cotizando\u2026",
9451
+ bridgeButton: "Mover USDC",
9452
+ starting: "Iniciando\u2026",
9453
+ invalidAmount: "Ingresa un monto con hasta 6 decimales.",
9454
+ overBalance: "El monto es mayor que tu saldo.",
9455
+ statusTitle: {
9456
+ PENDING: "Enviando",
9457
+ AWAITING_ACTION: "Falta tu aprobaci\xF3n",
9458
+ BURNED: "En camino",
9459
+ ATTESTED: "Llegando",
9460
+ COMPLETED: "Listo",
9461
+ FAILED: "No se complet\xF3",
9462
+ HELD: "En revisi\xF3n"
9463
+ },
9464
+ statusBody: {
9465
+ PENDING: "Tu USDC est\xE1 saliendo de tu wallet de {from}.",
9466
+ AWAITING_ACTION: "Aprueba el paso de abajo para continuar.",
9467
+ BURNED: "Circle est\xE1 confirmando la transferencia. Tarda unos minutos.",
9468
+ ATTESTED: "Tu USDC se est\xE1 entregando en tu wallet de {to}.",
9469
+ COMPLETED: "Llegaron {amount} USDC a tu wallet de {to}.",
9470
+ FAILED: "No sali\xF3 nada de tu wallet. Puedes intentarlo de nuevo.",
9471
+ 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."
9472
+ },
9473
+ steps: { burn: "Sale de {from}", attest: "Confirmado por Circle", mint: "Llega a {to}" },
9474
+ authorize: "Autorizar",
9475
+ waitingWallet: "Esperando a tu wallet\u2026",
9476
+ approveOnDevice: "Aprobar en tu dispositivo",
9477
+ viewBurn: "Ver en {chain}",
9478
+ viewMint: "Ver en {chain}",
9479
+ done: "Listo",
9480
+ newBridge: "Mover m\xE1s",
9481
+ pollTrouble: "No pudimos actualizar el estado. Reintentando\u2026",
9482
+ errors: {
9483
+ mainnetOnly: "Mover USDC entre redes solo funciona en mainnet.",
9484
+ chainNotEnabled: "Esta app no usa una de estas redes.",
9485
+ noGasWallet: "Esta app no puede pagar ahora las comisiones de red de este movimiento.",
9486
+ noWallet: (chain) => `Todav\xEDa no tienes una wallet en ${chain}.`,
9487
+ noTrustline: "Tu wallet de Stellar primero tiene que aceptar USDC.",
9488
+ connectSolanaWallet: "Conecta la wallet de Solana desde la que sale este movimiento para firmar.",
9489
+ unsupportedWallet: "Esta wallet no puede mover USDC entre redes.",
9490
+ credits: "Esta app no puede cubrir esta operaci\xF3n ahora.",
9491
+ actionChanged: "El paso cambi\xF3. Rev\xEDsalo y autoriza de nuevo.",
9492
+ connectStellarWallet: "Conecta tu wallet de Stellar para firmar.",
9493
+ walletChanged: "Cambi\xF3 la wallet conectada. Int\xE9ntalo de nuevo.",
9494
+ signingCancelled: "Se cancel\xF3 la firma.",
9495
+ generic: "Algo sali\xF3 mal. Int\xE9ntalo de nuevo."
9496
+ }
9497
+ },
9498
+ pt: {
9499
+ title: "Mover USDC entre redes",
9500
+ close: "Fechar",
9501
+ back: "Voltar",
9502
+ loading: "Carregando\u2026",
9503
+ mainnetOnly: "Mover USDC entre redes funciona s\xF3 na mainnet.",
9504
+ noDirections: "Voc\xEA precisa de uma carteira em pelo menos duas redes deste app para mover USDC entre elas.",
9505
+ from: "De",
9506
+ to: "Para",
9507
+ amount: "Valor (USDC)",
9508
+ balance: "Saldo",
9509
+ max: "M\xE1x",
9510
+ youReceive: "Voc\xEA recebe",
9511
+ fee: "Taxa",
9512
+ noFee: "Sem taxa",
9513
+ eta: "Tempo estimado",
9514
+ etaValue: "cerca de {minutes} min",
9515
+ signingInternal: "Sua carteira envia na hora.",
9516
+ signingCosigned: "Voc\xEA aprova no seu dispositivo.",
9517
+ signingExternal: "Voc\xEA assina na sua carteira.",
9518
+ quoting: "Cotando\u2026",
9519
+ bridgeButton: "Mover USDC",
9520
+ starting: "Iniciando\u2026",
9521
+ invalidAmount: "Informe um valor com at\xE9 6 casas decimais.",
9522
+ overBalance: "O valor \xE9 maior que o seu saldo.",
9523
+ statusTitle: {
9524
+ PENDING: "Enviando",
9525
+ AWAITING_ACTION: "Falta a sua aprova\xE7\xE3o",
9526
+ BURNED: "A caminho",
9527
+ ATTESTED: "Chegando",
9528
+ COMPLETED: "Pronto",
9529
+ FAILED: "N\xE3o foi conclu\xEDdo",
9530
+ HELD: "Em an\xE1lise"
9531
+ },
9532
+ statusBody: {
9533
+ PENDING: "Seu USDC est\xE1 saindo da sua carteira na {from}.",
9534
+ AWAITING_ACTION: "Aprove o passo abaixo para continuar.",
9535
+ BURNED: "A Circle est\xE1 confirmando a transfer\xEAncia. Leva alguns minutos.",
9536
+ ATTESTED: "Seu USDC est\xE1 sendo entregue na sua carteira na {to}.",
9537
+ COMPLETED: "{amount} USDC chegaram na sua carteira na {to}.",
9538
+ FAILED: "Nada saiu da sua carteira. Voc\xEA pode tentar de novo.",
9539
+ 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."
9540
+ },
9541
+ steps: { burn: "Sai da {from}", attest: "Confirmado pela Circle", mint: "Chega na {to}" },
9542
+ authorize: "Autorizar",
9543
+ waitingWallet: "Aguardando sua carteira\u2026",
9544
+ approveOnDevice: "Aprovar no dispositivo",
9545
+ viewBurn: "Ver na {chain}",
9546
+ viewMint: "Ver na {chain}",
9547
+ done: "Pronto",
9548
+ newBridge: "Mover mais",
9549
+ pollTrouble: "N\xE3o conseguimos atualizar o status. Tentando de novo\u2026",
9550
+ errors: {
9551
+ mainnetOnly: "Mover USDC entre redes funciona s\xF3 na mainnet.",
9552
+ chainNotEnabled: "Este app n\xE3o usa uma dessas redes.",
9553
+ noGasWallet: "Este app n\xE3o consegue pagar agora as taxas de rede deste movimento.",
9554
+ noWallet: (chain) => `Voc\xEA ainda n\xE3o tem uma carteira na ${chain}.`,
9555
+ noTrustline: "Sua carteira Stellar precisa aceitar USDC primeiro.",
9556
+ connectSolanaWallet: "Conecte a carteira Solana de onde sai este movimento para assinar.",
9557
+ unsupportedWallet: "Esta carteira n\xE3o pode mover USDC entre redes.",
9558
+ credits: "Este app n\xE3o consegue cobrir esta opera\xE7\xE3o agora.",
9559
+ actionChanged: "O passo mudou. Revise e autorize de novo.",
9560
+ connectStellarWallet: "Conecte sua carteira Stellar para assinar.",
9561
+ walletChanged: "A carteira conectada mudou. Tente de novo.",
9562
+ signingCancelled: "A assinatura foi cancelada.",
9563
+ generic: "Algo deu errado. Tente de novo."
9564
+ }
9565
+ }
9566
+ };
9567
+ var BRIDGE_CHAIN_LABEL = {
9568
+ STELLAR: "Stellar",
9569
+ SOLANA: "Solana",
9570
+ POLYGON: "Polygon"
9571
+ };
9572
+ var EXPLORER = {
9573
+ STELLAR: (hash) => `https://stellar.expert/explorer/public/tx/${hash}`,
9574
+ SOLANA: (hash) => `https://solscan.io/tx/${hash}`,
9575
+ POLYGON: (hash) => `https://polygonscan.com/tx/${hash}`
9576
+ };
9577
+ var fill = (text, values) => text.replace(/\{(\w+)\}/g, (_, key) => values[key] ?? `{${key}}`);
9578
+ function ChainPicker({
9579
+ label,
9580
+ value,
9581
+ options,
9582
+ onChange,
9583
+ disabled
9584
+ }) {
9585
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "pollar-bridge-field", children: [
9586
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "pollar-bridge-label", children: label }),
9587
+ /* @__PURE__ */ jsxRuntime.jsx(
9588
+ "select",
9589
+ {
9590
+ className: "pollar-input",
9591
+ value: value ?? "",
9592
+ disabled: disabled || options.length === 0,
9593
+ onChange: (event) => onChange(event.target.value),
9594
+ children: options.map((chain) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: chain, children: BRIDGE_CHAIN_LABEL[chain] }, chain))
9595
+ }
9596
+ )
9597
+ ] });
9598
+ }
9599
+ function Progress({ transfer, labels }) {
9600
+ const reached = {
9601
+ burn: !!transfer.burnTxHash,
9602
+ attest: transfer.status === "ATTESTED" || transfer.status === "COMPLETED" || !!transfer.mintTxHash,
9603
+ mint: transfer.status === "COMPLETED"
9604
+ };
9605
+ return /* @__PURE__ */ jsxRuntime.jsx("ol", { className: "pollar-bridge-steps", children: ["burn", "attest", "mint"].map((key) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: reached[key] ? "pollar-bridge-step pollar-bridge-step-done" : "pollar-bridge-step", children: [
9606
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "pollar-bridge-step-dot", "aria-hidden": true }),
9607
+ labels[key]
9608
+ ] }, key)) });
9609
+ }
9610
+ function BridgeModalTemplate(props) {
9611
+ const language = useInheritedLanguage(props.language);
9612
+ const copy = BRIDGE_COPY[language];
9613
+ const cssVars = buildModalCssVars(props.theme, props.accentColor, props.styleOverrides);
9614
+ const { transfer, quote } = props;
9615
+ const busy = props.submitting || props.quoting;
9616
+ const toName = props.toChain ? BRIDGE_CHAIN_LABEL[props.toChain] : "";
9617
+ const signingNote = quote?.signing === "EXTERNAL" ? copy.signingExternal : quote?.signing === "COSIGNED" || quote?.signing === "SELF_CUSTODY" ? copy.signingCosigned : copy.signingInternal;
9618
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9619
+ "div",
9620
+ {
9621
+ className: "pollar-modal-card pollar-bridge-modal",
9622
+ "data-theme": props.theme,
9623
+ style: cssVars,
9624
+ onClick: (event) => event.stopPropagation(),
9625
+ children: [
9626
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-modal-header", children: [
9627
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "pollar-modal-title", children: copy.title }),
9628
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-modal-header-actions", children: /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "pollar-modal-close", onClick: props.onClose, "aria-label": copy.close, children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 2l12 12M14 2L2 14", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) }) })
9629
+ ] }),
9630
+ props.step === "loading" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-modal-empty", children: copy.loading }),
9631
+ props.step === "unavailable" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-modal-empty", children: props.unavailableReason === "mainnet_only" ? copy.mainnetOnly : copy.noDirections }),
9632
+ props.step === "form" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-bridge-form", children: [
9633
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-bridge-chains", children: [
9634
+ /* @__PURE__ */ jsxRuntime.jsx(
9635
+ ChainPicker,
9636
+ {
9637
+ label: copy.from,
9638
+ value: props.fromChain,
9639
+ options: props.sources,
9640
+ onChange: props.onFromChange,
9641
+ disabled: busy
9642
+ }
9643
+ ),
9644
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "pollar-bridge-arrow", "aria-hidden": true, children: "\u2192" }),
9645
+ /* @__PURE__ */ jsxRuntime.jsx(
9646
+ ChainPicker,
9647
+ {
9648
+ label: copy.to,
9649
+ value: props.toChain,
9650
+ options: props.targets,
9651
+ onChange: props.onToChange,
9652
+ disabled: busy
9653
+ }
9654
+ )
9655
+ ] }),
9656
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "pollar-bridge-field", children: [
9657
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "pollar-bridge-label-row", children: [
9658
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "pollar-bridge-label", children: copy.amount }),
9659
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "pollar-bridge-balance", children: [
9660
+ copy.balance,
9661
+ " ",
9662
+ props.balance ?? "\u2014",
9663
+ props.balance !== null && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "pollar-bridge-max", onClick: props.onMax, disabled: busy, children: copy.max })
9664
+ ] })
9665
+ ] }),
9666
+ /* @__PURE__ */ jsxRuntime.jsx(
9667
+ "input",
9668
+ {
9669
+ className: "pollar-input",
9670
+ type: "text",
9671
+ inputMode: "decimal",
9672
+ placeholder: "0.00",
9673
+ value: props.amount,
9674
+ disabled: props.submitting,
9675
+ onChange: (event) => props.onAmountChange(event.target.value)
9676
+ }
9677
+ )
9678
+ ] }),
9679
+ props.quoting && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-bridge-note", children: copy.quoting }),
9680
+ quote && !props.quoting && /* @__PURE__ */ jsxRuntime.jsxs("dl", { className: "pollar-bridge-quote", children: [
9681
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9682
+ /* @__PURE__ */ jsxRuntime.jsx("dt", { children: copy.youReceive }),
9683
+ /* @__PURE__ */ jsxRuntime.jsxs("dd", { children: [
9684
+ quote.amountOut,
9685
+ " USDC \xB7 ",
9686
+ toName
9687
+ ] })
9688
+ ] }),
9689
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9690
+ /* @__PURE__ */ jsxRuntime.jsx("dt", { children: copy.fee }),
9691
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { children: quote.fee ? `${quote.fee.amount} USD` : copy.noFee })
9692
+ ] }),
9693
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9694
+ /* @__PURE__ */ jsxRuntime.jsx("dt", { children: copy.eta }),
9695
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { children: fill(copy.etaValue, { minutes: String(Math.max(1, Math.round(quote.etaSeconds / 60))) }) })
9696
+ ] }),
9697
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "pollar-bridge-note", children: signingNote })
9698
+ ] }),
9699
+ props.formError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-modal-error", children: props.formError }),
9700
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-modal-actions", children: /* @__PURE__ */ jsxRuntime.jsx(
9701
+ "button",
9702
+ {
9703
+ type: "button",
9704
+ className: "pollar-btn-primary",
9705
+ disabled: !props.canSubmit || props.submitting,
9706
+ onClick: props.onSubmit,
9707
+ children: props.submitting ? copy.starting : copy.bridgeButton
9708
+ }
9709
+ ) })
9710
+ ] }),
9711
+ props.step === "transfer" && transfer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-bridge-transfer", children: [
9712
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `pollar-bridge-status pollar-bridge-status-${transfer.status.toLowerCase()}`, children: [
9713
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: copy.statusTitle[transfer.status] }),
9714
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: fill(copy.statusBody[transfer.status], {
9715
+ from: BRIDGE_CHAIN_LABEL[transfer.fromChain],
9716
+ to: BRIDGE_CHAIN_LABEL[transfer.toChain],
9717
+ amount: transfer.amountOut ?? transfer.amount
9718
+ }) })
9719
+ ] }),
9720
+ /* @__PURE__ */ jsxRuntime.jsx(
9721
+ Progress,
9722
+ {
9723
+ transfer,
9724
+ labels: {
9725
+ burn: fill(copy.steps.burn, { from: BRIDGE_CHAIN_LABEL[transfer.fromChain] }),
9726
+ attest: copy.steps.attest,
9727
+ mint: fill(copy.steps.mint, { to: BRIDGE_CHAIN_LABEL[transfer.toChain] })
9728
+ }
9729
+ }
9730
+ ),
9731
+ transfer.pendingAction?.kind === "SIGNATURE" && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "pollar-btn-primary", disabled: props.signing, onClick: props.onAuthorize, children: props.signing ? copy.waitingWallet : copy.authorize }),
9732
+ transfer.pendingAction?.kind === "COSIGN_APPROVAL" && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "pollar-btn-primary", onClick: props.onApprove, children: copy.approveOnDevice }),
9733
+ props.actionError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-modal-error", children: props.actionError }),
9734
+ props.pollTrouble && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-bridge-note", children: copy.pollTrouble }),
9735
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-bridge-links", children: [
9736
+ transfer.burnTxHash && /* @__PURE__ */ jsxRuntime.jsx("a", { href: EXPLORER[transfer.fromChain](transfer.burnTxHash), target: "_blank", rel: "noopener noreferrer", children: fill(copy.viewBurn, { chain: BRIDGE_CHAIN_LABEL[transfer.fromChain] }) }),
9737
+ transfer.mintTxHash && /* @__PURE__ */ jsxRuntime.jsx("a", { href: EXPLORER[transfer.toChain](transfer.mintTxHash), target: "_blank", rel: "noopener noreferrer", children: fill(copy.viewMint, { chain: BRIDGE_CHAIN_LABEL[transfer.toChain] }) })
9738
+ ] }),
9739
+ (transfer.status === "COMPLETED" || transfer.status === "FAILED") && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-modal-actions", children: [
9740
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "pollar-btn-secondary", onClick: props.onNewBridge, children: copy.newBridge }),
9741
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "pollar-btn-primary", onClick: props.onClose, children: copy.done })
9742
+ ] })
9743
+ ] }),
9744
+ /* @__PURE__ */ jsxRuntime.jsx(PollarModalFooter, {})
9745
+ ]
9746
+ }
9747
+ );
9748
+ }
9749
+ var AMOUNT = /^(?:0|[1-9]\d{0,11})(?:\.\d{1,6})?$/;
9750
+ var QUOTE_DEBOUNCE_MS2 = 400;
9751
+ function errorText(error, copy) {
9752
+ if (!core.isPollarApiError(error)) return copy.errors.generic;
9753
+ const reason = typeof error.body.reason === "string" ? error.body.reason : null;
9754
+ const chain = typeof error.body.chain === "string" ? BRIDGE_CHAIN_LABEL[error.body.chain] ?? "" : "";
9755
+ switch (error.code) {
9756
+ case "SDK_BRIDGE_UNAVAILABLE":
9757
+ if (reason === "mainnet_only") return copy.errors.mainnetOnly;
9758
+ if (reason === "chain_not_enabled") return copy.errors.chainNotEnabled;
9759
+ return copy.errors.noGasWallet;
9760
+ case "SDK_BRIDGE_WALLET_NOT_READY":
9761
+ if (reason === "no_usdc_trustline") return copy.errors.noTrustline;
9762
+ if (reason === "no_wallet") return copy.errors.noWallet(chain);
9763
+ return copy.errors.unsupportedWallet;
9764
+ case "SDK_CREDITS_INSUFFICIENT":
9765
+ case "SDK_BILLING_OVERDUE":
9766
+ return copy.errors.credits;
9767
+ case "SDK_BRIDGE_ACTION_CHANGED":
9768
+ return copy.errors.actionChanged;
9769
+ default:
9770
+ return copy.errors.generic;
9771
+ }
9772
+ }
9773
+ function solanaBurnSigner(client, copy) {
9774
+ return async (action) => {
9775
+ const payload = JSON.parse(action.payload.value);
9776
+ const solanaWallet = () => client.getWallets().find((w) => w.chain === "SOLANA" && w.custody === "external");
9777
+ const wallet = solanaWallet();
9778
+ if (!wallet || payload.from !== wallet.address || !payload.unsignedTransaction)
9779
+ throw new Error(copy.errors.connectSolanaWallet);
9780
+ const signed = await client.signSolanaTransaction(payload.unsignedTransaction);
9781
+ if (solanaWallet()?.address !== wallet.address) throw new Error(copy.errors.walletChanged);
9782
+ return signed;
9783
+ };
9784
+ }
9785
+ async function signStepWithWallet(client, transferId, actionId, copy) {
9786
+ const lent = [];
9787
+ const lend = (chain, encoding, handler) => {
9788
+ try {
9789
+ lent.push(client.registerRampSigningHandler(chain, encoding, handler));
9790
+ } catch {
9791
+ }
9792
+ };
9793
+ lend("SOLANA", "solana-cctp-json", solanaBurnSigner(client, copy));
9794
+ lend("STELLAR", "xdr", async (action) => {
9795
+ const wallet = client.getWallet();
9796
+ if (!wallet) throw new Error(copy.errors.connectStellarWallet);
9797
+ core.assertRampStellarSigner(action, wallet.address);
9798
+ const outcome = await client.signTx(action.payload.value);
9799
+ if (client.getWallet()?.address !== wallet.address) throw new Error(copy.errors.walletChanged);
9800
+ if (outcome.status === "signed") return outcome.signedXdr;
9801
+ throw new Error(
9802
+ outcome.status === "error" ? outcome.message ?? outcome.details ?? copy.errors.signingCancelled : copy.errors.signingCancelled
9803
+ );
9804
+ });
9805
+ try {
9806
+ return await client.signBridgeStep(transferId, actionId);
9807
+ } finally {
9808
+ for (const release of lent) release();
9809
+ }
9810
+ }
9811
+ function newIntentKey() {
9812
+ return typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
9813
+ }
9814
+ function BridgeModal({ onClose, initial }) {
9815
+ const { getClient, styles, walletBalance, refreshWalletBalance, openCosignModal } = usePollar();
9816
+ const language = useModalLanguage();
9817
+ const copy = BRIDGE_COPY[language];
9818
+ const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
9819
+ const client = getClient();
9820
+ const [config, setConfig] = react.useState(null);
9821
+ const [configError, setConfigError] = react.useState(null);
9822
+ const [fromChain, setFromChain] = react.useState(null);
9823
+ const [toChain, setToChain] = react.useState(null);
9824
+ const [amount, setAmount] = react.useState(() => seededAmount(initial?.amount));
9825
+ const [quote, setQuote] = react.useState(null);
9826
+ const [quoting, setQuoting] = react.useState(false);
9827
+ const [quoteError, setQuoteError] = react.useState(null);
9828
+ const [submitting, setSubmitting] = react.useState(false);
9829
+ const [transfer, setTransfer] = react.useState(null);
9830
+ const [signing, setSigning] = react.useState(false);
9831
+ const [actionError, setActionError] = react.useState(null);
9832
+ const [pollTrouble, setPollTrouble] = react.useState(false);
9833
+ const intentKey = react.useRef(newIntentKey());
9834
+ react.useEffect(() => {
9835
+ let cancelled = false;
9836
+ client.getBridgeConfig().then((loaded) => {
9837
+ if (cancelled) return;
9838
+ setConfig(loaded);
9839
+ const sources2 = core.bridgeSourceChains(loaded);
9840
+ const from = oneOf(sources2, initial?.fromChain) ?? sources2[0] ?? null;
9841
+ const targets2 = from ? core.bridgeTargetChains(loaded, from) : [];
9842
+ setFromChain(from);
9843
+ setToChain(oneOf(targets2, initial?.toChain) ?? targets2[0] ?? null);
9844
+ }).catch((error) => !cancelled && setConfigError(errorText(error, copy)));
9845
+ return () => {
9846
+ cancelled = true;
9847
+ };
9848
+ }, [client]);
9849
+ const sources = react.useMemo(() => config ? core.bridgeSourceChains(config) : [], [config]);
9850
+ const targets = react.useMemo(() => config && fromChain ? core.bridgeTargetChains(config, fromChain) : [], [config, fromChain]);
9851
+ const balance = react.useMemo(() => {
9852
+ if (walletBalance.step !== "loaded" || !fromChain) return null;
9853
+ const usdc = walletBalance.data.balances.find((b) => (b.chain ?? "STELLAR") === fromChain && b.code === "USDC");
9854
+ return usdc ? usdc.available ?? usdc.balance : "0";
9855
+ }, [walletBalance, fromChain]);
9856
+ const amountValid = AMOUNT.test(amount) && Number(amount) > 0;
9857
+ const overBalance = amountValid && balance !== null && Number(amount) > Number(balance);
9858
+ const formError = configError ?? quoteError ?? (amount && !amountValid ? copy.invalidAmount : null) ?? (overBalance ? copy.overBalance : null);
9859
+ react.useEffect(() => {
9860
+ setQuote(null);
9861
+ setQuoteError(null);
9862
+ if (!fromChain || !toChain || !amountValid) return;
9863
+ let cancelled = false;
9864
+ const timer = setTimeout(() => {
9865
+ setQuoting(true);
9866
+ client.quoteBridge({ fromChain, toChain, amount }).then((next) => !cancelled && setQuote(next)).catch((error) => !cancelled && setQuoteError(errorText(error, copy))).finally(() => !cancelled && setQuoting(false));
9867
+ }, QUOTE_DEBOUNCE_MS2);
9868
+ return () => {
9869
+ cancelled = true;
9870
+ clearTimeout(timer);
9871
+ };
9872
+ }, [client, fromChain, toChain, amount, amountValid]);
9873
+ react.useEffect(() => {
9874
+ if (!transfer || core.isBridgeSettled(transfer)) return;
9875
+ const controller = new AbortController();
9876
+ client.pollBridgeTransfer(transfer.id, {
9877
+ signal: controller.signal,
9878
+ onUpdate: (next) => {
9879
+ setPollTrouble(false);
9880
+ setTransfer(next);
9881
+ },
9882
+ onError: () => setPollTrouble(true),
9883
+ // A co-signed step moves once the device approves: keep reading through it.
9884
+ until: (next) => next.status === "AWAITING_ACTION" && next.pendingAction?.kind === "SIGNATURE"
9885
+ }).then((settled) => {
9886
+ if (settled.status === "COMPLETED") void refreshWalletBalance();
9887
+ }).catch(() => {
9888
+ });
9889
+ return () => controller.abort();
9890
+ }, [client, transfer?.id, transfer?.pendingAction?.actionId]);
9891
+ const reported = react.useRef(null);
9892
+ const onSuccess = initial?.onSuccess;
9893
+ react.useEffect(() => {
9894
+ if (transfer?.status !== "COMPLETED" || reported.current === transfer.id) return;
9895
+ reported.current = transfer.id;
9896
+ onSuccess?.(transfer);
9897
+ }, [transfer, onSuccess]);
9898
+ async function submit() {
9899
+ if (!fromChain || !toChain || !amountValid || overBalance) return;
9900
+ setSubmitting(true);
9901
+ setQuoteError(null);
9902
+ try {
9903
+ const started = await client.bridge({ fromChain, toChain, amount, idempotencyKey: intentKey.current });
9904
+ setTransfer(started);
9905
+ } catch (error) {
9906
+ setQuoteError(errorText(error, copy));
9907
+ } finally {
9908
+ setSubmitting(false);
9909
+ }
9910
+ }
9911
+ async function authorize() {
9912
+ const action = transfer?.pendingAction;
9913
+ if (!transfer || action?.kind !== "SIGNATURE") return;
9914
+ setSigning(true);
9915
+ setActionError(null);
9916
+ try {
9917
+ setTransfer(await signStepWithWallet(client, transfer.id, action.actionId, copy));
9918
+ } catch (error) {
9919
+ setActionError(error instanceof Error && !core.isPollarApiError(error) ? error.message : errorText(error, copy));
9920
+ client.getBridgeTransfer(transfer.id).then(setTransfer).catch(() => {
9921
+ });
9922
+ } finally {
9923
+ setSigning(false);
9924
+ }
9925
+ }
9926
+ function newBridge() {
9927
+ intentKey.current = newIntentKey();
9928
+ setTransfer(null);
9929
+ setAmount("");
9930
+ setActionError(null);
9931
+ void refreshWalletBalance();
9932
+ }
9933
+ const step = transfer ? "transfer" : !config && !configError ? "loading" : config && (!config.available || sources.length === 0) ? "unavailable" : "form";
9934
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-overlay", style: overlayStyle, onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsx(
9935
+ BridgeModalTemplate,
9936
+ {
9937
+ theme,
9938
+ accentColor,
9939
+ styleOverrides,
9940
+ step,
9941
+ unavailableReason: config?.reason === "mainnet_only" ? "mainnet_only" : config ? "no_directions" : null,
9942
+ sources,
9943
+ targets,
9944
+ fromChain,
9945
+ toChain,
9946
+ onFromChange: (chain) => {
9947
+ setFromChain(chain);
9948
+ const next = config ? core.bridgeTargetChains(config, chain) : [];
9949
+ if (!toChain || !next.includes(toChain)) setToChain(next[0] ?? null);
9950
+ },
9951
+ onToChange: setToChain,
9952
+ amount,
9953
+ onAmountChange: (value) => setAmount(value.replace(",", ".").trim()),
9954
+ balance,
9955
+ onMax: () => balance !== null && setAmount(balance.replace(/(\.\d{6})\d+$/, "$1")),
9956
+ quote,
9957
+ quoting,
9958
+ formError,
9959
+ canSubmit: !!quote && !quoting && amountValid && !overBalance,
9960
+ submitting,
9961
+ onSubmit: () => void submit(),
9962
+ transfer,
9963
+ signing,
9964
+ onAuthorize: () => void authorize(),
9965
+ onApprove: openCosignModal,
9966
+ actionError,
9967
+ pollTrouble,
9968
+ onNewBridge: newBridge,
9969
+ onClose,
9970
+ language
9971
+ }
9972
+ ) });
9973
+ }
9974
+
9252
9975
  // src/components/earn-modal/earn-copy.ts
9253
9976
  var EARN_COPY = {
9254
9977
  en: {
@@ -9374,7 +10097,7 @@ function formatAmount3(value) {
9374
10097
  const n = parseFloat(value);
9375
10098
  return isNaN(n) ? value : n.toLocaleString(void 0, { maximumFractionDigits: 7 });
9376
10099
  }
9377
- function EarnModal({ onClose }) {
10100
+ function EarnModal({ onClose, initial }) {
9378
10101
  const {
9379
10102
  getEarnProviders,
9380
10103
  getEarnOpportunities,
@@ -9395,13 +10118,15 @@ function EarnModal({ onClose }) {
9395
10118
  const smartUnsupported = wallet?.custody === "smart";
9396
10119
  const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
9397
10120
  const [step, setStep] = react.useState("form");
9398
- const [tab, setTab] = react.useState("deposit");
10121
+ const [tab, setTab] = react.useState(
10122
+ () => oneOf(["deposit", "withdraw"], initial?.tab) ?? "deposit"
10123
+ );
9399
10124
  const [providers, setProviders] = react.useState(null);
9400
10125
  const [provider, setProvider] = react.useState(null);
9401
10126
  const [opportunities, setOpportunities] = react.useState([]);
9402
- const [opportunityId, setOpportunityId] = react.useState("");
10127
+ const [opportunityId, setOpportunityId] = react.useState(() => initial?.opportunityId ?? "");
9403
10128
  const [position, setPosition] = react.useState(null);
9404
- const [amount, setAmount] = react.useState("");
10129
+ const [amount, setAmount] = react.useState(() => seededAmount(initial?.amount));
9405
10130
  const [loadingOpps, setLoadingOpps] = react.useState(false);
9406
10131
  const [formError, setFormError] = react.useState("");
9407
10132
  const [refreshing, setRefreshing] = react.useState(false);
@@ -9412,9 +10137,9 @@ function EarnModal({ onClose }) {
9412
10137
  setProviders(null);
9413
10138
  return getEarnProviders().then((ps) => {
9414
10139
  setProviders(ps);
9415
- setProvider((cur) => cur ?? ps[0] ?? null);
10140
+ setProvider((cur) => cur ?? oneOf(ps, initial?.provider) ?? ps[0] ?? null);
9416
10141
  }).catch(() => setProviders([]));
9417
- }, [getEarnProviders]);
10142
+ }, [getEarnProviders, initial?.provider]);
9418
10143
  react.useEffect(() => {
9419
10144
  void loadProviders();
9420
10145
  }, [loadProviders]);
@@ -9476,6 +10201,7 @@ function EarnModal({ onClose }) {
9476
10201
  })();
9477
10202
  const depositNeedsTrustline = tab === "deposit" && !smartUnsupported && !!selectedOpportunity?.asset.issuer && !depositAssetRecord?.trustlineEstablished;
9478
10203
  const hash = transaction.step === "success" ? transaction.hash : null;
10204
+ useSuccessReport(transaction, step === "tx", initial?.onSuccess);
9479
10205
  const buildData = "buildData" in transaction ? transaction.buildData : null;
9480
10206
  const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : buildData ? "public" : network === "testnet" ? "testnet" : "public";
9481
10207
  const explorerUrl = hash ? `https://stellar.expert/explorer/${explorerNetwork}/tx/${hash}` : null;
@@ -9896,7 +10622,15 @@ var CARD_COPY = {
9896
10622
  chain: (id) => `chain ${id}`,
9897
10623
  sendOnly: (tokens, network) => `Send only ${tokens} on ${network}; anything else can be lost.`,
9898
10624
  noDeposit: "The provider returned no deposit address.",
9899
- hideDeposit: "Hide the deposit address"
10625
+ hideDeposit: "Hide the deposit address",
10626
+ fundingProblem: {
10627
+ noGas: "Your wallet does not have enough to pay the network fee.",
10628
+ sponsorNoGas: "The network fee cannot be covered right now. Please try again later.",
10629
+ noBalance: "Your wallet does not have enough USDC for this amount.",
10630
+ notPaid: "The payment was not sent.",
10631
+ failed: "The payment could not be completed. Please try again.",
10632
+ delayed: "Taking longer than usual. We are following up with the card provider."
10633
+ }
9900
10634
  },
9901
10635
  es: {
9902
10636
  funding: {
@@ -10054,7 +10788,15 @@ var CARD_COPY = {
10054
10788
  chain: (id) => `cadena ${id}`,
10055
10789
  sendOnly: (tokens, network) => `Env\xEDa solo ${tokens} en ${network}; cualquier otra cosa puede perderse.`,
10056
10790
  noDeposit: "El proveedor no devolvi\xF3 ninguna direcci\xF3n de dep\xF3sito.",
10057
- hideDeposit: "Ocultar la direcci\xF3n de dep\xF3sito"
10791
+ hideDeposit: "Ocultar la direcci\xF3n de dep\xF3sito",
10792
+ fundingProblem: {
10793
+ noGas: "Tu wallet no tiene saldo suficiente para pagar la comisi\xF3n de red.",
10794
+ sponsorNoGas: "Ahora no se puede cubrir la comisi\xF3n de red. Intenta de nuevo m\xE1s tarde.",
10795
+ noBalance: "Tu wallet no tiene suficiente USDC para este monto.",
10796
+ notPaid: "El pago no se envi\xF3.",
10797
+ failed: "No se pudo completar el pago. Intenta de nuevo.",
10798
+ delayed: "Est\xE1 tardando m\xE1s de lo normal. Estamos haciendo seguimiento con el emisor de la tarjeta."
10799
+ }
10058
10800
  },
10059
10801
  pt: {
10060
10802
  funding: {
@@ -10212,9 +10954,28 @@ var CARD_COPY = {
10212
10954
  chain: (id) => `rede ${id}`,
10213
10955
  sendOnly: (tokens, network) => `Envie apenas ${tokens} na ${network}; qualquer outra coisa pode ser perdida.`,
10214
10956
  noDeposit: "O provedor n\xE3o retornou nenhum endere\xE7o de dep\xF3sito.",
10215
- hideDeposit: "Ocultar o endere\xE7o de dep\xF3sito"
10957
+ hideDeposit: "Ocultar o endere\xE7o de dep\xF3sito",
10958
+ fundingProblem: {
10959
+ noGas: "Sua carteira n\xE3o tem saldo suficiente para pagar a taxa de rede.",
10960
+ sponsorNoGas: "A taxa de rede n\xE3o pode ser coberta agora. Tente novamente mais tarde.",
10961
+ noBalance: "Sua carteira n\xE3o tem USDC suficiente para este valor.",
10962
+ notPaid: "O pagamento n\xE3o foi enviado.",
10963
+ failed: "N\xE3o foi poss\xEDvel concluir o pagamento. Tente novamente.",
10964
+ delayed: "Est\xE1 demorando mais que o normal. Estamos acompanhando com o emissor do cart\xE3o."
10965
+ }
10216
10966
  }
10217
10967
  };
10968
+ var CREDIT_DELAYED = "provider_credit_delayed";
10969
+ function fundingProblemText(error, copy) {
10970
+ const raw = error ?? "";
10971
+ if (/^TX_INSUFFICIENT_BALANCE|needed \(fee/.test(raw)) {
10972
+ if (/sponsor/i.test(raw)) return copy.fundingProblem.sponsorNoGas;
10973
+ return /token balance/i.test(raw) ? copy.fundingProblem.noBalance : copy.fundingProblem.noGas;
10974
+ }
10975
+ if (/insufficient_usdc/.test(raw)) return copy.fundingProblem.noBalance;
10976
+ if (/^(payment_not_received|cosign_rejected|cosign_expired)/.test(raw)) return copy.fundingProblem.notPaid;
10977
+ return copy.fundingProblem.failed;
10978
+ }
10218
10979
 
10219
10980
  // src/components/card-modal/card-kyc.ts
10220
10981
  var nonEmpty = (value) => typeof value === "string" && !!value.trim();
@@ -10258,6 +11019,9 @@ var REVEAL_MS = 3e4;
10258
11019
  var TX_LIMIT = 10;
10259
11020
  var FUNDING_POLL_MS = 5e3;
10260
11021
  var FUNDING_INFLIGHT = /* @__PURE__ */ new Set(["CREATED", "SENT", "BURNED", "ATTESTED", "MINTED"]);
11022
+ function newFundingKey() {
11023
+ return `fund-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
11024
+ }
10261
11025
  var FUNDING_STEPS = {
10262
11026
  STELLAR: ["CREATED", "BURNED", "ATTESTED", "MINTED"],
10263
11027
  SOLANA: ["CREATED", "SENT"]
@@ -10296,10 +11060,20 @@ function money(amount, currency, language) {
10296
11060
  function groupPan(pan) {
10297
11061
  return pan.replace(/\s+/g, "").replace(/(.{4})/g, "$1 ").trim();
10298
11062
  }
10299
- function errorText(e, fallback, copy) {
11063
+ function errorText2(e, fallback, copy) {
10300
11064
  if (core.isPollarApiError(e)) {
10301
11065
  const known = copy.errors[e.code];
10302
11066
  if (known) return known;
11067
+ if (e.code === "SDK_CARDS_FUNDING_WALLET_NOT_READY") {
11068
+ const { reason, code, message: message2 } = e.body;
11069
+ if (reason === "insufficient_usdc") return copy.fundingProblem.noBalance;
11070
+ if (reason === "build_failed" || reason === "payment_rejected") {
11071
+ return fundingProblemText(
11072
+ `${typeof code === "string" ? code : ""}: ${typeof message2 === "string" ? message2 : ""}`,
11073
+ copy
11074
+ );
11075
+ }
11076
+ }
10303
11077
  const providerMessage = e.body.providerMessage;
10304
11078
  if (typeof providerMessage === "string" && providerMessage) return providerMessage;
10305
11079
  const message = e.body.message;
@@ -10308,7 +11082,7 @@ function errorText(e, fallback, copy) {
10308
11082
  }
10309
11083
  return e instanceof Error && e.message ? e.message : fallback;
10310
11084
  }
10311
- function CardModal({ onClose }) {
11085
+ function CardModal({ onClose, initial }) {
10312
11086
  const { getClient, styles, wallet } = usePollar();
10313
11087
  const language = useModalLanguage();
10314
11088
  const copy = CARD_COPY[language];
@@ -10324,8 +11098,10 @@ function CardModal({ onClose }) {
10324
11098
  const [transactions, setTransactions] = react.useState(null);
10325
11099
  const [deposit, setDeposit] = react.useState(null);
10326
11100
  const [fundings, setFundings] = react.useState(null);
10327
- const [fundAmount, setFundAmount] = react.useState("");
10328
- const [fundChain, setFundChain] = react.useState(null);
11101
+ const [fundAmount, setFundAmount] = react.useState(() => seededAmount(initial?.amount));
11102
+ const fundKey = react.useRef(null);
11103
+ const [fundChain, setFundChain] = react.useState(initial?.chain ?? null);
11104
+ const fundPanelSeed = react.useRef(initial?.panel === "fund");
10329
11105
  const [showManual, setShowManual] = react.useState(false);
10330
11106
  const [occupations, setOccupations] = react.useState([]);
10331
11107
  const [kyc, setKyc] = react.useState(emptyKyc);
@@ -10339,7 +11115,7 @@ function CardModal({ onClose }) {
10339
11115
  const provider = providers?.[0] ?? null;
10340
11116
  const fundingAsset = provider?.fundingAssets[0] ?? "USDC";
10341
11117
  const fundChains = useChains().chains.filter(isFundingChain);
10342
- const selectedFundChain = fundChain ?? fundChains[0] ?? "STELLAR";
11118
+ const selectedFundChain = (fundChain && fundChains.includes(fundChain) ? fundChain : null) ?? fundChains[0] ?? "STELLAR";
10343
11119
  const fundAvailable = useWalletAvailable(panel === "fund" ? { chain: selectedFundChain, code: fundingAsset } : null);
10344
11120
  const card = cards?.[0] ?? null;
10345
11121
  const expiry = card?.expMonth && card.expYear ? `${card.expMonth}/${card.expYear.slice(-2)}` : null;
@@ -10387,7 +11163,7 @@ function CardModal({ onClose }) {
10387
11163
  } catch (e) {
10388
11164
  if (!cancelled) {
10389
11165
  setProviders((cur) => cur ?? []);
10390
- setError(errorText(e, copy.failed.load, copy));
11166
+ setError(errorText2(e, copy.failed.load, copy));
10391
11167
  }
10392
11168
  }
10393
11169
  })();
@@ -10436,7 +11212,7 @@ function CardModal({ onClose }) {
10436
11212
  } catch (e) {
10437
11213
  const step = requiredCardStep(e);
10438
11214
  if (step) openStep(step);
10439
- else setError(errorText(e, fallback, copy));
11215
+ else setError(errorText2(e, fallback, copy));
10440
11216
  } finally {
10441
11217
  setBusy(null);
10442
11218
  }
@@ -10503,16 +11279,34 @@ function CardModal({ onClose }) {
10503
11279
  },
10504
11280
  copy.failed.loadFundings
10505
11281
  );
11282
+ react.useEffect(() => {
11283
+ if (!card || !fundPanelSeed.current) return;
11284
+ fundPanelSeed.current = false;
11285
+ void openFund();
11286
+ }, [card]);
10506
11287
  const fund = () => run(
10507
11288
  "fund-send",
10508
11289
  async () => {
10509
- const outcome = await getClient().fundCard({ amount: fundAmount.trim(), chain: selectedFundChain });
11290
+ fundKey.current ?? (fundKey.current = newFundingKey());
11291
+ let outcome;
11292
+ try {
11293
+ outcome = await getClient().fundCard({
11294
+ amount: fundAmount.trim(),
11295
+ chain: selectedFundChain,
11296
+ idempotencyKey: fundKey.current
11297
+ });
11298
+ } catch (e) {
11299
+ if (core.isPollarApiError(e)) fundKey.current = null;
11300
+ throw e;
11301
+ }
11302
+ fundKey.current = null;
10510
11303
  if (outcome.status === "cancelled") {
10511
11304
  setError(copy.notSigned);
10512
11305
  return;
10513
11306
  }
10514
11307
  setFundings((cur) => [outcome.funding, ...(cur ?? []).filter((f) => f.id !== outcome.funding.id)]);
10515
11308
  setFundAmount("");
11309
+ initial?.onFunded?.(outcome.funding);
10516
11310
  },
10517
11311
  copy.failed.fund
10518
11312
  );
@@ -10929,12 +11723,13 @@ function CardModal({ onClose }) {
10929
11723
  ] }),
10930
11724
  inflight && step > 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "pollar-card-tx-meta", role: "status", children: [
10931
11725
  copy.stepOf(step, steps.length),
10932
- " \xB7 ",
10933
- state?.hint
11726
+ " \xB7",
11727
+ " ",
11728
+ f.error === CREDIT_DELAYED ? copy.fundingProblem.delayed : state?.hint
10934
11729
  ] }),
10935
11730
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "pollar-card-tx-meta", children: [
10936
11731
  new Date(f.createdAt).toLocaleString(),
10937
- f.status === "FAILED" && f.error ? ` \xB7 ${f.error}` : ""
11732
+ f.status === "FAILED" ? ` \xB7 ${fundingProblemText(f.error, copy)}` : ""
10938
11733
  ] })
10939
11734
  ] }),
10940
11735
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-card-tx-amount", "data-direction": f.status === "CREDITED" ? "credit" : void 0, children: money(f.amount, "USD", language) })
@@ -11738,7 +12533,8 @@ function CosignModal({ nextStep = null, onClose }) {
11738
12533
  setError(
11739
12534
  core.transactionErrorMessage(core.isPollarApiError(err) ? err.code : null, err instanceof Error ? err.message : null, language)
11740
12535
  );
11741
- if (kind === "approving") setApproveFailedFor(request.id);
12536
+ if (kind === "approving" && !(core.isPollarApiError(err) && err.code === "SDK_COSIGN_GAS_PENDING"))
12537
+ setApproveFailedFor(request.id);
11742
12538
  } finally {
11743
12539
  setBusy(null);
11744
12540
  }
@@ -12390,7 +13186,7 @@ function RecoveryModalTemplate(p) {
12390
13186
  }
12391
13187
  );
12392
13188
  }
12393
- function errorText2(err, language) {
13189
+ function errorText3(err, language) {
12394
13190
  return core.cosignRefusalMessage(err, language) ?? core.transactionErrorMessage(core.isPollarApiError(err) ? err.code : null, err instanceof Error ? err.message : null, language);
12395
13191
  }
12396
13192
  function RecoveryModal({ onClose }) {
@@ -12423,7 +13219,7 @@ function RecoveryModal({ onClose }) {
12423
13219
  refreshRecovery();
12424
13220
  }, [getClient, refreshRecovery]);
12425
13221
  react.useEffect(() => {
12426
- load().catch((err) => setError(errorText2(err, language)));
13222
+ load().catch((err) => setError(errorText3(err, language)));
12427
13223
  }, [load]);
12428
13224
  const onCloseRef = react.useRef(onClose);
12429
13225
  onCloseRef.current = onClose;
@@ -12444,7 +13240,7 @@ function RecoveryModal({ onClose }) {
12444
13240
  if (after?.notice) setNotice(after.notice);
12445
13241
  if (after?.view) setView(after.view);
12446
13242
  } catch (err) {
12447
- setError(errorText2(err, language));
13243
+ setError(errorText3(err, language));
12448
13244
  } finally {
12449
13245
  setBusy(null);
12450
13246
  }
@@ -13085,7 +13881,7 @@ function TxHistoryModalTemplate({
13085
13881
  );
13086
13882
  }
13087
13883
  var PAGE_SIZE2 = 10;
13088
- function TxHistoryModal({ onClose }) {
13884
+ function TxHistoryModal({ onClose, initial }) {
13089
13885
  const { getClient, styles, txHistory, wallets } = usePollar();
13090
13886
  const { theme, accentColor, styleOverrides, overlayStyle } = modalChrome(styles);
13091
13887
  const language = useModalLanguage();
@@ -13093,8 +13889,8 @@ function TxHistoryModal({ onClose }) {
13093
13889
  const { chains } = useChains();
13094
13890
  const [selectedChain, setSelectedChain] = react.useState(null);
13095
13891
  react.useEffect(() => {
13096
- if (selectedChain === null && chains.length > 0) setSelectedChain(chains[0]);
13097
- }, [chains, selectedChain]);
13892
+ if (selectedChain === null && chains.length > 0) setSelectedChain(oneOf(chains, initial?.chain) ?? chains[0]);
13893
+ }, [chains, selectedChain, initial?.chain]);
13098
13894
  const walletAddress = addressForChain(wallets, selectedChain);
13099
13895
  const load = react.useCallback(
13100
13896
  (nextOffset, chain) => {
@@ -13472,6 +14268,7 @@ var PollarContext = react.createContext(null);
13472
14268
  var clientByConfig = /* @__PURE__ */ new WeakMap();
13473
14269
  function PollarProvider({
13474
14270
  client,
14271
+ language,
13475
14272
  appConfig: appConfigProp,
13476
14273
  adapters,
13477
14274
  onStorageDegrade,
@@ -13633,6 +14430,13 @@ function PollarProvider({
13633
14430
  const [kycModalOpen, setKycModalOpen] = react.useState(false);
13634
14431
  const [kycModalOptions, setKycModalOptions] = react.useState({});
13635
14432
  const [rampModalOpen, setRampModalOpen] = react.useState(false);
14433
+ const [rampSeed, seedRamp] = useModalOptions();
14434
+ const [receiveSeed, seedReceive] = useModalOptions();
14435
+ const [txHistorySeed, seedTxHistory] = useModalOptions();
14436
+ const [sendModalOptions, setSendModalOptions] = react.useState(void 0);
14437
+ const [swapModalOptions, setSwapModalOptions] = react.useState(void 0);
14438
+ const [earnModalOptions, setEarnModalOptions] = react.useState(void 0);
14439
+ const [cardModalOptions, setCardModalOptions] = react.useState(void 0);
13636
14440
  const [txHistoryModalOpen, setTxHistoryModalOpen] = react.useState(false);
13637
14441
  const [walletBalanceModalOpen, setWalletBalanceModalOpen] = react.useState(false);
13638
14442
  const [enabledAssetsModalOpen, setEnabledAssetsModalOpen] = react.useState(false);
@@ -13641,6 +14445,9 @@ function PollarProvider({
13641
14445
  const [earnModalOpen, setEarnModalOpen] = react.useState(false);
13642
14446
  const [sendModalKey, setSendModalKey] = react.useState(0);
13643
14447
  const [swapModalKey, setSwapModalKey] = react.useState(0);
14448
+ const [bridgeModalOpen, setBridgeModalOpen] = react.useState(false);
14449
+ const [bridgeModalKey, setBridgeModalKey] = react.useState(0);
14450
+ const [bridgeModalOptions, setBridgeModalOptions] = react.useState(void 0);
13644
14451
  const [earnModalKey, setEarnModalKey] = react.useState(0);
13645
14452
  const [cardModalOpen, setCardModalOpen] = react.useState(false);
13646
14453
  const [cardModalKey, setCardModalKey] = react.useState(0);
@@ -13666,6 +14473,7 @@ function PollarProvider({
13666
14473
  setEnabledAssetsModalOpen(false);
13667
14474
  setSendModalOpen(false);
13668
14475
  setSwapModalOpen(false);
14476
+ setBridgeModalOpen(false);
13669
14477
  setEarnModalOpen(false);
13670
14478
  setCardModalOpen(false);
13671
14479
  setReceiveModalOpen(false);
@@ -13749,7 +14557,10 @@ function PollarProvider({
13749
14557
  openTxModal: () => setTransactionModalOpen(true),
13750
14558
  // tx history
13751
14559
  txHistory,
13752
- openTxHistoryModal: () => setTxHistoryModalOpen(true),
14560
+ openTxHistoryModal: (options) => {
14561
+ seedTxHistory(options);
14562
+ setTxHistoryModalOpen(true);
14563
+ },
13753
14564
  // wallet balance
13754
14565
  walletBalance,
13755
14566
  refreshWalletBalance,
@@ -13760,12 +14571,16 @@ function PollarProvider({
13760
14571
  setTrustline: (asset, opts) => pollarClient.setTrustline(asset, opts),
13761
14572
  openEnabledAssetsModal: () => setEnabledAssetsModalOpen(true),
13762
14573
  // send / receive
13763
- openSendModal: () => {
14574
+ openSendModal: (options) => {
14575
+ setSendModalOptions(options);
13764
14576
  pollarClient.resetTransactionState();
13765
14577
  setSendModalKey((k) => k + 1);
13766
14578
  setSendModalOpen(true);
13767
14579
  },
13768
- openReceiveModal: () => setReceiveModalOpen(true),
14580
+ openReceiveModal: (options) => {
14581
+ seedReceive(options);
14582
+ setReceiveModalOpen(true);
14583
+ },
13769
14584
  // swap
13770
14585
  getSwapConfig: () => pollarClient.getSwapConfig(),
13771
14586
  getSwapTokens: () => pollarClient.getSwapTokens(),
@@ -13774,24 +14589,32 @@ function PollarProvider({
13774
14589
  getSolanaSwapConfig: () => pollarClient.getSolanaSwapConfig(),
13775
14590
  getSolanaSwapQuote: (params) => pollarClient.getSolanaSwapQuote(params),
13776
14591
  swapSolana: (quote, opts) => pollarClient.swapSolana(quote, opts),
13777
- openSwapModal: () => {
14592
+ openSwapModal: (options) => {
14593
+ setSwapModalOptions(options);
13778
14594
  pollarClient.resetTransactionState();
13779
14595
  setSwapModalKey((k) => k + 1);
13780
14596
  setSwapModalOpen(true);
13781
14597
  },
14598
+ openBridgeModal: (options) => {
14599
+ setBridgeModalOptions(options);
14600
+ setBridgeModalKey((k) => k + 1);
14601
+ setBridgeModalOpen(true);
14602
+ },
13782
14603
  // earn
13783
14604
  getEarnProviders: () => pollarClient.getEarnProviders(),
13784
14605
  getEarnOpportunities: (provider) => pollarClient.getEarnOpportunities(provider),
13785
14606
  getEarnPosition: (params) => pollarClient.getEarnPosition(params),
13786
14607
  earnDeposit: (params) => pollarClient.earnDeposit(params),
13787
14608
  earnWithdraw: (params) => pollarClient.earnWithdraw(params),
13788
- openEarnModal: () => {
14609
+ openEarnModal: (options) => {
14610
+ setEarnModalOptions(options);
13789
14611
  pollarClient.resetTransactionState();
13790
14612
  setEarnModalKey((k) => k + 1);
13791
14613
  setEarnModalOpen(true);
13792
14614
  },
13793
14615
  // cards
13794
- openCardModal: () => {
14616
+ openCardModal: (options) => {
14617
+ setCardModalOptions(options);
13795
14618
  setCardModalKey((k) => k + 1);
13796
14619
  setCardModalOpen(true);
13797
14620
  },
@@ -13820,7 +14643,10 @@ function PollarProvider({
13820
14643
  setKycModalOpen(true);
13821
14644
  },
13822
14645
  // ramp
13823
- openRampModal: () => setRampModalOpen(true),
14646
+ openRampModal: (options) => {
14647
+ seedRamp(options);
14648
+ setRampModalOpen(true);
14649
+ },
13824
14650
  // config
13825
14651
  appConfig: resolvedConfig,
13826
14652
  styles,
@@ -13855,7 +14681,7 @@ function PollarProvider({
13855
14681
  retryConfig,
13856
14682
  adapters
13857
14683
  ]);
13858
- const modalLanguage = useProviderLanguage(pollarClient, contextValue.styles?.language);
14684
+ const modalLanguage = useProviderLanguage(pollarClient, contextValue.styles?.language, language);
13859
14685
  return /* @__PURE__ */ jsxRuntime.jsx(PollarContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsxs(ModalLanguageContext.Provider, { value: modalLanguage, children: [
13860
14686
  children,
13861
14687
  loginModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setLoginModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(LoginModal, { onClose: () => setLoginModalOpen(false) }) }),
@@ -13882,16 +14708,17 @@ function PollarProvider({
13882
14708
  ...kycModalOptions.onApproved !== void 0 && { onApproved: kycModalOptions.onApproved }
13883
14709
  }
13884
14710
  ) }),
13885
- rampModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setRampModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(RampWidget, { onClose: () => setRampModalOpen(false) }) }),
13886
- txHistoryModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setTxHistoryModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(TxHistoryModal, { onClose: () => setTxHistoryModalOpen(false) }) }),
14711
+ rampModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setRampModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(RampWidget, { onClose: () => setRampModalOpen(false), initial: rampSeed.options }) }, `ramp:${rampSeed.key}`),
14712
+ txHistoryModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setTxHistoryModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(TxHistoryModal, { onClose: () => setTxHistoryModalOpen(false), initial: txHistorySeed.options }) }, `history:${txHistorySeed.key}`),
13887
14713
  walletBalanceModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setWalletBalanceModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(WalletBalanceModal, { onClose: () => setWalletBalanceModalOpen(false) }) }),
13888
14714
  enabledAssetsModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setEnabledAssetsModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(EnabledAssetsModal, { onClose: () => setEnabledAssetsModalOpen(false) }) }),
13889
- sendModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setSendModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(SendModal, { onClose: () => setSendModalOpen(false) }) }, sendModalKey),
13890
- swapModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setSwapModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(SwapModal, { onClose: () => setSwapModalOpen(false) }) }, swapModalKey),
13891
- earnModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setEarnModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(EarnModal, { onClose: () => setEarnModalOpen(false) }) }, earnModalKey),
14715
+ sendModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setSendModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(SendModal, { onClose: () => setSendModalOpen(false), initial: sendModalOptions }) }, `send:${sendModalKey}`),
14716
+ swapModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setSwapModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(SwapModal, { onClose: () => setSwapModalOpen(false), initial: swapModalOptions }) }, `swap:${swapModalKey}`),
14717
+ bridgeModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setBridgeModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(BridgeModal, { onClose: () => setBridgeModalOpen(false), initial: bridgeModalOptions }) }, bridgeModalKey),
14718
+ earnModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setEarnModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(EarnModal, { onClose: () => setEarnModalOpen(false), initial: earnModalOptions }) }, `earn:${earnModalKey}`),
13892
14719
  cardModalOpen && // Keyed by the wallet too: a different user, or signing in with it open, starts it from scratch.
13893
- /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setCardModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(CardModal, { onClose: () => setCardModalOpen(false) }) }, `${cardModalKey}:${walletAddress}`),
13894
- receiveModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setReceiveModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(ReceiveModal, { onClose: () => setReceiveModalOpen(false) }) }),
14720
+ /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setCardModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(CardModal, { onClose: () => setCardModalOpen(false), initial: cardModalOptions }) }, `${cardModalKey}:${walletAddress}`),
14721
+ receiveModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setReceiveModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(ReceiveModal, { onClose: () => setReceiveModalOpen(false), initial: receiveSeed.options }) }, `receive:${receiveSeed.key}`),
13895
14722
  sessionsModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setSessionsModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(SessionsModal, { onClose: () => setSessionsModalOpen(false) }) }),
13896
14723
  cosignModalOpen && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: () => setCosignModalOpen(false), children: /* @__PURE__ */ jsxRuntime.jsx(CosignModal, { nextStep: cosignNextStep, onClose: () => setCosignModalOpen(false) }) }),
13897
14724
  custodyMigration?.required && !custodyMigrationLater && /* @__PURE__ */ jsxRuntime.jsx(ModalErrorBoundary, { onClose: refreshCustodyMigration, children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -14705,6 +15532,8 @@ function WalletButton() {
14705
15532
  );
14706
15533
  }
14707
15534
 
15535
+ exports.BridgeModal = BridgeModal;
15536
+ exports.BridgeModalTemplate = BridgeModalTemplate;
14708
15537
  exports.CardModal = CardModal;
14709
15538
  exports.ChainSelect = ChainSelect;
14710
15539
  exports.CosignModal = CosignModal;