@deframe-sdk/components 0.1.70 → 0.1.72

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
@@ -4846,6 +4846,28 @@ function SkeletonCard({ testId, symbol, network, amount, usd, balance }) {
4846
4846
  }
4847
4847
  );
4848
4848
  }
4849
+ function useBackgroundConfirmationTransition({
4850
+ enabled,
4851
+ started,
4852
+ slowAfterMs = 5e3,
4853
+ dismissAfterSlowMs = 3e3,
4854
+ onDismiss
4855
+ }) {
4856
+ const [phase, setPhase] = React6.useState("initial");
4857
+ React6.useEffect(() => {
4858
+ if (!enabled || !started) return;
4859
+ if (phase !== "initial") return;
4860
+ const id = window.setTimeout(() => setPhase("background-confirmation"), slowAfterMs);
4861
+ return () => window.clearTimeout(id);
4862
+ }, [enabled, started, phase, slowAfterMs]);
4863
+ React6.useEffect(() => {
4864
+ if (phase !== "background-confirmation") return;
4865
+ if (!onDismiss) return;
4866
+ const id = window.setTimeout(() => onDismiss(), dismissAfterSlowMs);
4867
+ return () => window.clearTimeout(id);
4868
+ }, [phase, dismissAfterSlowMs, onDismiss]);
4869
+ return { phase };
4870
+ }
4849
4871
  function LoadingIcon() {
4850
4872
  const green = "var(--deframe-widget-color-brand-primary)";
4851
4873
  const trackColor = "color-mix(in srgb, var(--deframe-widget-color-brand-primary) 12%, transparent)";
@@ -4906,10 +4928,42 @@ function LoadingIcon() {
4906
4928
  }
4907
4929
  );
4908
4930
  }
4931
+ function SlowIcon() {
4932
+ return /* @__PURE__ */ jsxRuntime.jsx(
4933
+ framerMotion.motion.div,
4934
+ {
4935
+ "data-test-id": "swap-processing-simple-background-confirmation-icon",
4936
+ initial: { scale: 0.7, opacity: 0 },
4937
+ animate: { scale: 1, opacity: 1 },
4938
+ transition: { type: "spring", stiffness: 280, damping: 22 },
4939
+ className: "flex items-center justify-center shrink-0 w-[56px] h-[56px]",
4940
+ "aria-hidden": "true",
4941
+ children: /* @__PURE__ */ jsxRuntime.jsx(
4942
+ md.MdAccessTime,
4943
+ {
4944
+ size: 56,
4945
+ color: "var(--deframe-widget-color-brand-primary)"
4946
+ }
4947
+ )
4948
+ }
4949
+ );
4950
+ }
4909
4951
  var SwapProcessingViewSimple = ({
4910
4952
  titleText,
4911
- descriptionPrefix
4953
+ descriptionPrefix,
4954
+ allowBackgroundConfirmation = false,
4955
+ backgroundConfirmationStarted = false,
4956
+ backgroundConfirmationLabels,
4957
+ onBackgroundConfirmationDismiss
4912
4958
  }) => {
4959
+ const { phase } = useBackgroundConfirmationTransition({
4960
+ enabled: allowBackgroundConfirmation,
4961
+ started: backgroundConfirmationStarted,
4962
+ onDismiss: onBackgroundConfirmationDismiss
4963
+ });
4964
+ const isBackgroundConfirmation = phase === "background-confirmation" && backgroundConfirmationLabels !== void 0;
4965
+ const renderedTitle = isBackgroundConfirmation ? backgroundConfirmationLabels.title : titleText;
4966
+ const renderedSubtitle = isBackgroundConfirmation ? backgroundConfirmationLabels.subtitle : descriptionPrefix;
4913
4967
  return /* @__PURE__ */ jsxRuntime.jsxs(
4914
4968
  "div",
4915
4969
  {
@@ -4939,7 +4993,7 @@ var SwapProcessingViewSimple = ({
4939
4993
  "bg-[color-mix(in_srgb,var(--deframe-widget-color-bg-secondary)_88%,transparent)]"
4940
4994
  ),
4941
4995
  children: [
4942
- /* @__PURE__ */ jsxRuntime.jsx(LoadingIcon, {}),
4996
+ isBackgroundConfirmation ? /* @__PURE__ */ jsxRuntime.jsx(SlowIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(LoadingIcon, {}),
4943
4997
  /* @__PURE__ */ jsxRuntime.jsxs(
4944
4998
  "div",
4945
4999
  {
@@ -4949,20 +5003,20 @@ var SwapProcessingViewSimple = ({
4949
5003
  /* @__PURE__ */ jsxRuntime.jsx(
4950
5004
  "span",
4951
5005
  {
4952
- "data-test-id": "swap-processing-simple-title",
5006
+ "data-test-id": isBackgroundConfirmation ? "swap-processing-simple-background-confirmation-title" : "swap-processing-simple-title",
4953
5007
  className: tailwindMerge.twMerge(
4954
5008
  "[font-size:12px] [line-height:1.25] [letter-spacing:0.10em] uppercase",
4955
5009
  "[font-weight:var(--deframe-widget-font-weight-semibold)]",
4956
5010
  "font-[var(--deframe-widget-font-family)]",
4957
5011
  "text-[color:var(--deframe-widget-color-brand-primary)]"
4958
5012
  ),
4959
- children: titleText
5013
+ children: renderedTitle
4960
5014
  }
4961
5015
  ),
4962
5016
  /* @__PURE__ */ jsxRuntime.jsx(
4963
5017
  "span",
4964
5018
  {
4965
- "data-test-id": "swap-processing-simple-subtitle",
5019
+ "data-test-id": isBackgroundConfirmation ? "swap-processing-simple-background-confirmation-subtitle" : "swap-processing-simple-subtitle",
4966
5020
  className: tailwindMerge.twMerge(
4967
5021
  "[font-size:var(--deframe-widget-font-size-md)] [line-height:1.6]",
4968
5022
  "[font-weight:var(--deframe-widget-font-weight-regular)]",
@@ -4970,7 +5024,7 @@ var SwapProcessingViewSimple = ({
4970
5024
  "text-[color:var(--deframe-widget-color-text-secondary)]",
4971
5025
  "max-w-[260px]"
4972
5026
  ),
4973
- children: descriptionPrefix
5027
+ children: renderedSubtitle
4974
5028
  }
4975
5029
  )
4976
5030
  ]
@@ -5086,12 +5140,20 @@ var SwapCrossChainProcessingView = ({
5086
5140
  };
5087
5141
  var SwapCrossChainProcessingViewSimple = ({
5088
5142
  title,
5089
- description
5143
+ description,
5144
+ allowBackgroundConfirmation,
5145
+ backgroundConfirmationStarted,
5146
+ backgroundConfirmationLabels,
5147
+ onBackgroundConfirmationDismiss
5090
5148
  }) => /* @__PURE__ */ jsxRuntime.jsx(
5091
5149
  SwapProcessingViewSimple,
5092
5150
  {
5093
5151
  titleText: title,
5094
- descriptionPrefix: description
5152
+ descriptionPrefix: description,
5153
+ allowBackgroundConfirmation,
5154
+ backgroundConfirmationStarted,
5155
+ backgroundConfirmationLabels,
5156
+ onBackgroundConfirmationDismiss
5095
5157
  }
5096
5158
  );
5097
5159
  var InvestmentCrossChainProcessingView = ({
@@ -5284,9 +5346,14 @@ function EarnFeedbackOverlaySimpleView({
5284
5346
  variant,
5285
5347
  title,
5286
5348
  subtitle,
5287
- formData
5349
+ formData,
5350
+ phase = "initial",
5351
+ backgroundConfirmationLabels
5288
5352
  }) {
5289
- const isLoading = variant === "loading";
5353
+ const isBackgroundConfirmation = phase === "background-confirmation" && variant === "loading" && backgroundConfirmationLabels !== void 0;
5354
+ const renderedTitle = isBackgroundConfirmation ? backgroundConfirmationLabels.title : title;
5355
+ const renderedSubtitle = isBackgroundConfirmation ? backgroundConfirmationLabels.subtitle : subtitle;
5356
+ const isLoading = variant === "loading" && !isBackgroundConfirmation;
5290
5357
  const wrapperClasses = tailwindMerge.twMerge(
5291
5358
  "relative flex flex-col overflow-hidden w-[420px]",
5292
5359
  "rounded-[var(--deframe-widget-size-radius-md)]",
@@ -5307,7 +5374,7 @@ function EarnFeedbackOverlaySimpleView({
5307
5374
  "gap-[var(--deframe-widget-size-gap-sm)] text-center"
5308
5375
  );
5309
5376
  const titleClasses2 = tailwindMerge.twMerge(
5310
- isLoading ? "[font-size:12px] [line-height:1.25] [letter-spacing:0.10em] uppercase [font-weight:var(--deframe-widget-font-weight-semibold)] font-[var(--deframe-widget-font-family)] text-[color:var(--deframe-widget-color-brand-primary)]" : "text-[22px] font-bold text-[color:var(--deframe-widget-color-text-primary)] leading-[1.25]"
5377
+ isLoading || isBackgroundConfirmation ? "[font-size:12px] [line-height:1.25] [letter-spacing:0.10em] uppercase [font-weight:var(--deframe-widget-font-weight-semibold)] font-[var(--deframe-widget-font-family)] text-[color:var(--deframe-widget-color-brand-primary)]" : "text-[22px] font-bold text-[color:var(--deframe-widget-color-text-primary)] leading-[1.25]"
5311
5378
  );
5312
5379
  const subtitleClasses = tailwindMerge.twMerge(
5313
5380
  "[font-size:var(--deframe-widget-font-size-md)] [line-height:1.6]",
@@ -5335,6 +5402,7 @@ function EarnFeedbackOverlaySimpleView({
5335
5402
  transition: { duration: 0.2 },
5336
5403
  className: overlayClasses,
5337
5404
  children: [
5405
+ isBackgroundConfirmation && /* @__PURE__ */ jsxRuntime.jsx(SlowIcon2, {}),
5338
5406
  isLoading && /* @__PURE__ */ jsxRuntime.jsx(LoadingIcon2, {}),
5339
5407
  variant === "success" && /* @__PURE__ */ jsxRuntime.jsx(SuccessIcon, {}),
5340
5408
  variant === "warning" && /* @__PURE__ */ jsxRuntime.jsx(WarningIcon, {}),
@@ -5349,19 +5417,19 @@ function EarnFeedbackOverlaySimpleView({
5349
5417
  /* @__PURE__ */ jsxRuntime.jsx(
5350
5418
  "span",
5351
5419
  {
5352
- "data-test-id": "earn-feedback-title",
5420
+ "data-test-id": isBackgroundConfirmation ? "earn-feedback-background-confirmation-title" : "earn-feedback-title",
5353
5421
  "data-slot": "earn-feedback-title",
5354
5422
  className: titleClasses2,
5355
- children: title
5423
+ children: renderedTitle
5356
5424
  }
5357
5425
  ),
5358
- subtitle && /* @__PURE__ */ jsxRuntime.jsx(
5426
+ renderedSubtitle && /* @__PURE__ */ jsxRuntime.jsx(
5359
5427
  "span",
5360
5428
  {
5361
- "data-test-id": "earn-feedback-subtitle",
5429
+ "data-test-id": isBackgroundConfirmation ? "earn-feedback-background-confirmation-subtitle" : "earn-feedback-subtitle",
5362
5430
  "data-slot": "earn-feedback-subtitle",
5363
5431
  className: subtitleClasses,
5364
- children: subtitle
5432
+ children: renderedSubtitle
5365
5433
  }
5366
5434
  )
5367
5435
  ]
@@ -5375,6 +5443,27 @@ function EarnFeedbackOverlaySimpleView({
5375
5443
  }
5376
5444
  );
5377
5445
  }
5446
+ function SlowIcon2() {
5447
+ return /* @__PURE__ */ jsxRuntime.jsx(
5448
+ framerMotion.motion.div,
5449
+ {
5450
+ "data-test-id": "earn-feedback-background-confirmation-icon",
5451
+ "data-slot": "earn-feedback-background-confirmation-icon",
5452
+ initial: { scale: 0.7, opacity: 0 },
5453
+ animate: { scale: 1, opacity: 1 },
5454
+ transition: { type: "spring", stiffness: 280, damping: 22 },
5455
+ className: "flex items-center justify-center shrink-0 w-[56px] h-[56px]",
5456
+ "aria-hidden": "true",
5457
+ children: /* @__PURE__ */ jsxRuntime.jsx(
5458
+ md.MdAccessTime,
5459
+ {
5460
+ size: 56,
5461
+ color: "var(--deframe-widget-color-brand-primary)"
5462
+ }
5463
+ )
5464
+ }
5465
+ );
5466
+ }
5378
5467
  function LoadingIcon2() {
5379
5468
  const green = "var(--deframe-widget-color-brand-primary)";
5380
5469
  const trackColor = "color-mix(in srgb, var(--deframe-widget-color-brand-primary) 12%, transparent)";
@@ -5613,14 +5702,25 @@ var InvestmentCrossChainProcessingSimpleView = ({
5613
5702
  strategyName,
5614
5703
  strategyIcon,
5615
5704
  amountToken,
5616
- amountUSD
5705
+ amountUSD,
5706
+ allowBackgroundConfirmation = false,
5707
+ backgroundConfirmationStarted = false,
5708
+ backgroundConfirmationLabels,
5709
+ onBackgroundConfirmationDismiss
5617
5710
  }) => {
5711
+ const { phase } = useBackgroundConfirmationTransition({
5712
+ enabled: allowBackgroundConfirmation,
5713
+ started: backgroundConfirmationStarted,
5714
+ onDismiss: onBackgroundConfirmationDismiss
5715
+ });
5618
5716
  return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-test-id": "investment-crosschain-processing-simple-view", children: /* @__PURE__ */ jsxRuntime.jsx(
5619
5717
  EarnFeedbackOverlaySimpleView,
5620
5718
  {
5621
5719
  variant: "loading",
5622
5720
  title,
5623
5721
  subtitle: description,
5722
+ phase,
5723
+ backgroundConfirmationLabels,
5624
5724
  formData: {
5625
5725
  headerTitle: title,
5626
5726
  tokenSymbol: strategyName,
@@ -9716,6 +9816,32 @@ function StatusBadge2({ status, labels, className }) {
9716
9816
  }
9717
9817
  );
9718
9818
  }
9819
+ var explorerLinkClass = "text-[color:var(--deframe-widget-color-brand-primary)] underline text-[12px] leading-none [font-weight:var(--deframe-widget-font-weight-semibold)]";
9820
+ function renderExplorerLink(tx) {
9821
+ return /* @__PURE__ */ jsxRuntime.jsx(
9822
+ "a",
9823
+ {
9824
+ "data-test-id": "history-list-item-simple-explorer",
9825
+ href: tx.explorerUrl,
9826
+ target: "_blank",
9827
+ rel: "noopener noreferrer",
9828
+ className: explorerLinkClass,
9829
+ children: tx.label
9830
+ }
9831
+ );
9832
+ }
9833
+ function renderExplorerLinks(transactions) {
9834
+ if (!(transactions == null ? void 0 : transactions.length)) return null;
9835
+ if (transactions.length === 1) return renderExplorerLink(transactions[0]);
9836
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-[var(--deframe-widget-size-gap-xs)] flex-wrap", children: transactions.map((tx, i) => /* @__PURE__ */ jsxRuntime.jsxs(React6__namespace.Fragment, { children: [
9837
+ i > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[color:var(--deframe-widget-color-text-tertiary)] text-[12px]", children: "\u2192" }),
9838
+ tx.prefix && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-[color:var(--deframe-widget-color-text-secondary)] text-[12px]", children: [
9839
+ tx.prefix,
9840
+ ":"
9841
+ ] }),
9842
+ renderExplorerLink(tx)
9843
+ ] }, tx.explorerUrl)) });
9844
+ }
9719
9845
  var HistoryListItemSimple = ({ item, labels, locale }) => {
9720
9846
  const label = historyResolveLabel(item, labels);
9721
9847
  const { primary, secondary } = historyResolveAmounts(item);
@@ -9778,7 +9904,8 @@ var HistoryListItemSimple = ({ item, labels, locale }) => {
9778
9904
  }
9779
9905
  )
9780
9906
  ] })
9781
- ] })
9907
+ ] }),
9908
+ renderExplorerLinks(item.transactions)
9782
9909
  ]
9783
9910
  }
9784
9911
  );
@@ -11274,7 +11401,12 @@ function formatEarnPositions(positions, { currency, locale, formatCurrency }) {
11274
11401
  const principalUSD = p.spotPosition.underlyingBalanceUSD - p.spotPosition.profitInUSD;
11275
11402
  const investedFormatted = isBrlPegged && p.spotPosition.principal ? formatHistoryAssetAmount({ amountHumanized: p.spotPosition.principal.humanized, symbol, currency, locale, formatCurrency }) : formatCurrency(principalUSD);
11276
11403
  const totalBrla = isBrlPegged && principalHumanized > 0 && principalUSD > 0 ? p.spotPosition.underlyingBalanceUSD * principalHumanized / principalUSD : null;
11277
- const totalValueFormatted = totalBrla !== null ? formatHistoryAssetAmount({ amountHumanized: String(totalBrla), symbol, currency, locale, formatCurrency }) : formatCurrency(p.spotPosition.underlyingBalanceUSD);
11404
+ const totalValueFormatted = (() => {
11405
+ if (totalBrla !== null) {
11406
+ return totalBrla < 0.01 ? investedFormatted : formatHistoryAssetAmount({ amountHumanized: String(totalBrla), symbol, currency, locale, formatCurrency });
11407
+ }
11408
+ return p.spotPosition.underlyingBalanceUSD < 0.01 ? investedFormatted : formatCurrency(p.spotPosition.underlyingBalanceUSD);
11409
+ })();
11278
11410
  return __spreadProps(__spreadValues({}, p), { spotPosition: __spreadProps(__spreadValues({}, p.spotPosition), { investedFormatted, totalValueFormatted }) });
11279
11411
  })
11280
11412
  });
@@ -13624,14 +13756,25 @@ var EarnDepositProcessingSimpleView = ({
13624
13756
  amountToken,
13625
13757
  amountUSD,
13626
13758
  iconSrc,
13627
- strategyName
13759
+ strategyName,
13760
+ allowBackgroundConfirmation = false,
13761
+ backgroundConfirmationStarted = false,
13762
+ backgroundConfirmationLabels,
13763
+ onBackgroundConfirmationDismiss
13628
13764
  }) => {
13765
+ const { phase } = useBackgroundConfirmationTransition({
13766
+ enabled: allowBackgroundConfirmation,
13767
+ started: backgroundConfirmationStarted,
13768
+ onDismiss: onBackgroundConfirmationDismiss
13769
+ });
13629
13770
  return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-test-id": "earn-deposit-processing-simple-view", children: /* @__PURE__ */ jsxRuntime.jsx(
13630
13771
  EarnFeedbackOverlaySimpleView,
13631
13772
  {
13632
13773
  variant: "loading",
13633
13774
  title,
13634
13775
  subtitle: descriptionPrefix,
13776
+ phase,
13777
+ backgroundConfirmationLabels,
13635
13778
  formData: {
13636
13779
  headerTitle: title,
13637
13780
  tokenSymbol: strategyName,
@@ -13999,14 +14142,25 @@ var EarnWithdrawProcessingSimpleView = ({
13999
14142
  amountToken,
14000
14143
  amountUSD,
14001
14144
  iconSrc,
14002
- strategyName
14145
+ strategyName,
14146
+ allowBackgroundConfirmation = false,
14147
+ backgroundConfirmationStarted = false,
14148
+ backgroundConfirmationLabels,
14149
+ onBackgroundConfirmationDismiss
14003
14150
  }) => {
14151
+ const { phase } = useBackgroundConfirmationTransition({
14152
+ enabled: allowBackgroundConfirmation,
14153
+ started: backgroundConfirmationStarted,
14154
+ onDismiss: onBackgroundConfirmationDismiss
14155
+ });
14004
14156
  return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-test-id": "earn-withdraw-processing-simple-view", children: /* @__PURE__ */ jsxRuntime.jsx(
14005
14157
  EarnFeedbackOverlaySimpleView,
14006
14158
  {
14007
14159
  variant: "loading",
14008
14160
  title,
14009
14161
  subtitle: descriptionPrefix,
14162
+ phase,
14163
+ backgroundConfirmationLabels,
14010
14164
  formData: {
14011
14165
  headerTitle: title,
14012
14166
  tokenSymbol: strategyName,
@@ -16083,14 +16237,25 @@ var OnchainWithdrawFailedSimpleView = ({
16083
16237
  ) });
16084
16238
  var OnchainWithdrawProcessingSimpleView = ({
16085
16239
  onClose: _onClose,
16086
- formData
16240
+ formData,
16241
+ allowBackgroundConfirmation = false,
16242
+ backgroundConfirmationStarted = false,
16243
+ backgroundConfirmationLabels,
16244
+ onBackgroundConfirmationDismiss
16087
16245
  }) => {
16246
+ const { phase } = useBackgroundConfirmationTransition({
16247
+ enabled: allowBackgroundConfirmation,
16248
+ started: backgroundConfirmationStarted,
16249
+ onDismiss: onBackgroundConfirmationDismiss
16250
+ });
16088
16251
  return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-test-id": "onchain-withdraw-processing-simple-view", children: /* @__PURE__ */ jsxRuntime.jsx(
16089
16252
  EarnFeedbackOverlaySimpleView,
16090
16253
  {
16091
16254
  variant: "loading",
16092
16255
  title: "PROCESSANDO SAQUE...",
16093
16256
  subtitle: "Aguarde enquanto sua transa\xE7\xE3o \xE9 confirmada.",
16257
+ phase,
16258
+ backgroundConfirmationLabels,
16094
16259
  formData
16095
16260
  }
16096
16261
  ) });
@@ -18174,13 +18339,25 @@ function OfframpProcessingView({
18174
18339
  }
18175
18340
  );
18176
18341
  }
18177
- var OfframpProcessingSimpleView = () => {
18342
+ var OfframpProcessingSimpleView = ({
18343
+ allowBackgroundConfirmation = false,
18344
+ backgroundConfirmationStarted = false,
18345
+ backgroundConfirmationLabels,
18346
+ onBackgroundConfirmationDismiss
18347
+ }) => {
18348
+ const { phase } = useBackgroundConfirmationTransition({
18349
+ enabled: allowBackgroundConfirmation,
18350
+ started: backgroundConfirmationStarted,
18351
+ onDismiss: onBackgroundConfirmationDismiss
18352
+ });
18178
18353
  return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-test-id": "offramp-processing-simple-view", children: /* @__PURE__ */ jsxRuntime.jsx(
18179
18354
  EarnFeedbackOverlaySimpleView,
18180
18355
  {
18181
18356
  variant: "loading",
18182
18357
  title: "PROCESSANDO SAQUE...",
18183
- subtitle: "Seu PIX est\xE1 sendo enviado. Aguarde alguns instantes."
18358
+ subtitle: "Seu PIX est\xE1 sendo enviado. Aguarde alguns instantes.",
18359
+ phase,
18360
+ backgroundConfirmationLabels
18184
18361
  }
18185
18362
  ) });
18186
18363
  };