@0xsquid/deposit-widget 0.1.0-beta.0

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.
Files changed (122) hide show
  1. package/dist/cjs/index.cjs +4062 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/index.d.ts +52 -0
  4. package/dist/index.esm.js +4042 -0
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/types/DepositWidget.d.ts +7 -0
  7. package/dist/types/components/ViewTransition.d.ts +7 -0
  8. package/dist/types/components/shared/buttons/button.d.ts +3 -0
  9. package/dist/types/components/shared/icons/types.d.ts +3 -0
  10. package/dist/types/components/shared/icons/user-round.d.ts +2 -0
  11. package/dist/types/components/shared/navigation/base-navbar.d.ts +3 -0
  12. package/dist/types/components/shared/navigation/sub-navbar.d.ts +6 -0
  13. package/dist/types/components/token-badge-icon.d.ts +6 -0
  14. package/dist/types/components/token-list-item.d.ts +13 -0
  15. package/dist/types/components/view-container.d.ts +1 -0
  16. package/dist/types/constants.d.ts +1 -0
  17. package/dist/types/hooks/ui/useMainCTAButtonState.d.ts +8 -0
  18. package/dist/types/hooks/use-auto-select-token.d.ts +1 -0
  19. package/dist/types/hooks/use-deposit-route.d.ts +7 -0
  20. package/dist/types/hooks/use-token-selection.d.ts +5 -0
  21. package/dist/types/hooks/use-transaction-history.d.ts +6 -0
  22. package/dist/types/index.d.ts +3 -0
  23. package/dist/types/services/assets-service.d.ts +6 -0
  24. package/dist/types/services/wallet-history/format.d.ts +10 -0
  25. package/dist/types/services/wallet-history/format.test.d.ts +1 -0
  26. package/dist/types/services/wallet-history/get-main-explorer-url.d.ts +23 -0
  27. package/dist/types/services/wallet-history/get-wallet-history.d.ts +2 -0
  28. package/dist/types/services/wallet-history/types.d.ts +66 -0
  29. package/dist/types/services/wallet-history/validation.d.ts +2 -0
  30. package/dist/types/store/use-deposit-store.d.ts +9 -0
  31. package/dist/types/store/use-input-mode.d.ts +5 -0
  32. package/dist/types/store/useRouter.d.ts +12 -0
  33. package/dist/types/types.d.ts +43 -0
  34. package/dist/types/utils/format-date.d.ts +2 -0
  35. package/dist/types/utils/format-date.test.d.ts +1 -0
  36. package/dist/types/utils/transaction.d.ts +10 -0
  37. package/dist/types/views/connect-wallet/connect-wallet-view.d.ts +6 -0
  38. package/dist/types/views/connect-wallet/wallet-list-item.d.ts +9 -0
  39. package/dist/types/views/main/amount-input.d.ts +10 -0
  40. package/dist/types/views/main/connect-prompt.d.ts +1 -0
  41. package/dist/types/views/main/deposit-amount-input.d.ts +1 -0
  42. package/dist/types/views/main/deposit-form.d.ts +1 -0
  43. package/dist/types/views/main/main-cta-button.d.ts +1 -0
  44. package/dist/types/views/main/main-view.d.ts +1 -0
  45. package/dist/types/views/main/navbar/actions.d.ts +1 -0
  46. package/dist/types/views/main/navbar/icon.d.ts +1 -0
  47. package/dist/types/views/main/navbar/navbar.d.ts +1 -0
  48. package/dist/types/views/main/navbar/title.d.ts +10 -0
  49. package/dist/types/views/main/recipient/account.d.ts +14 -0
  50. package/dist/types/views/main/recipient/recipient.d.ts +1 -0
  51. package/dist/types/views/main/token-selector.d.ts +1 -0
  52. package/dist/types/views/qr-code.d.ts +1 -0
  53. package/dist/types/views/render-view.d.ts +3 -0
  54. package/dist/types/views/select-chain/chain-type-meta.d.ts +7 -0
  55. package/dist/types/views/select-chain/select-chain-view.d.ts +6 -0
  56. package/dist/types/views/select-token.d.ts +1 -0
  57. package/dist/types/views/transaction-history/activity-list-item.d.ts +4 -0
  58. package/dist/types/views/transaction-history/transaction-history-view.d.ts +1 -0
  59. package/dist/types/views/transaction-progress/helpers.d.ts +14 -0
  60. package/dist/types/views/transaction-progress/transaction-progress-view.d.ts +1 -0
  61. package/dist/types/views/transaction-progress/use-transaction-progress.d.ts +17 -0
  62. package/package.json +99 -0
  63. package/src/DepositWidget.tsx +158 -0
  64. package/src/compiled-tailwind.css +6100 -0
  65. package/src/components/ViewTransition.tsx +81 -0
  66. package/src/components/shared/buttons/button.tsx +17 -0
  67. package/src/components/shared/icons/types.ts +3 -0
  68. package/src/components/shared/icons/user-round.tsx +21 -0
  69. package/src/components/shared/navigation/base-navbar.tsx +15 -0
  70. package/src/components/shared/navigation/sub-navbar.tsx +46 -0
  71. package/src/components/token-badge-icon.tsx +31 -0
  72. package/src/components/token-list-item.tsx +84 -0
  73. package/src/components/view-container.tsx +16 -0
  74. package/src/constants.ts +1 -0
  75. package/src/css.d.ts +4 -0
  76. package/src/fonts/DMSans-Variable.woff2 +0 -0
  77. package/src/hooks/ui/useMainCTAButtonState.ts +143 -0
  78. package/src/hooks/use-auto-select-token.ts +65 -0
  79. package/src/hooks/use-deposit-route.ts +58 -0
  80. package/src/hooks/use-token-selection.ts +17 -0
  81. package/src/hooks/use-transaction-history.ts +198 -0
  82. package/src/index.ts +3 -0
  83. package/src/services/assets-service.ts +21 -0
  84. package/src/services/wallet-history/format.test.ts +63 -0
  85. package/src/services/wallet-history/format.ts +128 -0
  86. package/src/services/wallet-history/get-main-explorer-url.ts +74 -0
  87. package/src/services/wallet-history/get-wallet-history.ts +24 -0
  88. package/src/services/wallet-history/types.ts +66 -0
  89. package/src/services/wallet-history/validation.ts +60 -0
  90. package/src/store/use-deposit-store.ts +20 -0
  91. package/src/store/use-input-mode.ts +10 -0
  92. package/src/store/useRouter.ts +49 -0
  93. package/src/tailwind.css +16 -0
  94. package/src/types.ts +39 -0
  95. package/src/utils/format-date.test.ts +32 -0
  96. package/src/utils/format-date.ts +25 -0
  97. package/src/utils/transaction.ts +39 -0
  98. package/src/views/connect-wallet/connect-wallet-view.tsx +147 -0
  99. package/src/views/connect-wallet/wallet-list-item.tsx +69 -0
  100. package/src/views/main/amount-input.tsx +272 -0
  101. package/src/views/main/connect-prompt.tsx +47 -0
  102. package/src/views/main/deposit-amount-input.tsx +42 -0
  103. package/src/views/main/deposit-form.tsx +13 -0
  104. package/src/views/main/main-cta-button.tsx +14 -0
  105. package/src/views/main/main-view.tsx +24 -0
  106. package/src/views/main/navbar/actions.tsx +25 -0
  107. package/src/views/main/navbar/icon.tsx +11 -0
  108. package/src/views/main/navbar/navbar.tsx +16 -0
  109. package/src/views/main/navbar/title.tsx +64 -0
  110. package/src/views/main/recipient/account.tsx +81 -0
  111. package/src/views/main/recipient/recipient.tsx +64 -0
  112. package/src/views/main/token-selector.tsx +77 -0
  113. package/src/views/qr-code.tsx +14 -0
  114. package/src/views/render-view.tsx +28 -0
  115. package/src/views/select-chain/chain-type-meta.ts +37 -0
  116. package/src/views/select-chain/select-chain-view.tsx +97 -0
  117. package/src/views/select-token.tsx +227 -0
  118. package/src/views/transaction-history/activity-list-item.tsx +87 -0
  119. package/src/views/transaction-history/transaction-history-view.tsx +58 -0
  120. package/src/views/transaction-progress/helpers.tsx +93 -0
  121. package/src/views/transaction-progress/transaction-progress-view.tsx +217 -0
  122. package/src/views/transaction-progress/use-transaction-progress.ts +112 -0
@@ -0,0 +1,158 @@
1
+ import React, { useEffect, useMemo } from "react";
2
+ import {
3
+ SquidProvider,
4
+ useAllConnectedWalletBalances,
5
+ useAllTransactionsStatus,
6
+ useSwap,
7
+ } from "@0xsquid/react-hooks";
8
+ import { darkTheme, lightTheme, ThemeProvider } from "@0xsquid/ui";
9
+ import type { Theme, ThemeType } from "@0xsquid/ui";
10
+ import compiledCss from "./compiled-tailwind.css";
11
+ import { selectCurrentView, useRouter } from "./store/useRouter";
12
+ import { ViewTransition } from "./components/ViewTransition";
13
+ import { renderView } from "./views/render-view";
14
+ import { useAutoSelectToken } from "./hooks/use-auto-select-token";
15
+ import { useDepositStore, usePaymentAmount } from "./store/use-deposit-store";
16
+ import type { DepositConfig } from "./types";
17
+
18
+ interface DepositWidgetProps {
19
+ config: DepositConfig;
20
+ }
21
+
22
+ export function DepositWidget({
23
+ config,
24
+ }: DepositWidgetProps): React.ReactElement {
25
+ const { theme, themeType } = config;
26
+ return (
27
+ <SquidProvider
28
+ config={{ integratorId: config.integrator.id, apiUrl: config.apiUrl }}
29
+ placeholder={
30
+ <WidgetLayout theme={theme} themeType={themeType}>
31
+ <WidgetSkeleton />
32
+ </WidgetLayout>
33
+ }
34
+ >
35
+ <WidgetLayout theme={theme} themeType={themeType}>
36
+ <DepositWidgetContent config={config} />
37
+ </WidgetLayout>
38
+ </SquidProvider>
39
+ );
40
+ }
41
+
42
+ function DepositWidgetContent({
43
+ config,
44
+ }: {
45
+ config: DepositConfig;
46
+ }): React.ReactElement {
47
+ const currentView = useRouter(selectCurrentView);
48
+ const setConfig = useDepositStore((s) => s.setConfig);
49
+ const { onSwapChange, toAmountChanged, fromAmountChanged } = useSwap();
50
+
51
+ useEffect(() => {
52
+ setConfig(config);
53
+ }, [config, setConfig]);
54
+
55
+ useEffect(() => {
56
+ onSwapChange({
57
+ toChainId: config.destinationToken.chainId,
58
+ toTokenAddress: config.destinationToken.address,
59
+ destinationAddress: { address: config.destinationAddress },
60
+ });
61
+ // eslint-disable-next-line react-hooks/exhaustive-deps
62
+ }, [
63
+ config.destinationAddress,
64
+ config.destinationToken.chainId,
65
+ config.destinationToken.address,
66
+ ]);
67
+
68
+ const paymentAmount = usePaymentAmount();
69
+ useEffect(() => {
70
+ if (paymentAmount) {
71
+ fromAmountChanged("");
72
+ toAmountChanged(paymentAmount);
73
+ } else {
74
+ toAmountChanged("");
75
+ fromAmountChanged("");
76
+ }
77
+ }, [paymentAmount, toAmountChanged, fromAmountChanged]);
78
+
79
+ useAutoSelectToken();
80
+ useAllConnectedWalletBalances(); // Pre-warm balance cache
81
+ // Polls /v2/status for pending txs — also what registers them with Squid's backend for /history/wallet
82
+ useAllTransactionsStatus({ enabled: true });
83
+
84
+ return (
85
+ <ViewTransition viewId={currentView.id}>
86
+ {renderView(currentView)}
87
+ </ViewTransition>
88
+ );
89
+ }
90
+
91
+ interface WidgetLayoutProps {
92
+ theme?: Theme;
93
+ themeType?: ThemeType;
94
+ children: React.ReactNode;
95
+ }
96
+
97
+ function WidgetLayout({
98
+ theme,
99
+ themeType,
100
+ children,
101
+ }: WidgetLayoutProps): React.ReactElement {
102
+ const mergedTheme = useMemo<Theme>(() => {
103
+ const base = themeType === "dark" ? darkTheme : lightTheme;
104
+ const merged = { ...base.color, ...theme?.color };
105
+ return {
106
+ ...base,
107
+ ...theme,
108
+ fontFamily: {
109
+ ...base.fontFamily,
110
+ "squid-main": '"DMSansVariable", sans-serif',
111
+ // Integrator override wins.
112
+ ...theme?.fontFamily,
113
+ },
114
+ color: {
115
+ ...merged,
116
+ "animation-bg": merged["grey-900"],
117
+ "animation-text": merged["animation-bg"] ?? merged["grey-900"],
118
+ },
119
+ };
120
+ }, [theme, themeType]);
121
+
122
+ return (
123
+ <ThemeProvider theme={mergedTheme} themeType={themeType}>
124
+ <style
125
+ id="squid-deposit-widget-inline-style"
126
+ dangerouslySetInnerHTML={{ __html: compiledCss }}
127
+ />
128
+ <div className="squid-style-container--preflight tw-bg-grey-900 tw-text-grey-100 tw-flex tw-w-widget-card tw-h-widget-card tw-flex-col tw-items-center tw-shrink-0 tw-rounded-3xl tw-border tw-border-grey-900 dark:tw-shadow-widget-card-dark tw-shadow-widget-card-light tw-font-medium">
129
+ {children}
130
+ </div>
131
+ </ThemeProvider>
132
+ );
133
+ }
134
+
135
+ function WidgetSkeleton(): React.ReactElement {
136
+ return (
137
+ <div className="tw-flex tw-flex-col tw-flex-1 tw-w-full tw-animate-pulse">
138
+ {/* Connect-wallet content: logo + heading + description */}
139
+ <div className="tw-flex tw-pt-3 tw-pb-8 tw-px-4 tw-flex-col tw-justify-end tw-items-center tw-gap-4 tw-flex-1">
140
+ <div className="tw-w-32 tw-h-32 tw-rounded-full tw-bg-grey-800" />
141
+
142
+ <div className="tw-flex tw-pt-2 tw-pb-4 tw-flex-col tw-items-center tw-gap-4">
143
+ <div className="tw-h-6 tw-w-48 tw-rounded tw-bg-grey-800" />
144
+ <div className="tw-flex tw-flex-col tw-items-center tw-gap-2">
145
+ <div className="tw-h-4 tw-w-56 tw-rounded tw-bg-grey-800" />
146
+ <div className="tw-h-4 tw-w-40 tw-rounded tw-bg-grey-800" />
147
+ </div>
148
+ <div className="tw-h-4 tw-w-20 tw-rounded tw-bg-grey-800" />
149
+ </div>
150
+ </div>
151
+
152
+ {/* CTA button */}
153
+ <div className="tw-px-4 tw-pb-4">
154
+ <div className="tw-h-12 tw-w-full tw-rounded-full tw-bg-grey-800" />
155
+ </div>
156
+ </div>
157
+ );
158
+ }