@0xsquid/deposit-widget 0.1.0-beta.0 → 0.1.1-beta.1

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 (117) hide show
  1. package/dist/types/DepositWidget.d.ts +1 -0
  2. package/dist/types/components/ViewTransition.d.ts +1 -0
  3. package/dist/types/components/shared/buttons/button.d.ts +1 -0
  4. package/dist/types/components/shared/icons/types.d.ts +1 -0
  5. package/dist/types/components/shared/icons/user-round.d.ts +1 -0
  6. package/dist/types/components/shared/navigation/base-navbar.d.ts +1 -0
  7. package/dist/types/components/shared/navigation/sub-navbar.d.ts +1 -0
  8. package/dist/types/components/token-badge-icon.d.ts +1 -0
  9. package/dist/types/components/token-list-item.d.ts +1 -0
  10. package/dist/types/components/view-container.d.ts +1 -0
  11. package/dist/types/constants.d.ts +1 -0
  12. package/dist/types/hooks/ui/useMainCTAButtonState.d.ts +1 -0
  13. package/dist/types/hooks/use-auto-select-token.d.ts +1 -0
  14. package/dist/types/hooks/use-deposit-route.d.ts +1 -0
  15. package/dist/types/hooks/use-token-selection.d.ts +1 -0
  16. package/dist/types/hooks/use-transaction-history.d.ts +1 -0
  17. package/dist/types/index.d.ts +1 -0
  18. package/dist/types/services/assets-service.d.ts +1 -0
  19. package/dist/types/services/wallet-history/format.d.ts +1 -0
  20. package/dist/types/services/wallet-history/format.test.d.ts +1 -0
  21. package/dist/types/services/wallet-history/get-main-explorer-url.d.ts +1 -0
  22. package/dist/types/services/wallet-history/get-wallet-history.d.ts +1 -0
  23. package/dist/types/services/wallet-history/types.d.ts +1 -0
  24. package/dist/types/services/wallet-history/validation.d.ts +1 -0
  25. package/dist/types/store/use-deposit-store.d.ts +1 -0
  26. package/dist/types/store/use-input-mode.d.ts +1 -0
  27. package/dist/types/store/useRouter.d.ts +1 -0
  28. package/dist/types/types.d.ts +1 -0
  29. package/dist/types/utils/format-date.d.ts +1 -0
  30. package/dist/types/utils/format-date.test.d.ts +1 -0
  31. package/dist/types/utils/transaction.d.ts +1 -0
  32. package/dist/types/views/connect-wallet/connect-wallet-view.d.ts +1 -0
  33. package/dist/types/views/connect-wallet/wallet-list-item.d.ts +1 -0
  34. package/dist/types/views/main/amount-input.d.ts +1 -0
  35. package/dist/types/views/main/connect-prompt.d.ts +1 -0
  36. package/dist/types/views/main/deposit-amount-input.d.ts +1 -0
  37. package/dist/types/views/main/deposit-form.d.ts +1 -0
  38. package/dist/types/views/main/main-cta-button.d.ts +1 -0
  39. package/dist/types/views/main/main-view.d.ts +1 -0
  40. package/dist/types/views/main/navbar/actions.d.ts +1 -0
  41. package/dist/types/views/main/navbar/icon.d.ts +1 -0
  42. package/dist/types/views/main/navbar/navbar.d.ts +1 -0
  43. package/dist/types/views/main/navbar/title.d.ts +1 -0
  44. package/dist/types/views/main/recipient/account.d.ts +1 -0
  45. package/dist/types/views/main/recipient/recipient.d.ts +1 -0
  46. package/dist/types/views/main/token-selector.d.ts +1 -0
  47. package/dist/types/views/qr-code.d.ts +1 -0
  48. package/dist/types/views/render-view.d.ts +1 -0
  49. package/dist/types/views/select-chain/chain-type-meta.d.ts +1 -0
  50. package/dist/types/views/select-chain/select-chain-view.d.ts +1 -0
  51. package/dist/types/views/select-token.d.ts +1 -0
  52. package/dist/types/views/transaction-history/activity-list-item.d.ts +1 -0
  53. package/dist/types/views/transaction-history/transaction-history-view.d.ts +1 -0
  54. package/dist/types/views/transaction-progress/helpers.d.ts +1 -0
  55. package/dist/types/views/transaction-progress/transaction-progress-view.d.ts +1 -0
  56. package/dist/types/views/transaction-progress/use-transaction-progress.d.ts +1 -0
  57. package/package.json +7 -4
  58. package/src/DepositWidget.tsx +0 -158
  59. package/src/compiled-tailwind.css +0 -6100
  60. package/src/components/ViewTransition.tsx +0 -81
  61. package/src/components/shared/buttons/button.tsx +0 -17
  62. package/src/components/shared/icons/types.ts +0 -3
  63. package/src/components/shared/icons/user-round.tsx +0 -21
  64. package/src/components/shared/navigation/base-navbar.tsx +0 -15
  65. package/src/components/shared/navigation/sub-navbar.tsx +0 -46
  66. package/src/components/token-badge-icon.tsx +0 -31
  67. package/src/components/token-list-item.tsx +0 -84
  68. package/src/components/view-container.tsx +0 -16
  69. package/src/constants.ts +0 -1
  70. package/src/css.d.ts +0 -4
  71. package/src/fonts/DMSans-Variable.woff2 +0 -0
  72. package/src/hooks/ui/useMainCTAButtonState.ts +0 -143
  73. package/src/hooks/use-auto-select-token.ts +0 -65
  74. package/src/hooks/use-deposit-route.ts +0 -58
  75. package/src/hooks/use-token-selection.ts +0 -17
  76. package/src/hooks/use-transaction-history.ts +0 -198
  77. package/src/index.ts +0 -3
  78. package/src/services/assets-service.ts +0 -21
  79. package/src/services/wallet-history/format.test.ts +0 -63
  80. package/src/services/wallet-history/format.ts +0 -128
  81. package/src/services/wallet-history/get-main-explorer-url.ts +0 -74
  82. package/src/services/wallet-history/get-wallet-history.ts +0 -24
  83. package/src/services/wallet-history/types.ts +0 -66
  84. package/src/services/wallet-history/validation.ts +0 -60
  85. package/src/store/use-deposit-store.ts +0 -20
  86. package/src/store/use-input-mode.ts +0 -10
  87. package/src/store/useRouter.ts +0 -49
  88. package/src/tailwind.css +0 -16
  89. package/src/types.ts +0 -39
  90. package/src/utils/format-date.test.ts +0 -32
  91. package/src/utils/format-date.ts +0 -25
  92. package/src/utils/transaction.ts +0 -39
  93. package/src/views/connect-wallet/connect-wallet-view.tsx +0 -147
  94. package/src/views/connect-wallet/wallet-list-item.tsx +0 -69
  95. package/src/views/main/amount-input.tsx +0 -272
  96. package/src/views/main/connect-prompt.tsx +0 -47
  97. package/src/views/main/deposit-amount-input.tsx +0 -42
  98. package/src/views/main/deposit-form.tsx +0 -13
  99. package/src/views/main/main-cta-button.tsx +0 -14
  100. package/src/views/main/main-view.tsx +0 -24
  101. package/src/views/main/navbar/actions.tsx +0 -25
  102. package/src/views/main/navbar/icon.tsx +0 -11
  103. package/src/views/main/navbar/navbar.tsx +0 -16
  104. package/src/views/main/navbar/title.tsx +0 -64
  105. package/src/views/main/recipient/account.tsx +0 -81
  106. package/src/views/main/recipient/recipient.tsx +0 -64
  107. package/src/views/main/token-selector.tsx +0 -77
  108. package/src/views/qr-code.tsx +0 -14
  109. package/src/views/render-view.tsx +0 -28
  110. package/src/views/select-chain/chain-type-meta.ts +0 -37
  111. package/src/views/select-chain/select-chain-view.tsx +0 -97
  112. package/src/views/select-token.tsx +0 -227
  113. package/src/views/transaction-history/activity-list-item.tsx +0 -87
  114. package/src/views/transaction-history/transaction-history-view.tsx +0 -58
  115. package/src/views/transaction-progress/helpers.tsx +0 -93
  116. package/src/views/transaction-progress/transaction-progress-view.tsx +0 -217
  117. package/src/views/transaction-progress/use-transaction-progress.ts +0 -112
@@ -5,3 +5,4 @@ interface DepositWidgetProps {
5
5
  }
6
6
  export declare function DepositWidget({ config, }: DepositWidgetProps): React.ReactElement;
7
7
  export {};
8
+ //# sourceMappingURL=DepositWidget.d.ts.map
@@ -5,3 +5,4 @@ interface ViewTransitionProps {
5
5
  }
6
6
  export declare function ViewTransition({ viewId, children }: ViewTransitionProps): import("react/jsx-runtime").JSX.Element;
7
7
  export {};
8
+ //# sourceMappingURL=ViewTransition.d.ts.map
@@ -1,3 +1,4 @@
1
1
  type ButtonProps = React.ComponentProps<"button">;
2
2
  export declare function Button(props: ButtonProps): import("react/jsx-runtime").JSX.Element;
3
3
  export {};
4
+ //# sourceMappingURL=button.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export interface IconProps extends React.ComponentProps<"svg"> {
2
2
  size?: `${number}rem`;
3
3
  }
4
+ //# sourceMappingURL=types.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { IconProps } from "./types";
2
2
  export declare function UserRoundIcon({ size, ...props }: IconProps): import("react/jsx-runtime").JSX.Element;
3
+ //# sourceMappingURL=user-round.d.ts.map
@@ -1,3 +1,4 @@
1
1
  type BaseNavBarProps = React.ComponentProps<"nav">;
2
2
  export declare function BaseNavBar({ className, ...props }: BaseNavBarProps): import("react/jsx-runtime").JSX.Element;
3
3
  export {};
4
+ //# sourceMappingURL=base-navbar.d.ts.map
@@ -4,3 +4,4 @@ interface SubNavBarProps {
4
4
  }
5
5
  export declare function SubNavBar({ title, input }: SubNavBarProps): import("react/jsx-runtime").JSX.Element;
6
6
  export {};
7
+ //# sourceMappingURL=sub-navbar.d.ts.map
@@ -4,3 +4,4 @@ interface TokenBadgeIconProps {
4
4
  }
5
5
  export declare function TokenBadgeIcon({ tokenSrc, chainSrc }: TokenBadgeIconProps): import("react/jsx-runtime").JSX.Element;
6
6
  export {};
7
+ //# sourceMappingURL=token-badge-icon.d.ts.map
@@ -11,3 +11,4 @@ interface TokenListItemProps extends React.ComponentProps<"button"> {
11
11
  }
12
12
  export declare function TokenListItem({ icon, chainIcon, symbol, name, balance, price, usdValue, disabled, isLoadingBalance, ...props }: TokenListItemProps): import("react/jsx-runtime").JSX.Element;
13
13
  export {};
14
+ //# sourceMappingURL=token-list-item.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function ViewContainer({ className, ...props }: React.ComponentProps<"section">): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=view-container.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare const VIEW_TRANSITION_DURATION_MS = 250;
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -6,3 +6,4 @@ interface ButtonState {
6
6
  }
7
7
  export declare function useMainCTAButtonState(): ButtonState;
8
8
  export {};
9
+ //# sourceMappingURL=useMainCTAButtonState.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function useAutoSelectToken(): void;
2
+ //# sourceMappingURL=use-auto-select-token.d.ts.map
@@ -5,3 +5,4 @@ export declare function useDepositRoute(): {
5
5
  showLoading: boolean;
6
6
  routeErrorMessage: string | undefined;
7
7
  };
8
+ //# sourceMappingURL=use-deposit-route.d.ts.map
@@ -3,3 +3,4 @@ export declare function useTokenSelection(): {
3
3
  chain: import("@0xsquid/squid-types").ChainData | undefined;
4
4
  balance: string;
5
5
  };
6
+ //# sourceMappingURL=use-token-selection.d.ts.map
@@ -4,3 +4,4 @@ export declare function useTransactionHistory(): {
4
4
  isError: boolean;
5
5
  groups: DayGroup[];
6
6
  };
7
+ //# sourceMappingURL=use-transaction-history.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export { DepositWidget } from "./DepositWidget";
2
2
  export type { DepositConfig, WidgetView, WidgetViewId } from "./types";
3
3
  export type { Theme, ThemeType } from "@0xsquid/ui";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -4,3 +4,4 @@ export type TokenWithBalance = Token & {
4
4
  };
5
5
  export declare function sortTokensByBalance(tokens: TokenWithBalance[]): TokenWithBalance[];
6
6
  export declare function filterTokensByChain(tokens: TokenWithBalance[], chainId: string | null): TokenWithBalance[];
7
+ //# sourceMappingURL=assets-service.d.ts.map
@@ -8,3 +8,4 @@ export interface DayGroup {
8
8
  export declare function toFormattedTx(tx: SquidTransaction, sourceChain: ChainData | undefined): FormattedTx;
9
9
  export declare function pendingSwapToFormattedTx(pending: SwapTransactionHistory, findToken: (address?: string, chainId?: string) => Token | undefined, findChain: (chainId: string | undefined) => ChainData | undefined): FormattedTx;
10
10
  export declare function groupAndSortByDay(txs: FormattedTx[]): DayGroup[];
11
+ //# sourceMappingURL=format.d.ts.map
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=format.test.d.ts.map
@@ -21,3 +21,4 @@ export interface MainExplorer {
21
21
  name: string;
22
22
  }
23
23
  export declare function getMainExplorerUrl(transaction: ExplorerInput): MainExplorer | undefined;
24
+ //# sourceMappingURL=get-main-explorer-url.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { SquidTransaction } from "./types";
2
2
  export declare function getWalletHistory(address: string, integratorId: string, apiUrl: string): Promise<SquidTransaction[]>;
3
+ //# sourceMappingURL=get-wallet-history.d.ts.map
@@ -64,3 +64,4 @@ export interface FormattedTx {
64
64
  };
65
65
  id: string;
66
66
  }
67
+ //# sourceMappingURL=types.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { SquidTransaction } from "./types";
2
2
  export declare function isSquidTransaction(tx: unknown): tx is SquidTransaction;
3
+ //# sourceMappingURL=validation.d.ts.map
@@ -7,3 +7,4 @@ export declare const useDepositStore: import("zustand").UseBoundStore<import("zu
7
7
  export declare const useIsPaymentMode: () => boolean;
8
8
  export declare const usePaymentAmount: () => string | null;
9
9
  export {};
10
+ //# sourceMappingURL=use-deposit-store.d.ts.map
@@ -3,3 +3,4 @@ export declare const useInputMode: import("zustand").UseBoundStore<import("zusta
3
3
  mode: UserInputType;
4
4
  setMode: (_mode: UserInputType) => void;
5
5
  }>>;
6
+ //# sourceMappingURL=use-input-mode.d.ts.map
@@ -10,3 +10,4 @@ interface WidgetNavigationState {
10
10
  export declare const selectCurrentView: (state: WidgetNavigationState) => WidgetView;
11
11
  export declare const useRouter: import("zustand").UseBoundStore<import("zustand").StoreApi<WidgetNavigationState>>;
12
12
  export {};
13
+ //# sourceMappingURL=useRouter.d.ts.map
@@ -41,3 +41,4 @@ export type DepositConfig = (BaseDepositConfig & {
41
41
  amount: string;
42
42
  });
43
43
  export {};
44
+ //# sourceMappingURL=types.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export declare function formatDateToHhMm(date: Date): string;
2
2
  export declare function formatDayHeader(yyyyMmDd: string): string;
3
+ //# sourceMappingURL=format-date.d.ts.map
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=format-date.test.d.ts.map
@@ -8,3 +8,4 @@ export declare function matchesDestinationToken(toToken: {
8
8
  chainId: string;
9
9
  }, destinationToken: DepositConfig["destinationToken"]): boolean;
10
10
  export declare function isPaymentTx(tx: SquidTransaction, paymentAmount: string, destinationTokenDecimals: number): boolean;
11
+ //# sourceMappingURL=transaction.d.ts.map
@@ -4,3 +4,4 @@ interface ConnectWalletViewProps {
4
4
  }
5
5
  export declare function ConnectWalletView({ chainType }: ConnectWalletViewProps): import("react/jsx-runtime").JSX.Element;
6
6
  export {};
7
+ //# sourceMappingURL=connect-wallet-view.d.ts.map
@@ -7,3 +7,4 @@ interface WalletListItemProps extends React.ComponentProps<"button"> {
7
7
  }
8
8
  export declare function WalletListItem({ wallet, isConnecting, showAsMultiChain, parentProps, ...props }: WalletListItemProps): import("react/jsx-runtime").JSX.Element;
9
9
  export {};
10
+ //# sourceMappingURL=wallet-list-item.d.ts.map
@@ -8,3 +8,4 @@ interface AmountInputProps extends NumericInputProps {
8
8
  }
9
9
  export declare function AmountInput({ balance, token, onAmountChange, forcedAmount, maxUsdDecimals, formatIfVerySmall, inputModeButton, debounceInput, allowMaxButton, readOnly, errorMessage, loading, forcedUsdDisplay, }: AmountInputProps): import("react/jsx-runtime").JSX.Element;
10
10
  export {};
11
+ //# sourceMappingURL=amount-input.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function ConnectPrompt(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=connect-prompt.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function DepositAmountInput(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=deposit-amount-input.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function DepositForm(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=deposit-form.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function MainCTAButton(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=main-cta-button.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function MainView(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=main-view.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function Actions(): import("react/jsx-runtime").JSX.Element | null;
2
+ //# sourceMappingURL=actions.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function Icon(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=icon.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function NavBar(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=navbar.d.ts.map
@@ -8,3 +8,4 @@ interface TitleLabelInput {
8
8
  }
9
9
  export declare function buildTitleLabel({ isPaymentMode, paymentAmount, tokenSymbol, tokenUsdPrice, name, }: TitleLabelInput): string;
10
10
  export {};
11
+ //# sourceMappingURL=title.d.ts.map
@@ -12,3 +12,4 @@ interface AvatarProps {
12
12
  }
13
13
  export declare function Avatar({ icon, onDisconnect }: AvatarProps): import("react/jsx-runtime").JSX.Element;
14
14
  export {};
15
+ //# sourceMappingURL=account.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function Recipient(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=recipient.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function TokenSelector(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=token-selector.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function QrCodeView(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=qr-code.d.ts.map
@@ -1,3 +1,4 @@
1
1
  import React from "react";
2
2
  import type { WidgetView } from "../types";
3
3
  export declare function renderView(view: WidgetView): React.ReactElement;
4
+ //# sourceMappingURL=render-view.d.ts.map
@@ -5,3 +5,4 @@ interface ChainTypeMeta {
5
5
  }
6
6
  export declare const CHAIN_TYPE_META: Record<ChainType, ChainTypeMeta>;
7
7
  export {};
8
+ //# sourceMappingURL=chain-type-meta.d.ts.map
@@ -4,3 +4,4 @@ interface SelectChainViewProps {
4
4
  }
5
5
  export declare function SelectChainView({ wallet }: SelectChainViewProps): import("react/jsx-runtime").JSX.Element | null;
6
6
  export {};
7
+ //# sourceMappingURL=select-chain-view.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function SelectTokenView(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=select-token.d.ts.map
@@ -2,3 +2,4 @@ import type { FormattedTx } from "../../services/wallet-history/types";
2
2
  type Props = FormattedTx;
3
3
  export declare function ActivityListItem({ fromAmount, fromToken, fromChain, toAmount, toToken, timestamp, status, explorer, }: Props): import("react/jsx-runtime").JSX.Element;
4
4
  export {};
5
+ //# sourceMappingURL=activity-list-item.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function TransactionHistoryView(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=transaction-history-view.d.ts.map
@@ -12,3 +12,4 @@ export declare function TimeDetail({ status, timer, estimatedTimeDisplay, }: {
12
12
  timer: string;
13
13
  estimatedTimeDisplay: string | undefined;
14
14
  }): import("react/jsx-runtime").JSX.Element;
15
+ //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function TransactionProgressView(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=transaction-progress-view.d.ts.map
@@ -15,3 +15,4 @@ export declare function useTransactionProgress(): {
15
15
  address: string;
16
16
  };
17
17
  };
18
+ //# sourceMappingURL=use-transaction-progress.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@0xsquid/deposit-widget",
3
3
  "description": "Squid deposit widget",
4
- "version": "0.1.0-beta.0",
4
+ "version": "0.1.1-beta.1",
5
5
  "author": "",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -11,17 +11,20 @@
11
11
  },
12
12
  "main": "dist/cjs/index.cjs",
13
13
  "module": "dist/index.esm.js",
14
- "types": "dist/index.d.ts",
14
+ "types": "dist/types/index.d.ts",
15
15
  "exports": {
16
16
  ".": {
17
- "types": "./dist/index.d.ts",
17
+ "types": "./dist/types/index.d.ts",
18
18
  "import": "./dist/index.esm.js",
19
19
  "require": "./dist/cjs/index.cjs"
20
20
  }
21
21
  },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
22
25
  "files": [
23
26
  "dist",
24
- "src"
27
+ "!dist/**/*.d.ts.map"
25
28
  ],
26
29
  "scripts": {
27
30
  "build": "yarn build-css && rollup -c",
@@ -1,158 +0,0 @@
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
- }