@coin-voyage/shared 2.2.1 → 2.2.3

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 (55) hide show
  1. package/dist/api/client.d.ts +3 -3
  2. package/dist/api/client.js +3 -2
  3. package/dist/api/fetcher.js +12 -1
  4. package/dist/common/address.d.ts +1 -1
  5. package/dist/common/address.js +1 -1
  6. package/dist/{utils → common}/browser.d.ts +1 -1
  7. package/dist/common/chain-explorer.d.ts +1 -1
  8. package/dist/common/chain-explorer.js +1 -1
  9. package/dist/common/chains.d.ts +1 -28
  10. package/dist/common/chains.js +1 -38
  11. package/dist/common/format.d.ts +4 -0
  12. package/dist/common/format.js +35 -0
  13. package/dist/common/index.d.ts +4 -2
  14. package/dist/common/index.js +4 -2
  15. package/dist/common/organization.d.ts +1 -1
  16. package/dist/common/time.d.ts +1 -0
  17. package/dist/common/time.js +6 -0
  18. package/dist/common/{pay-order/validation.d.ts → validation.d.ts} +0 -11
  19. package/dist/common/{pay-order/validation.js → validation.js} +3 -3
  20. package/dist/hooks/index.d.ts +5 -1
  21. package/dist/hooks/index.js +5 -1
  22. package/dist/hooks/use-focus-trap.d.ts +9 -0
  23. package/dist/hooks/use-focus-trap.js +53 -0
  24. package/dist/hooks/use-is-client.d.ts +1 -0
  25. package/dist/hooks/use-is-client.js +5 -0
  26. package/dist/hooks/use-is-mobile.d.ts +1 -1
  27. package/dist/hooks/use-is-mobile.js +2 -2
  28. package/dist/hooks/use-previous.d.ts +1 -0
  29. package/dist/hooks/use-previous.js +8 -0
  30. package/dist/hooks/use-window-size.d.ts +4 -0
  31. package/dist/hooks/use-window-size.js +19 -0
  32. package/dist/types/api.d.ts +3 -1
  33. package/dist/{common/pay-order → types}/enums.d.ts +28 -0
  34. package/dist/types/enums.js +66 -0
  35. package/dist/{common/pay-order → types}/events.d.ts +3 -3
  36. package/dist/types/index.d.ts +3 -0
  37. package/dist/types/index.js +3 -0
  38. package/dist/{common/pay-order/types.d.ts → types/model.d.ts} +36 -13
  39. package/package.json +4 -4
  40. package/dist/common/model.d.ts +0 -15
  41. package/dist/common/pay-order/enums.js +0 -28
  42. package/dist/common/pay-order/index.d.ts +0 -4
  43. package/dist/common/pay-order/index.js +0 -4
  44. package/dist/common/pay-order/types.js +0 -1
  45. package/dist/utils/account.d.ts +0 -1
  46. package/dist/utils/account.js +0 -3
  47. package/dist/utils/format.d.ts +0 -1
  48. package/dist/utils/format.js +0 -3
  49. package/dist/utils/index.d.ts +0 -4
  50. package/dist/utils/index.js +0 -4
  51. /package/dist/{utils → common}/browser.js +0 -0
  52. /package/dist/{utils → common}/plural.d.ts +0 -0
  53. /package/dist/{utils → common}/plural.js +0 -0
  54. /package/dist/{common/pay-order → types}/events.js +0 -0
  55. /package/dist/{common → types}/model.js +0 -0
@@ -1,4 +1,4 @@
1
- import { type CurrencyWithBalance, type PayOrder, PayOrderMode } from "../common/index";
1
+ import { type PayOrder, PayOrderMode } from "../types";
2
2
  import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams, QuoteWithBalance, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, UpdateWebhookRequest, WebhookResponse } from "../types/api";
3
3
  import { type APIEnvironment } from "./config";
4
4
  import { type APIResponse } from "./fetcher";
@@ -140,7 +140,7 @@ export declare class ApiClient {
140
140
  *
141
141
  * @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested.
142
142
  * @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, `chain_id`.
143
- * @returns {Promise<APIResponse<CurrencyWithBalance[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
143
+ * @returns {Promise<APIResponse<QuoteWithBalance[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
144
144
  *
145
145
  * @example
146
146
  * const orderId = 'existingOrderId';
@@ -155,7 +155,7 @@ export declare class ApiClient {
155
155
  * console.log('Available tokens:', response.data);
156
156
  * }
157
157
  */
158
- payOrderQuote(orderId: string, quoteParams: PayOrderQuoteParams): Promise<APIResponse<CurrencyWithBalance[]>>;
158
+ payOrderQuote(orderId: string, quoteParams: PayOrderQuoteParams): Promise<APIResponse<QuoteWithBalance[]>>;
159
159
  /**
160
160
  * Retrieves payment details for a specific PayOrder.
161
161
  *
@@ -1,5 +1,6 @@
1
1
  import { createHmac } from "crypto";
2
- import { now, PayOrderMode, zPayOrder, zPayOrderMetadata, } from "../common/index";
2
+ import { now, zPayOrder, zPayOrderMetadata } from "../common";
3
+ import { PayOrderMode } from "../types";
3
4
  import { fetchApi } from "./fetcher";
4
5
  export class ApiClient {
5
6
  constructor({ apiKey, sessionId, environment = "production", version, }) {
@@ -217,7 +218,7 @@ export class ApiClient {
217
218
  *
218
219
  * @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested.
219
220
  * @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, `chain_id`.
220
- * @returns {Promise<APIResponse<CurrencyWithBalance[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
221
+ * @returns {Promise<APIResponse<QuoteWithBalance[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
221
222
  *
222
223
  * @example
223
224
  * const orderId = 'existingOrderId';
@@ -21,7 +21,18 @@ export async function fetchApi(opts) {
21
21
  },
22
22
  };
23
23
  }
24
- const data = await response.json();
24
+ if (response.status === 204 || response.status === 205) {
25
+ return { data: undefined };
26
+ }
27
+ const contentLength = response.headers.get("content-length");
28
+ if (contentLength === "0") {
29
+ return { data: undefined };
30
+ }
31
+ const text = await response.text();
32
+ if (!text) {
33
+ return { data: undefined };
34
+ }
35
+ const data = JSON.parse(text);
25
36
  return { data };
26
37
  }
27
38
  catch (error) {
@@ -1,4 +1,4 @@
1
- import { ChainId } from "./chains";
1
+ import { ChainId } from "../types/enums";
2
2
  export declare const isBitcoinAddress: (address: string) => boolean;
3
3
  export declare const isEthereumAddress: (addr: string) => boolean;
4
4
  export declare const isSolanaAddress: (addr: string) => boolean;
@@ -1,4 +1,4 @@
1
- import { ChainId } from "./chains";
1
+ import { ChainId } from "../types/enums";
2
2
  const isBase58 = (str) => /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(str);
3
3
  const isBech32 = (str) => /^[qpzry9x8gf2tvdw0s3jn54khce6mua7l]+$/i.test(str.slice(3));
4
4
  export const isBitcoinAddress = (address) => {
@@ -1,4 +1,4 @@
1
- declare const detectBrowser: () => "" | import("detect-browser").Browser | "bot" | "node" | "react-native";
1
+ declare const detectBrowser: () => import("detect-browser").Browser | "bot" | "node" | "react-native" | "";
2
2
  declare const detectOS: () => "" | import("detect-browser").OperatingSystem | NodeJS.Platform;
3
3
  declare const isIOS: () => boolean;
4
4
  declare const isAndroid: () => boolean;
@@ -1,3 +1,3 @@
1
- import { ChainId } from "./chains";
1
+ import { ChainId } from "../types/enums";
2
2
  export declare function getChainExplorerTxUrl(chainId: ChainId, txHash?: string): string;
3
3
  export declare function getChainExplorerAddressUrl(chainId: ChainId, address?: string): string;
@@ -1,4 +1,4 @@
1
- import { ChainId } from "./chains";
1
+ import { ChainId } from "../types/enums";
2
2
  const chainExplorerUrls = {
3
3
  [ChainId.ETH]: "https://etherscan.io",
4
4
  [ChainId.ARB]: "https://arbiscan.io",
@@ -1,31 +1,4 @@
1
- export declare enum ChainType {
2
- EVM = "EVM",
3
- SOL = "SOL",
4
- SUI = "SUI",
5
- TRON = "TRON",
6
- UTXO = "UTXO"
7
- }
1
+ import { ChainId, ChainType } from "../types/enums";
8
2
  export declare function getChainTypeName(chainType?: ChainType): string;
9
- export declare enum ChainId {
10
- ETH = 1,
11
- OP = 10,
12
- BSC = 56,
13
- POL = 137,
14
- FTM = 250,
15
- ZKSYNC = 324,
16
- STABLE_TESTNET = 2201,
17
- BASE = 8453,
18
- ARB = 42161,
19
- AVAX = 43114,
20
- BLAST = 81457,
21
- SEPOLIA = 11155111,
22
- SEPOLIA_BASE = 84532,
23
- SEPOLIA_ARB = 421614,
24
- SEPOLIA_OP = 11155420,
25
- BTC = 20000000000001,
26
- SOL = 30000000000001,
27
- SUI = 30000000000002,
28
- TRX = 30000000000003
29
- }
30
3
  export declare function getChainTypeByChainId(chainId?: ChainId): ChainType;
31
4
  export declare function getChainName(chainId?: ChainId): string | undefined;
@@ -1,12 +1,4 @@
1
- export var ChainType;
2
- (function (ChainType) {
3
- ChainType["EVM"] = "EVM";
4
- ChainType["SOL"] = "SOL";
5
- ChainType["SUI"] = "SUI";
6
- ChainType["TRON"] = "TRON";
7
- // (e.g. Bitcoin, Litecoin, Dogecoin)
8
- ChainType["UTXO"] = "UTXO";
9
- })(ChainType || (ChainType = {}));
1
+ import { ChainId, ChainType } from "../types/enums";
10
2
  export function getChainTypeName(chainType) {
11
3
  switch (chainType) {
12
4
  case ChainType.EVM:
@@ -23,35 +15,6 @@ export function getChainTypeName(chainType) {
23
15
  return "";
24
16
  }
25
17
  }
26
- export var ChainId;
27
- (function (ChainId) {
28
- ChainId[ChainId["ETH"] = 1] = "ETH";
29
- ChainId[ChainId["OP"] = 10] = "OP";
30
- ChainId[ChainId["BSC"] = 56] = "BSC";
31
- ChainId[ChainId["POL"] = 137] = "POL";
32
- ChainId[ChainId["FTM"] = 250] = "FTM";
33
- ChainId[ChainId["ZKSYNC"] = 324] = "ZKSYNC";
34
- ChainId[ChainId["STABLE_TESTNET"] = 2201] = "STABLE_TESTNET";
35
- ChainId[ChainId["BASE"] = 8453] = "BASE";
36
- ChainId[ChainId["ARB"] = 42161] = "ARB";
37
- ChainId[ChainId["AVAX"] = 43114] = "AVAX";
38
- ChainId[ChainId["BLAST"] = 81457] = "BLAST";
39
- // testnet
40
- ChainId[ChainId["SEPOLIA"] = 11155111] = "SEPOLIA";
41
- ChainId[ChainId["SEPOLIA_BASE"] = 84532] = "SEPOLIA_BASE";
42
- ChainId[ChainId["SEPOLIA_ARB"] = 421614] = "SEPOLIA_ARB";
43
- ChainId[ChainId["SEPOLIA_OP"] = 11155420] = "SEPOLIA_OP";
44
- // UTXO (IDs are made up)
45
- ChainId[ChainId["BTC"] = 20000000000001] = "BTC";
46
- // BCH = 20000000000002,
47
- // LTC = 20000000000003,
48
- // DGE = 20000000000004,
49
- // None-EVM (IDs are made up)
50
- ChainId[ChainId["SOL"] = 30000000000001] = "SOL";
51
- ChainId[ChainId["SUI"] = 30000000000002] = "SUI";
52
- ChainId[ChainId["TRX"] = 30000000000003] = "TRX";
53
- // XRPL = 30000000000004,
54
- })(ChainId || (ChainId = {}));
55
18
  export function getChainTypeByChainId(chainId) {
56
19
  switch (chainId) {
57
20
  case ChainId.ETH:
@@ -0,0 +1,4 @@
1
+ export declare function capitalize(str: string): string;
2
+ export declare function truncateAddress(address?: string, length?: number): string;
3
+ export declare function truncateENSName(ensName: string, maxLength: number): string;
4
+ export declare function nFormatter(num: number, digits?: number): string;
@@ -0,0 +1,35 @@
1
+ export function capitalize(str) {
2
+ return str.charAt(0).toUpperCase() + str.slice(1);
3
+ }
4
+ export function truncateAddress(address, length = 4) {
5
+ if (!address) {
6
+ return "";
7
+ }
8
+ return address.slice(0, 2 + length) + "••••" + address.slice(-length);
9
+ }
10
+ export function truncateENSName(ensName, maxLength) {
11
+ if (ensName.length > maxLength) {
12
+ return `${ensName.replace(".eth", "").slice(0, maxLength)}...`;
13
+ }
14
+ return ensName;
15
+ }
16
+ export function nFormatter(num, digits = 2) {
17
+ if (num < 10000) {
18
+ return num.toFixed(2);
19
+ }
20
+ const lookup = [
21
+ { value: 1, symbol: "" },
22
+ { value: 1e3, symbol: "k" },
23
+ { value: 1e6, symbol: "m" },
24
+ { value: 1e9, symbol: "g" },
25
+ { value: 1e12, symbol: "t" },
26
+ { value: 1e15, symbol: "p" },
27
+ { value: 1e18, symbol: "e" },
28
+ ];
29
+ const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
30
+ const item = lookup
31
+ .slice()
32
+ .reverse()
33
+ .find((item) => num >= item.value);
34
+ return item ? (num / item.value).toFixed(digits).replace(rx, "$1") + item.symbol : "0";
35
+ }
@@ -1,11 +1,13 @@
1
1
  export * from "./address";
2
2
  export * from "./assert";
3
+ export * from "./browser";
3
4
  export * from "./chain-explorer";
4
5
  export * from "./chains";
5
6
  export * from "./currencies";
6
7
  export * from "./debug";
8
+ export * from "./format";
7
9
  export * from "./local-storage";
8
- export * from "./model";
9
10
  export * from "./organization";
10
- export * from "./pay-order";
11
+ export * from "./plural";
11
12
  export * from "./time";
13
+ export * from "./validation";
@@ -1,11 +1,13 @@
1
1
  export * from "./address";
2
2
  export * from "./assert";
3
+ export * from "./browser";
3
4
  export * from "./chain-explorer";
4
5
  export * from "./chains";
5
6
  export * from "./currencies";
6
7
  export * from "./debug";
8
+ export * from "./format";
7
9
  export * from "./local-storage";
8
- export * from "./model";
9
10
  export * from "./organization";
10
- export * from "./pay-order";
11
+ export * from "./plural";
11
12
  export * from "./time";
13
+ export * from "./validation";
@@ -1,4 +1,4 @@
1
- import { Currency } from "./model";
1
+ import { Currency } from "../types/model";
2
2
  export type SettlementCurrency = {
3
3
  receiving_address: string;
4
4
  } & Currency;
@@ -10,3 +10,4 @@ export declare function daysUntil(untilS: number, nowS?: number, long?: boolean)
10
10
  export declare function timeString(s: number): string;
11
11
  /** Returns eg "Aug 2023" */
12
12
  export declare function timeMonth(s: number): string;
13
+ export declare function formatTime(sec: number): string;
@@ -65,3 +65,9 @@ export function timeMonth(s) {
65
65
  year: "numeric",
66
66
  });
67
67
  }
68
+ export function formatTime(sec) {
69
+ const total = Math.max(0, Math.floor(sec));
70
+ const minutes = Math.floor(total / 60);
71
+ const seconds = total % 60;
72
+ return `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
73
+ }
@@ -301,14 +301,3 @@ export declare const zPayOrder: z.ZodObject<{
301
301
  receiving_address: z.ZodOptional<z.ZodString>;
302
302
  }, z.core.$strip>;
303
303
  }, z.core.$strip>;
304
- export type PayOrderMetadata = z.infer<typeof zPayOrderMetadata> & {
305
- [key: string]: string | number | boolean | any[] | {
306
- [x: string]: any;
307
- };
308
- };
309
- export type PayOrderMetadataInput = {
310
- items?: z.input<typeof zPayOrderMetadata.shape.items>;
311
- refund?: z.input<typeof zPayOrderMetadata.shape.refund>;
312
- } & Record<string, string | number | boolean | any[] | {
313
- [x: string]: any;
314
- }>;
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
- import { isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSuiAddress, isTronAddress } from "../address";
3
- import { ChainId } from "../chains";
4
- import { FIAT_CURRENCIES } from "../currencies";
2
+ import { isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSuiAddress, isTronAddress } from "./address";
3
+ import { ChainId } from "../types/enums";
4
+ import { FIAT_CURRENCIES } from "./currencies";
5
5
  const knownKeys = ["items", "refund"];
6
6
  const customFieldSchema = z
7
7
  .union([z.string(), z.number(), z.boolean(), z.array(z.any()), z.object(z.any())])
@@ -1 +1,5 @@
1
- export { useIsMobile } from "./use-is-mobile";
1
+ export { default as FocusTrap } from "./use-focus-trap";
2
+ export { default as useIsClient } from "./use-is-client";
3
+ export { default as useIsMobile } from "./use-is-mobile";
4
+ export { default as usePrevious } from "./use-previous";
5
+ export { default as useWindowSize } from "./use-window-size";
@@ -1 +1,5 @@
1
- export { useIsMobile } from "./use-is-mobile";
1
+ export { default as FocusTrap } from "./use-focus-trap";
2
+ export { default as useIsClient } from "./use-is-client";
3
+ export { default as useIsMobile } from "./use-is-mobile";
4
+ export { default as usePrevious } from "./use-previous";
5
+ export { default as useWindowSize } from "./use-window-size";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Component that traps focus within its children.
3
+ */
4
+ interface FocusTrapProps {
5
+ children: React.ReactNode;
6
+ className?: string;
7
+ }
8
+ export default function FocusTrap({ children, className }: FocusTrapProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useCallback } from "react";
3
+ const KEYCODE_TAB = 9;
4
+ function useFocusTrap() {
5
+ const elRef = useRef(null);
6
+ const handleFocus = useCallback((e) => {
7
+ if (!elRef.current)
8
+ return;
9
+ const focusableEls = elRef.current.querySelectorAll(`
10
+ a[href]:not(:disabled),
11
+ button:not(:disabled),
12
+ textarea:not(:disabled),
13
+ input[type="text"]:not(:disabled),
14
+ input[type="radio"]:not(:disabled),
15
+ input[type="checkbox"]:not(:disabled),
16
+ select:not(:disabled)
17
+ `);
18
+ const firstFocusableEl = focusableEls[0];
19
+ const lastFocusableEl = focusableEls[focusableEls.length - 1];
20
+ const isTabPressed = e.key === "Tab" || e.keyCode === KEYCODE_TAB;
21
+ if (!isTabPressed)
22
+ return;
23
+ if (e.shiftKey) {
24
+ // shift + tab
25
+ if (document.activeElement === firstFocusableEl) {
26
+ lastFocusableEl?.focus();
27
+ e.preventDefault();
28
+ }
29
+ }
30
+ else {
31
+ // tab
32
+ if (document.activeElement === lastFocusableEl) {
33
+ firstFocusableEl?.focus();
34
+ e.preventDefault();
35
+ }
36
+ }
37
+ }, []);
38
+ useEffect(() => {
39
+ const el = elRef.current;
40
+ if (!el)
41
+ return;
42
+ el.focus({ preventScroll: true });
43
+ el.addEventListener("keydown", handleFocus);
44
+ return () => {
45
+ el.removeEventListener("keydown", handleFocus);
46
+ };
47
+ }, [handleFocus]);
48
+ return elRef;
49
+ }
50
+ export default function FocusTrap({ children, className }) {
51
+ const elRef = useFocusTrap();
52
+ return (_jsx("div", { ref: elRef, tabIndex: -1, className: className, children: children }));
53
+ }
@@ -0,0 +1 @@
1
+ export default function useIsClient(): boolean;
@@ -0,0 +1,5 @@
1
+ import { useSyncExternalStore } from "react";
2
+ const emptySubscribe = () => () => { };
3
+ export default function useIsClient() {
4
+ return useSyncExternalStore(emptySubscribe, () => true, () => false);
5
+ }
@@ -1 +1 @@
1
- export declare function useIsMobile(): boolean;
1
+ export default function useIsMobile(): boolean;
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from "react";
2
- import { isMobile } from "../utils/browser";
3
- export function useIsMobile() {
2
+ import { isMobile } from "../common/browser";
3
+ export default function useIsMobile() {
4
4
  const [mobile, setMobile] = useState(isMobile());
5
5
  useEffect(() => {
6
6
  const handleResize = () => {
@@ -0,0 +1 @@
1
+ export default function usePrevious<T>(value: T, initial: T): T;
@@ -0,0 +1,8 @@
1
+ import { useState } from "react";
2
+ export default function usePrevious(value, initial) {
3
+ const [[previous, current], setState] = useState([initial, value]);
4
+ if (value !== current) {
5
+ setState([current, value]);
6
+ }
7
+ return previous;
8
+ }
@@ -0,0 +1,4 @@
1
+ export default function useWindowSize(): {
2
+ width: number;
3
+ height: number;
4
+ };
@@ -0,0 +1,19 @@
1
+ import { useEffect, useState } from "react";
2
+ export default function useWindowSize() {
3
+ const [windowSize, setWindowSize] = useState({
4
+ width: 0,
5
+ height: 0,
6
+ });
7
+ useEffect(() => {
8
+ function handleResize() {
9
+ setWindowSize({
10
+ width: window.innerWidth,
11
+ height: window.innerHeight,
12
+ });
13
+ }
14
+ window.addEventListener("resize", handleResize);
15
+ handleResize();
16
+ return () => window.removeEventListener("resize", handleResize);
17
+ }, []);
18
+ return windowSize;
19
+ }
@@ -1,4 +1,6 @@
1
- import { ChainId, ChainType, Currency, CurrencyAmount, CurrencyBase, CurrencyWithAmount, FiatCurrency, PaymentData, PayOrderMetadataInput, PayOrderStatus, QuoteWithCurrency } from "../common";
1
+ import { FiatCurrency } from "../common/currencies";
2
+ import { ChainId, ChainType, PayOrderStatus } from "./enums";
3
+ import { Currency, CurrencyAmount, CurrencyBase, CurrencyWithAmount, PaymentData, PayOrderMetadataInput, QuoteWithCurrency } from "./model";
2
4
  export type PayOrderParams = {
3
5
  /**
4
6
  * Intent of the order.
@@ -1,3 +1,31 @@
1
+ export declare enum ChainType {
2
+ EVM = "EVM",
3
+ SOL = "SOL",
4
+ SUI = "SUI",
5
+ TRON = "TRON",
6
+ UTXO = "UTXO"
7
+ }
8
+ export declare enum ChainId {
9
+ ETH = 1,
10
+ OP = 10,
11
+ BSC = 56,
12
+ POL = 137,
13
+ FTM = 250,
14
+ ZKSYNC = 324,
15
+ STABLE_TESTNET = 2201,
16
+ BASE = 8453,
17
+ ARB = 42161,
18
+ AVAX = 43114,
19
+ BLAST = 81457,
20
+ SEPOLIA = 11155111,
21
+ SEPOLIA_BASE = 84532,
22
+ SEPOLIA_ARB = 421614,
23
+ SEPOLIA_OP = 11155420,
24
+ BTC = 20000000000001,
25
+ SOL = 30000000000001,
26
+ SUI = 30000000000002,
27
+ TRX = 30000000000003
28
+ }
1
29
  export declare enum PayOrderMode {
2
30
  SALE = "SALE",
3
31
  DEPOSIT = "DEPOSIT",
@@ -0,0 +1,66 @@
1
+ export var ChainType;
2
+ (function (ChainType) {
3
+ ChainType["EVM"] = "EVM";
4
+ ChainType["SOL"] = "SOL";
5
+ ChainType["SUI"] = "SUI";
6
+ ChainType["TRON"] = "TRON";
7
+ // (e.g. Bitcoin, Litecoin, Dogecoin)
8
+ ChainType["UTXO"] = "UTXO";
9
+ })(ChainType || (ChainType = {}));
10
+ export var ChainId;
11
+ (function (ChainId) {
12
+ ChainId[ChainId["ETH"] = 1] = "ETH";
13
+ ChainId[ChainId["OP"] = 10] = "OP";
14
+ ChainId[ChainId["BSC"] = 56] = "BSC";
15
+ ChainId[ChainId["POL"] = 137] = "POL";
16
+ ChainId[ChainId["FTM"] = 250] = "FTM";
17
+ ChainId[ChainId["ZKSYNC"] = 324] = "ZKSYNC";
18
+ ChainId[ChainId["STABLE_TESTNET"] = 2201] = "STABLE_TESTNET";
19
+ ChainId[ChainId["BASE"] = 8453] = "BASE";
20
+ ChainId[ChainId["ARB"] = 42161] = "ARB";
21
+ ChainId[ChainId["AVAX"] = 43114] = "AVAX";
22
+ ChainId[ChainId["BLAST"] = 81457] = "BLAST";
23
+ // testnet
24
+ ChainId[ChainId["SEPOLIA"] = 11155111] = "SEPOLIA";
25
+ ChainId[ChainId["SEPOLIA_BASE"] = 84532] = "SEPOLIA_BASE";
26
+ ChainId[ChainId["SEPOLIA_ARB"] = 421614] = "SEPOLIA_ARB";
27
+ ChainId[ChainId["SEPOLIA_OP"] = 11155420] = "SEPOLIA_OP";
28
+ // UTXO (IDs are made up)
29
+ ChainId[ChainId["BTC"] = 20000000000001] = "BTC";
30
+ // BCH = 20000000000002,
31
+ // LTC = 20000000000003,
32
+ // DGE = 20000000000004,
33
+ // None-EVM (IDs are made up)
34
+ ChainId[ChainId["SOL"] = 30000000000001] = "SOL";
35
+ ChainId[ChainId["SUI"] = 30000000000002] = "SUI";
36
+ ChainId[ChainId["TRX"] = 30000000000003] = "TRX";
37
+ // XRPL = 30000000000004,
38
+ })(ChainId || (ChainId = {}));
39
+ export var PayOrderMode;
40
+ (function (PayOrderMode) {
41
+ PayOrderMode["SALE"] = "SALE";
42
+ PayOrderMode["DEPOSIT"] = "DEPOSIT";
43
+ PayOrderMode["REFUND"] = "REFUND";
44
+ })(PayOrderMode || (PayOrderMode = {}));
45
+ export var PayOrderStatus;
46
+ (function (PayOrderStatus) {
47
+ PayOrderStatus["PENDING"] = "PENDING";
48
+ PayOrderStatus["FAILED"] = "FAILED";
49
+ PayOrderStatus["AWAITING_PAYMENT"] = "AWAITING_PAYMENT";
50
+ PayOrderStatus["AWAITING_CONFIRMATION"] = "AWAITING_CONFIRMATION";
51
+ PayOrderStatus["OPTIMISTIC_CONFIRMED"] = "OPTIMISTIC_CONFIRMED";
52
+ PayOrderStatus["EXECUTING_ORDER"] = "EXECUTING_ORDER";
53
+ PayOrderStatus["COMPLETED"] = "COMPLETED";
54
+ PayOrderStatus["EXPIRED"] = "EXPIRED";
55
+ PayOrderStatus["REFUNDED"] = "REFUNDED";
56
+ })(PayOrderStatus || (PayOrderStatus = {}));
57
+ export var WebhookEventType;
58
+ (function (WebhookEventType) {
59
+ WebhookEventType["ORDER_CREATED"] = "ORDER_CREATED";
60
+ WebhookEventType["ORDER_AWAITING_PAYMENT"] = "ORDER_AWAITING_PAYMENT";
61
+ WebhookEventType["ORDER_CONFIRMING"] = "ORDER_CONFIRMING";
62
+ WebhookEventType["ORDER_EXECUTING"] = "ORDER_EXECUTING";
63
+ WebhookEventType["ORDER_COMPLETED"] = "ORDER_COMPLETED";
64
+ WebhookEventType["ORDER_ERROR"] = "ORDER_ERROR";
65
+ WebhookEventType["ORDER_REFUNDED"] = "ORDER_REFUNDED";
66
+ })(WebhookEventType || (WebhookEventType = {}));
@@ -1,6 +1,6 @@
1
- import { Hex } from "../../types/crypto";
2
- import { PaymentData } from "./types";
3
- import { PayOrderMetadata } from "./validation";
1
+ import { PayOrderMetadata } from "./model";
2
+ import { Hex } from "./crypto";
3
+ import { PaymentData } from "./model";
4
4
  export type PayOrderCreationErrorEvent = {
5
5
  type: "payorder_creation_error";
6
6
  errorMessage: string;
@@ -1,2 +1,5 @@
1
1
  export * from "./api";
2
2
  export * from "./crypto";
3
+ export * from "./enums";
4
+ export * from "./events";
5
+ export * from "./model";
@@ -1,2 +1,5 @@
1
1
  export * from "./api";
2
2
  export * from "./crypto";
3
+ export * from "./enums";
4
+ export * from "./events";
5
+ export * from "./model";
@@ -1,8 +1,8 @@
1
- import { FiatCurrency } from "../currencies";
2
- import { BigIntStr, Currency } from "../model";
3
- import { PayOrderMode, PayOrderStatus, ProviderStatus, WebhookEventType } from "./enums";
1
+ import { z } from "zod";
2
+ import { zPayOrderMetadata } from "../common";
3
+ import { FiatCurrency } from "../common/currencies";
4
+ import { ChainId, PayOrderMode, PayOrderStatus, ProviderStatus, WebhookEventType } from "./enums";
4
5
  import { PayOrderEvent } from "./events";
5
- import { PayOrderMetadata } from "./validation";
6
6
  export type PayOrder = {
7
7
  id: string;
8
8
  mode: PayOrderMode;
@@ -14,21 +14,38 @@ export type PayOrder = {
14
14
  fulfillment: FulfillmentData;
15
15
  payment?: PaymentData;
16
16
  };
17
- export interface CurrencyWithTokenFiatAmount extends Currency {
18
- currency_amount: {
19
- token: TokenAmount;
20
- fiat: FiatAmount;
17
+ export type PayOrderMetadata = z.infer<typeof zPayOrderMetadata> & {
18
+ [key: string]: string | number | boolean | any[] | {
19
+ [x: string]: any;
21
20
  };
21
+ };
22
+ export type PayOrderMetadataInput = {
23
+ items?: z.input<typeof zPayOrderMetadata.shape.items>;
24
+ refund?: z.input<typeof zPayOrderMetadata.shape.refund>;
25
+ } & Record<string, string | number | boolean | any[] | {
26
+ [x: string]: any;
27
+ }>;
28
+ export interface Currency extends CurrencyBase {
29
+ id?: string;
30
+ name: string;
31
+ ticker: string;
32
+ decimals: number;
33
+ image_uri?: string;
34
+ price_usd?: number;
22
35
  }
23
- export interface QuoteWithCurrency extends CurrencyWithAmount {
24
- total: CurrencyWithAmount;
25
- base: CurrencyWithAmount;
26
- fees?: CurrencyWithAmount;
27
- gas?: CurrencyWithAmount;
36
+ export interface CurrencyBase {
37
+ chain_id: ChainId;
38
+ address?: string;
28
39
  }
29
40
  export interface CurrencyWithAmount extends Currency {
30
41
  currency_amount: CurrencyAmount;
31
42
  }
43
+ export interface QuoteWithCurrency extends CurrencyWithAmount {
44
+ total: CurrencyAmount;
45
+ base: CurrencyAmount;
46
+ fees?: FeeBreakdown;
47
+ gas?: CurrencyAmount;
48
+ }
32
49
  export interface CurrencyWithBalance extends CurrencyWithAmount {
33
50
  balance?: CurrencyAmount;
34
51
  }
@@ -38,6 +55,11 @@ export interface CurrencyAmount {
38
55
  raw_amount: BigIntStr;
39
56
  value_usd: number;
40
57
  }
58
+ export interface FeeBreakdown {
59
+ total_fee: CurrencyAmount;
60
+ protocol_fee?: CurrencyAmount;
61
+ custom_fee?: CurrencyAmount;
62
+ }
41
63
  export type TokenAmount = {
42
64
  ui_amount: number;
43
65
  raw_amount: BigIntStr;
@@ -120,3 +142,4 @@ export interface WebhookDelivery {
120
142
  export interface FeePlan extends CurrencyWithAmount {
121
143
  fee_bps?: number;
122
144
  }
145
+ export type BigIntStr = `${bigint}`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/shared",
3
3
  "description": "Shared utilities for Coin Voyage",
4
- "version": "2.2.1",
4
+ "version": "2.2.3",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -10,8 +10,8 @@
10
10
  "default": "./dist/common/chains.js"
11
11
  },
12
12
  "./types/*": {
13
- "types": "./dist/types/*.d.ts",
14
- "default": "./dist/types/*.js"
13
+ "types": "./dist/types/index.d.ts",
14
+ "default": "./dist/types/index.js"
15
15
  },
16
16
  "./*": {
17
17
  "types": "./dist/*/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "dist/common/chains.d.ts"
28
28
  ],
29
29
  "types/*": [
30
- "dist/types/*.d.ts"
30
+ "dist/types/index.d.ts"
31
31
  ],
32
32
  "*": [
33
33
  "dist/*/index.d.ts"
@@ -1,15 +0,0 @@
1
- import { ChainId } from "./chains";
2
- export interface Currency extends CurrencyBase {
3
- id?: string;
4
- name: string;
5
- ticker: string;
6
- decimals: number;
7
- image_uri?: string;
8
- price_usd?: number;
9
- }
10
- export interface CurrencyBase {
11
- chain_id: ChainId;
12
- address?: string;
13
- }
14
- export type BigIntStr = `${bigint}`;
15
- export type PlatformType = "ios" | "android" | "other";
@@ -1,28 +0,0 @@
1
- export var PayOrderMode;
2
- (function (PayOrderMode) {
3
- PayOrderMode["SALE"] = "SALE";
4
- PayOrderMode["DEPOSIT"] = "DEPOSIT";
5
- PayOrderMode["REFUND"] = "REFUND";
6
- })(PayOrderMode || (PayOrderMode = {}));
7
- export var PayOrderStatus;
8
- (function (PayOrderStatus) {
9
- PayOrderStatus["PENDING"] = "PENDING";
10
- PayOrderStatus["FAILED"] = "FAILED";
11
- PayOrderStatus["AWAITING_PAYMENT"] = "AWAITING_PAYMENT";
12
- PayOrderStatus["AWAITING_CONFIRMATION"] = "AWAITING_CONFIRMATION";
13
- PayOrderStatus["OPTIMISTIC_CONFIRMED"] = "OPTIMISTIC_CONFIRMED";
14
- PayOrderStatus["EXECUTING_ORDER"] = "EXECUTING_ORDER";
15
- PayOrderStatus["COMPLETED"] = "COMPLETED";
16
- PayOrderStatus["EXPIRED"] = "EXPIRED";
17
- PayOrderStatus["REFUNDED"] = "REFUNDED";
18
- })(PayOrderStatus || (PayOrderStatus = {}));
19
- export var WebhookEventType;
20
- (function (WebhookEventType) {
21
- WebhookEventType["ORDER_CREATED"] = "ORDER_CREATED";
22
- WebhookEventType["ORDER_AWAITING_PAYMENT"] = "ORDER_AWAITING_PAYMENT";
23
- WebhookEventType["ORDER_CONFIRMING"] = "ORDER_CONFIRMING";
24
- WebhookEventType["ORDER_EXECUTING"] = "ORDER_EXECUTING";
25
- WebhookEventType["ORDER_COMPLETED"] = "ORDER_COMPLETED";
26
- WebhookEventType["ORDER_ERROR"] = "ORDER_ERROR";
27
- WebhookEventType["ORDER_REFUNDED"] = "ORDER_REFUNDED";
28
- })(WebhookEventType || (WebhookEventType = {}));
@@ -1,4 +0,0 @@
1
- export * from "./enums";
2
- export * from "./events";
3
- export * from "./types";
4
- export * from "./validation";
@@ -1,4 +0,0 @@
1
- export * from "./enums";
2
- export * from "./events";
3
- export * from "./types";
4
- export * from "./validation";
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare function shortenAddress(address: string, length?: number): string;
@@ -1,3 +0,0 @@
1
- export function shortenAddress(address, length = 4) {
2
- return `${address.slice(0, 2 + length)}…${address.slice(-length)}`;
3
- }
@@ -1 +0,0 @@
1
- export declare function capitalize(str: string): string;
@@ -1,3 +0,0 @@
1
- export function capitalize(str) {
2
- return str.charAt(0).toUpperCase() + str.slice(1);
3
- }
@@ -1,4 +0,0 @@
1
- export * from "./account";
2
- export * from "./browser";
3
- export * from "./format";
4
- export * from "./plural";
@@ -1,4 +0,0 @@
1
- export * from "./account";
2
- export * from "./browser";
3
- export * from "./format";
4
- export * from "./plural";
File without changes
File without changes
File without changes
File without changes
File without changes