@dhedge/trading-widget 4.0.11 → 4.1.1-canary.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 (36) hide show
  1. package/README.md +13 -9
  2. package/core-kit/const/currency.d.ts +1 -0
  3. package/core-kit/hooks/trading/use-swaps-data-query.d.ts +12 -3
  4. package/core-kit/hooks/trading/withdraw-v2/init-step/use-fetch-init-withdraw-aave-swap-data.d.ts +1 -1
  5. package/core-kit/utils/aave.d.ts +2 -1
  6. package/core-kit/utils/formatter.d.ts +7 -0
  7. package/core-kit/utils/swap-data.d.ts +12 -0
  8. package/core-kit/utils/token.d.ts +1 -0
  9. package/core-kit/utils/transaction.d.ts +2 -2
  10. package/index.cjs +10 -10
  11. package/index.js +4025 -3884
  12. package/package.json +1 -1
  13. package/style.css +1 -1
  14. package/trading-widget/components/common/balance/balance.d.ts +1 -1
  15. package/trading-widget/components/common/layout/index.d.ts +0 -2
  16. package/trading-widget/components/widget/widget-buttons/index.d.ts +1 -0
  17. package/trading-widget/components/widget/widget-buttons/limit-order-button/limit-order-button.d.ts +3 -0
  18. package/trading-widget/components/widget/widget-input/index.d.ts +3 -0
  19. package/trading-widget/components/widget/widget-input/input-arrow/input-arrow.d.ts +2 -0
  20. package/trading-widget/components/widget/widget-input/input-arrow/input-arrow.hooks.d.ts +3 -0
  21. package/trading-widget/components/widget/widget-input/receive-token-balance/receive-token-balance.d.ts +2 -0
  22. package/trading-widget/components/widget/widget-input/receive-token-balance/receive-token-balance.hooks.d.ts +4 -0
  23. package/trading-widget/components/widget/widget-input/send-token-balance/send-token-balance.d.ts +2 -0
  24. package/trading-widget/components/widget/widget-input/send-token-balance/send-token-balance.hooks.d.ts +4 -0
  25. package/trading-widget/components/widget/widget-input/widget-input.d.ts +2 -2
  26. package/trading-widget/components/withdraw/init-step/button/valid-init-withdraw-button/valid-init-withdraw-button.hooks.d.ts +0 -2
  27. package/trading-widget/providers/component-provider/component-provider.d.ts +1 -0
  28. package/trading-widget/providers/component-provider/component-provider.hooks.d.ts +1 -0
  29. package/trading-widget/providers/component-provider/component-provider.types.d.ts +4 -0
  30. package/trading-widget/providers/theme-provider/theme-provider.types.d.ts +15 -2
  31. package/trading-widget/providers/translation-provider/translation-provider.types.d.ts +5 -3
  32. package/trading-widget/components/common/layout/balance/balance.d.ts +0 -2
  33. package/trading-widget/components/deposit/balance/balance.d.ts +0 -2
  34. package/trading-widget/components/deposit/balance/balance.hooks.d.ts +0 -4
  35. package/trading-widget/components/withdraw/init-step/balance/init-withdraw-balance.d.ts +0 -2
  36. package/trading-widget/components/withdraw/init-step/balance/init-withdraw-balance.hooks.d.ts +0 -4
package/README.md CHANGED
@@ -454,12 +454,16 @@ path: `component.actionButton[name]`
454
454
 
455
455
  path: `component.meta[name]`
456
456
 
457
- > | name | type | default value | description |
458
- > | --------------------- | ------ | ------------------------------------ | -------------------- |
459
- > | `size.gap` | string | `global.size.gap` | Meta flex gap |
460
- > | `size.px` | string | `global.size.spacer * 3` | Meta padding inline |
461
- > | `color.linkTextColor` | string | `global.color.colorBgAccentFrom` | Meta link text color |
462
- > | `color.panelBgHover` | string | `config.global.color.colorBgNeutral` | Meta panel hover bg |
457
+ > | name | type | default value | description |
458
+ > | --------------------------- | ------ | ------------------------------------ | --------------------------- |
459
+ > | `size.gap` | string | `global.size.gap` | Meta flex gap |
460
+ > | `size.px` | string | `global.size.spacer * 3` | Meta padding inline |
461
+ > | `size.fontSize` | string | `global.size.fontSizeXs` | Meta font size |
462
+ > | `size.lineHeight` | string | `global.size.lineHeightXs` | Meta line height |
463
+ > | `size.emphasisedFontSize` | string | `global.size.fontSizeSm` | Meta font size emphasised |
464
+ > | `size.emphasisedLineHeight` | string | `global.size.lineHeightSm` | Meta line height emphasised |
465
+ > | `color.linkTextColor` | string | `global.color.colorBgAccentFrom` | Meta link text color |
466
+ > | `color.panelBgHover` | string | `config.global.color.colorBgNeutral` | Meta panel hover bg |
463
467
 
464
468
  ###### Source: `packages/trading-widget/src/trading-widget/providers/theme-provider/theme-provider.tsx`
465
469
 
@@ -507,12 +511,9 @@ path: `component.meta[name]`
507
511
  > | `lengthenLockup` | string | Lengthen lockup to remove entry fee | |
508
512
  > | `deposit` | string | Buy | |
509
513
  > | `withdraw` | string | Sell | |
510
- > | `yourBalance` | string | Your Balance | |
511
514
  > | `max` | string | Max | |
512
515
  > | `allAssets` | string | All Assets | |
513
516
  > | `all` | string | All | |
514
- > | `payWith` | string | Pay with | |
515
- > | `buyEstimated` | string | Buy (estimated) | |
516
517
  > | `sell` | string | Sell | |
517
518
  > | `receiveEstimated` | string | Receive (estimated) | |
518
519
  > | `confirmInWallet` | string | Please confirm in wallet | |
@@ -582,6 +583,9 @@ path: `component.meta[name]`
582
583
  > | `paidLabel` | string | Paid | |
583
584
  > | `priceLabel` | string | Price | |
584
585
  > | `transactionLabel` | string | Transaction | |
586
+ > | `stopOrder` | string | Stop Order | |
587
+ > | `send` | string | Send | |
588
+ > | `cooldown` | string | Cooldown | |
585
589
 
586
590
  ###### Source: `packages/trading-widget/src/trading-widget/providers/translation-provider/translation-provider.tsx`
587
591
 
@@ -1,3 +1,4 @@
1
1
  import type { ApyCurrency } from '../types';
2
2
  export declare const CURRENCY_SYMBOL_MAP: Record<ApyCurrency, string>;
3
3
  export declare const CURRENCY_DECIMALS_MAP: Record<ApyCurrency, number>;
4
+ export declare const STABLE_TOKEN_SYMBOLS: string[];
@@ -2,13 +2,22 @@ import { type UseQueryOptions } from '@tanstack/react-query';
2
2
  import type { Address } from 'viem';
3
3
  import { useGetSwapData } from '../../hooks/state';
4
4
  import type { SwapDataRequest, SwapDataResponse } from '../../types';
5
- export declare const fetchSwapsData: ({ assets, getSwapData, signal, }: {
6
- assets: Omit<SwapDataRequest, 'fromAddress'>[];
5
+ import type { AssetWithoutFromAddress, SwapsDataMap } from '../../utils/swap-data';
6
+ interface FetchSwapsDataParams {
7
+ assets: AssetWithoutFromAddress[];
7
8
  getSwapData: ReturnType<typeof useGetSwapData>;
8
9
  signal: AbortSignal;
9
- }) => Promise<Record<Address, SwapDataResponse>>;
10
+ }
11
+ /**
12
+ * Aave-specific variant: during Aave swaps it is possible to have two entries
13
+ * with the same source asset and the same destination asset but different amounts.
14
+ * To avoid key collisions it includes the amount.
15
+ */
16
+ export declare const fetchSwapsDataForAave: ({ assets, getSwapData, signal, }: FetchSwapsDataParams) => Promise<SwapsDataMap<string>>;
17
+ export declare const fetchSwapsData: ({ assets, getSwapData, signal, }: FetchSwapsDataParams) => Promise<SwapsDataMap<Address>>;
10
18
  export declare const useSwapsDataQuery: (assets: Omit<SwapDataRequest, 'fromAddress'>[], options?: Omit<UseQueryOptions<Record<Address, SwapDataResponse | null>, Error, Record<Address, SwapDataResponse | null>, [
11
19
  string,
12
20
  Omit<SwapDataRequest, 'fromAddress'>[],
13
21
  string[]
14
22
  ]>, 'queryKey' | 'queryFn'>) => import("@tanstack/react-query/build/legacy/types").UseQueryResult<Record<`0x${string}`, SwapDataResponse | null>, Error>;
23
+ export {};
@@ -2,4 +2,4 @@ import type { CalculateSwapDataParamsResponse, PoolConfig } from '../../../../ty
2
2
  export declare const useFetchInitWithdrawAaveSwapData: ({ chainId, }: Pick<PoolConfig, 'chainId'>) => ({ swapParams, slippage, }: {
3
3
  swapParams: CalculateSwapDataParamsResponse | undefined;
4
4
  slippage: number;
5
- }) => Promise<Record<`0x${string}`, import('../../../../types').SwapDataResponse>>;
5
+ }) => Promise<import("../../../../utils/swap-data").SwapsDataMap<string>>;
@@ -1,6 +1,7 @@
1
- import type { Address, ChainId } from '../types';
1
+ import type { Address, ChainId, SwapDataRequest } from '../types';
2
2
  export interface IsLendAndBorrowAssetParams {
3
3
  address: Address;
4
4
  chainId: ChainId;
5
5
  }
6
6
  export declare const isAaveLendAndBorrowAsset: ({ address, chainId, }: IsLendAndBorrowAssetParams) => boolean;
7
+ export declare const buildSwapDataKeyForAave: ({ sourceAddress, amount, }: Pick<SwapDataRequest, 'sourceAddress' | 'amount'>) => string;
@@ -20,3 +20,10 @@ export declare function formatBalanceInUsd(balance: string | undefined, tokenPri
20
20
  balanceInUsdNumber: number;
21
21
  };
22
22
  export declare const formatVaultBalance: (balance: bigint | undefined, tokenPrice: bigint | undefined) => Balance;
23
+ export declare const truncateString: (str: string, first?: number, last?: number) => string;
24
+ export declare const formatTokenBalance: ({ balance, symbol, precision, truncateSymbol, }: {
25
+ balance: string;
26
+ symbol: string;
27
+ precision: number;
28
+ truncateSymbol?: boolean | undefined;
29
+ }) => string;
@@ -0,0 +1,12 @@
1
+ import type { useGetSwapData } from '../hooks/state';
2
+ import type { SwapDataRequest, SwapDataResponse } from '../types';
3
+ export type AssetWithoutFromAddress = Omit<SwapDataRequest, 'fromAddress'>;
4
+ export type SwapsDataMap<T extends string> = Record<T, SwapDataResponse | null>;
5
+ interface FetchSwapsDataWithKeyParams<K extends string> {
6
+ assets: AssetWithoutFromAddress[];
7
+ getSwapData: ReturnType<typeof useGetSwapData>;
8
+ signal: AbortSignal;
9
+ buildKey: (asset: AssetWithoutFromAddress) => K;
10
+ }
11
+ export declare const fetchSwapsDataWithKey: <K extends string>({ assets, getSwapData, signal, buildKey, }: FetchSwapsDataWithKeyParams<K>) => Promise<SwapsDataMap<K>>;
12
+ export {};
@@ -6,3 +6,4 @@ export declare const getNativeTokenInvestableBalance: ({ nativeTokenBalance, tok
6
6
  gasPrice: number;
7
7
  tokenDecimals: number;
8
8
  }) => BigNumber;
9
+ export declare const isStableSymbol: (symbol: string) => boolean;
@@ -1,5 +1,5 @@
1
1
  import type { Address, Hex } from 'viem';
2
- import type { useSwapsDataQuery } from '../hooks/trading/use-swaps-data-query';
2
+ import type { fetchSwapsDataForAave, useSwapsDataQuery } from '../hooks/trading/use-swaps-data-query';
3
3
  import type { useCompleteWithdrawTrackedAssets } from '../hooks/trading/withdraw-v2/complete-step/use-complete-withdraw-tracked-assets';
4
4
  import type { CalculateSwapDataParamsResponse } from '../types';
5
5
  /**
@@ -30,7 +30,7 @@ export declare const buildSwapWithdrawTransactionData: ({ receiveAssetAddress, s
30
30
  export declare const buildAaveWithdrawAssetTransactionData: ({ assetAddress, swapData, swapParams, slippageToleranceForContractTransaction, }: {
31
31
  assetAddress: Address;
32
32
  swapParams: CalculateSwapDataParamsResponse | undefined;
33
- swapData: ReturnType<typeof useSwapsDataQuery>['data'];
33
+ swapData: Awaited<ReturnType<typeof fetchSwapsDataForAave>>;
34
34
  slippageToleranceForContractTransaction: bigint;
35
35
  }) => {
36
36
  supportedAsset: `0x${string}`;