@one_deploy/sdk 1.0.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.
- package/.turbo/turbo-build.log +0 -0
- package/.turbo/turbo-type-check.log +0 -0
- package/dist/config/index.d.mts +74 -0
- package/dist/config/index.d.ts +74 -0
- package/dist/config/index.js +242 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/index.mjs +224 -0
- package/dist/config/index.mjs.map +1 -0
- package/dist/engine-5ndtBaCr.d.ts +1039 -0
- package/dist/engine-CrlhH0nw.d.mts +1039 -0
- package/dist/hooks/index.d.mts +56 -0
- package/dist/hooks/index.d.ts +56 -0
- package/dist/hooks/index.js +1360 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +1356 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/index.d.mts +356 -0
- package/dist/index.d.ts +356 -0
- package/dist/index.js +5068 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4949 -0
- package/dist/index.mjs.map +1 -0
- package/dist/price-CgqXPnT3.d.ts +13 -0
- package/dist/price-ClbLHHjv.d.mts +13 -0
- package/dist/providers/index.d.mts +121 -0
- package/dist/providers/index.d.ts +121 -0
- package/dist/providers/index.js +1642 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/index.mjs +1600 -0
- package/dist/providers/index.mjs.map +1 -0
- package/dist/react-native.d.mts +120 -0
- package/dist/react-native.d.ts +120 -0
- package/dist/react-native.js +1792 -0
- package/dist/react-native.js.map +1 -0
- package/dist/react-native.mjs +1755 -0
- package/dist/react-native.mjs.map +1 -0
- package/dist/services/index.d.mts +85 -0
- package/dist/services/index.d.ts +85 -0
- package/dist/services/index.js +1466 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/index.mjs +1458 -0
- package/dist/services/index.mjs.map +1 -0
- package/dist/types/index.d.mts +759 -0
- package/dist/types/index.d.ts +759 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +3 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/utils/index.d.mts +36 -0
- package/dist/utils/index.d.ts +36 -0
- package/dist/utils/index.js +164 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +142 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +101 -0
- package/src/components/OneConnectButton.tsx +143 -0
- package/src/components/OneNFTGallery.tsx +324 -0
- package/src/components/OneOfframpWidget.tsx +660 -0
- package/src/components/OneOnrampWidget.tsx +596 -0
- package/src/components/OnePayWidget.tsx +160 -0
- package/src/components/OneReceiveWidget.tsx +272 -0
- package/src/components/OneSendWidget.tsx +248 -0
- package/src/components/OneSwapWidget.tsx +715 -0
- package/src/components/OneTransactionButton.tsx +150 -0
- package/src/components/OneWalletBalance.tsx +354 -0
- package/src/components/index.ts +24 -0
- package/src/config/index.ts +299 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useTokenPrice.ts +162 -0
- package/src/hooks/useWalletBalance.ts +98 -0
- package/src/index.ts +193 -0
- package/src/providers/OneProvider.tsx +452 -0
- package/src/providers/ThirdwebProvider.tsx +203 -0
- package/src/providers/index.ts +26 -0
- package/src/react-native.ts +378 -0
- package/src/services/engine.ts +1854 -0
- package/src/services/index.ts +30 -0
- package/src/services/price.ts +164 -0
- package/src/services/supabase.ts +180 -0
- package/src/types/index.ts +887 -0
- package/src/utils/index.ts +200 -0
- package/tsconfig.json +22 -0
- package/tsup.config.ts +25 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare function shortenAddress(address: string, chars?: number): string;
|
|
2
|
+
declare function isValidAddress(address: string): boolean;
|
|
3
|
+
declare function checksumAddress(address: string): string;
|
|
4
|
+
declare function formatNumber(value: number, options?: {
|
|
5
|
+
decimals?: number;
|
|
6
|
+
compact?: boolean;
|
|
7
|
+
currency?: string;
|
|
8
|
+
locale?: string;
|
|
9
|
+
}): string;
|
|
10
|
+
declare function formatUSD(value: number, compact?: boolean): string;
|
|
11
|
+
declare function formatPercent(value: number, decimals?: number): string;
|
|
12
|
+
declare function formatTokenAmount(amount: number, decimals?: number): string;
|
|
13
|
+
declare function formatDate(date: string | Date, options?: Intl.DateTimeFormatOptions): string;
|
|
14
|
+
declare function formatDateTime(date: string | Date): string;
|
|
15
|
+
declare function formatRelativeTime(date: string | Date): string;
|
|
16
|
+
declare function isValidEmail(email: string): boolean;
|
|
17
|
+
declare function isValidPhone(phone: string): boolean;
|
|
18
|
+
declare function capitalize(str: string): string;
|
|
19
|
+
declare function truncate(str: string, length: number): string;
|
|
20
|
+
declare function slugify(str: string): string;
|
|
21
|
+
declare function sleep(ms: number): Promise<void>;
|
|
22
|
+
declare function retry<T>(fn: () => Promise<T>, options?: {
|
|
23
|
+
maxAttempts?: number;
|
|
24
|
+
delay?: number;
|
|
25
|
+
backoff?: number;
|
|
26
|
+
}): Promise<T>;
|
|
27
|
+
declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
28
|
+
declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
29
|
+
declare class OneSDKError extends Error {
|
|
30
|
+
code: string;
|
|
31
|
+
details?: any;
|
|
32
|
+
constructor(message: string, code: string, details?: any);
|
|
33
|
+
}
|
|
34
|
+
declare function isOneSDKError(error: unknown): error is OneSDKError;
|
|
35
|
+
|
|
36
|
+
export { OneSDKError, capitalize, checksumAddress, formatDate, formatDateTime, formatNumber, formatPercent, formatRelativeTime, formatTokenAmount, formatUSD, isOneSDKError, isValidAddress, isValidEmail, isValidPhone, omit, pick, retry, shortenAddress, sleep, slugify, truncate };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare function shortenAddress(address: string, chars?: number): string;
|
|
2
|
+
declare function isValidAddress(address: string): boolean;
|
|
3
|
+
declare function checksumAddress(address: string): string;
|
|
4
|
+
declare function formatNumber(value: number, options?: {
|
|
5
|
+
decimals?: number;
|
|
6
|
+
compact?: boolean;
|
|
7
|
+
currency?: string;
|
|
8
|
+
locale?: string;
|
|
9
|
+
}): string;
|
|
10
|
+
declare function formatUSD(value: number, compact?: boolean): string;
|
|
11
|
+
declare function formatPercent(value: number, decimals?: number): string;
|
|
12
|
+
declare function formatTokenAmount(amount: number, decimals?: number): string;
|
|
13
|
+
declare function formatDate(date: string | Date, options?: Intl.DateTimeFormatOptions): string;
|
|
14
|
+
declare function formatDateTime(date: string | Date): string;
|
|
15
|
+
declare function formatRelativeTime(date: string | Date): string;
|
|
16
|
+
declare function isValidEmail(email: string): boolean;
|
|
17
|
+
declare function isValidPhone(phone: string): boolean;
|
|
18
|
+
declare function capitalize(str: string): string;
|
|
19
|
+
declare function truncate(str: string, length: number): string;
|
|
20
|
+
declare function slugify(str: string): string;
|
|
21
|
+
declare function sleep(ms: number): Promise<void>;
|
|
22
|
+
declare function retry<T>(fn: () => Promise<T>, options?: {
|
|
23
|
+
maxAttempts?: number;
|
|
24
|
+
delay?: number;
|
|
25
|
+
backoff?: number;
|
|
26
|
+
}): Promise<T>;
|
|
27
|
+
declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
28
|
+
declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
29
|
+
declare class OneSDKError extends Error {
|
|
30
|
+
code: string;
|
|
31
|
+
details?: any;
|
|
32
|
+
constructor(message: string, code: string, details?: any);
|
|
33
|
+
}
|
|
34
|
+
declare function isOneSDKError(error: unknown): error is OneSDKError;
|
|
35
|
+
|
|
36
|
+
export { OneSDKError, capitalize, checksumAddress, formatDate, formatDateTime, formatNumber, formatPercent, formatRelativeTime, formatTokenAmount, formatUSD, isOneSDKError, isValidAddress, isValidEmail, isValidPhone, omit, pick, retry, shortenAddress, sleep, slugify, truncate };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/index.ts
|
|
4
|
+
function shortenAddress(address, chars = 4) {
|
|
5
|
+
if (!address) return "";
|
|
6
|
+
return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
|
|
7
|
+
}
|
|
8
|
+
function isValidAddress(address) {
|
|
9
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
10
|
+
}
|
|
11
|
+
function checksumAddress(address) {
|
|
12
|
+
return address.toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
function formatNumber(value, options = {}) {
|
|
15
|
+
const { decimals = 2, compact = false, currency, locale = "en-US" } = options;
|
|
16
|
+
if (currency) {
|
|
17
|
+
return new Intl.NumberFormat(locale, {
|
|
18
|
+
style: "currency",
|
|
19
|
+
currency,
|
|
20
|
+
minimumFractionDigits: decimals,
|
|
21
|
+
maximumFractionDigits: decimals,
|
|
22
|
+
notation: compact ? "compact" : "standard"
|
|
23
|
+
}).format(value);
|
|
24
|
+
}
|
|
25
|
+
return new Intl.NumberFormat(locale, {
|
|
26
|
+
minimumFractionDigits: decimals,
|
|
27
|
+
maximumFractionDigits: decimals,
|
|
28
|
+
notation: compact ? "compact" : "standard"
|
|
29
|
+
}).format(value);
|
|
30
|
+
}
|
|
31
|
+
function formatUSD(value, compact = false) {
|
|
32
|
+
return formatNumber(value, { currency: "USD", compact });
|
|
33
|
+
}
|
|
34
|
+
function formatPercent(value, decimals = 2) {
|
|
35
|
+
const sign = value >= 0 ? "+" : "";
|
|
36
|
+
return `${sign}${value.toFixed(decimals)}%`;
|
|
37
|
+
}
|
|
38
|
+
function formatTokenAmount(amount, decimals = 6) {
|
|
39
|
+
if (amount === 0) return "0";
|
|
40
|
+
if (amount < 1e-6) return "<0.000001";
|
|
41
|
+
if (amount < 1) return amount.toFixed(decimals);
|
|
42
|
+
if (amount < 1e3) return amount.toFixed(4);
|
|
43
|
+
if (amount < 1e6) return formatNumber(amount, { decimals: 2 });
|
|
44
|
+
return formatNumber(amount, { decimals: 2, compact: true });
|
|
45
|
+
}
|
|
46
|
+
function formatDate(date, options = {
|
|
47
|
+
year: "numeric",
|
|
48
|
+
month: "short",
|
|
49
|
+
day: "numeric"
|
|
50
|
+
}) {
|
|
51
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
52
|
+
return d.toLocaleDateString("en-US", options);
|
|
53
|
+
}
|
|
54
|
+
function formatDateTime(date) {
|
|
55
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
56
|
+
return d.toLocaleString("en-US", {
|
|
57
|
+
year: "numeric",
|
|
58
|
+
month: "short",
|
|
59
|
+
day: "numeric",
|
|
60
|
+
hour: "2-digit",
|
|
61
|
+
minute: "2-digit"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function formatRelativeTime(date) {
|
|
65
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
66
|
+
const now = /* @__PURE__ */ new Date();
|
|
67
|
+
const diffMs = now.getTime() - d.getTime();
|
|
68
|
+
const diffSec = Math.floor(diffMs / 1e3);
|
|
69
|
+
const diffMin = Math.floor(diffSec / 60);
|
|
70
|
+
const diffHour = Math.floor(diffMin / 60);
|
|
71
|
+
const diffDay = Math.floor(diffHour / 24);
|
|
72
|
+
if (diffSec < 60) return "just now";
|
|
73
|
+
if (diffMin < 60) return `${diffMin}m ago`;
|
|
74
|
+
if (diffHour < 24) return `${diffHour}h ago`;
|
|
75
|
+
if (diffDay < 7) return `${diffDay}d ago`;
|
|
76
|
+
return formatDate(d);
|
|
77
|
+
}
|
|
78
|
+
function isValidEmail(email) {
|
|
79
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
80
|
+
return emailRegex.test(email);
|
|
81
|
+
}
|
|
82
|
+
function isValidPhone(phone) {
|
|
83
|
+
const phoneRegex = /^\+?[1-9]\d{1,14}$/;
|
|
84
|
+
return phoneRegex.test(phone.replace(/[\s-()]/g, ""));
|
|
85
|
+
}
|
|
86
|
+
function capitalize(str) {
|
|
87
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
88
|
+
}
|
|
89
|
+
function truncate(str, length) {
|
|
90
|
+
if (str.length <= length) return str;
|
|
91
|
+
return `${str.slice(0, length)}...`;
|
|
92
|
+
}
|
|
93
|
+
function slugify(str) {
|
|
94
|
+
return str.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
95
|
+
}
|
|
96
|
+
function sleep(ms) {
|
|
97
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
98
|
+
}
|
|
99
|
+
async function retry(fn, options = {}) {
|
|
100
|
+
const { maxAttempts = 3, delay = 1e3, backoff = 2 } = options;
|
|
101
|
+
let lastError;
|
|
102
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
103
|
+
try {
|
|
104
|
+
return await fn();
|
|
105
|
+
} catch (error) {
|
|
106
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
107
|
+
if (attempt < maxAttempts) {
|
|
108
|
+
await sleep(delay * Math.pow(backoff, attempt - 1));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
throw lastError;
|
|
113
|
+
}
|
|
114
|
+
function omit(obj, keys) {
|
|
115
|
+
const result = { ...obj };
|
|
116
|
+
for (const key of keys) {
|
|
117
|
+
delete result[key];
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
function pick(obj, keys) {
|
|
122
|
+
const result = {};
|
|
123
|
+
for (const key of keys) {
|
|
124
|
+
if (key in obj) {
|
|
125
|
+
result[key] = obj[key];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
var OneSDKError = class extends Error {
|
|
131
|
+
constructor(message, code, details) {
|
|
132
|
+
super(message);
|
|
133
|
+
this.name = "OneSDKError";
|
|
134
|
+
this.code = code;
|
|
135
|
+
this.details = details;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
function isOneSDKError(error) {
|
|
139
|
+
return error instanceof OneSDKError;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
exports.OneSDKError = OneSDKError;
|
|
143
|
+
exports.capitalize = capitalize;
|
|
144
|
+
exports.checksumAddress = checksumAddress;
|
|
145
|
+
exports.formatDate = formatDate;
|
|
146
|
+
exports.formatDateTime = formatDateTime;
|
|
147
|
+
exports.formatNumber = formatNumber;
|
|
148
|
+
exports.formatPercent = formatPercent;
|
|
149
|
+
exports.formatRelativeTime = formatRelativeTime;
|
|
150
|
+
exports.formatTokenAmount = formatTokenAmount;
|
|
151
|
+
exports.formatUSD = formatUSD;
|
|
152
|
+
exports.isOneSDKError = isOneSDKError;
|
|
153
|
+
exports.isValidAddress = isValidAddress;
|
|
154
|
+
exports.isValidEmail = isValidEmail;
|
|
155
|
+
exports.isValidPhone = isValidPhone;
|
|
156
|
+
exports.omit = omit;
|
|
157
|
+
exports.pick = pick;
|
|
158
|
+
exports.retry = retry;
|
|
159
|
+
exports.shortenAddress = shortenAddress;
|
|
160
|
+
exports.sleep = sleep;
|
|
161
|
+
exports.slugify = slugify;
|
|
162
|
+
exports.truncate = truncate;
|
|
163
|
+
//# sourceMappingURL=index.js.map
|
|
164
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AACO,SAAS,cAAA,CAAe,OAAA,EAAiB,KAAA,GAAQ,CAAA,EAAW;AACjE,EAAA,IAAI,CAAC,SAAS,OAAO,EAAA;AACrB,EAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,KAAA,GAAQ,CAAC,CAAC,CAAA,GAAA,EAAM,OAAA,CAAQ,KAAA,CAAM,CAAC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AAM,SAAA;AACR;AAGO,SAAS,IAAA,CACd,KACA,IAAA,EACY;AACZ,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,GAAA,EAAI;AACxB,EAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACtB,IAAA,OAAO,OAAO,GAAG,CAAA;AAAA,EACnB;AACA,EAAA,OAAO,MAAA;AACT;AAEO,SAAS,IAAA,CACd,KACA,IAAA,EACY;AACZ,EAAA,MAAM,SAAS,EAAC;AAChB,EAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACtB,IAAA,IAAI,OAAO,GAAA,EAAK;AACd,MAAA,MAAA,CAAO,GAAG,CAAA,GAAI,GAAA,CAAI,GAAG,CAAA;AAAA,IACvB;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAGO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EAIrC,WAAA,CAAY,OAAA,EAAiB,IAAA,EAAc,OAAA,EAAe;AACxD,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AACF;AAEO,SAAS,cAAc,KAAA,EAAsC;AAClE,EAAA,OAAO,KAAA,YAAiB,WAAA;AAC1B","file":"index.js","sourcesContent":["// ===== Address Utilities =====\nexport function shortenAddress(address: string, chars = 4): string {\n if (!address) return '';\n return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;\n}\n\nexport function isValidAddress(address: string): boolean {\n return /^0x[a-fA-F0-9]{40}$/.test(address);\n}\n\nexport function checksumAddress(address: string): string {\n // Basic checksum - for proper checksum use ethers/viem\n return address.toLowerCase();\n}\n\n// ===== Number Formatting =====\nexport function formatNumber(\n value: number,\n options: {\n decimals?: number;\n compact?: boolean;\n currency?: string;\n locale?: string;\n } = {}\n): string {\n const { decimals = 2, compact = false, currency, locale = 'en-US' } = options;\n\n if (currency) {\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency,\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n notation: compact ? 'compact' : 'standard',\n }).format(value);\n }\n\n return new Intl.NumberFormat(locale, {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n notation: compact ? 'compact' : 'standard',\n }).format(value);\n}\n\nexport function formatUSD(value: number, compact = false): string {\n return formatNumber(value, { currency: 'USD', compact });\n}\n\nexport function formatPercent(value: number, decimals = 2): string {\n const sign = value >= 0 ? '+' : '';\n return `${sign}${value.toFixed(decimals)}%`;\n}\n\nexport function formatTokenAmount(amount: number, decimals = 6): string {\n if (amount === 0) return '0';\n if (amount < 0.000001) return '<0.000001';\n if (amount < 1) return amount.toFixed(decimals);\n if (amount < 1000) return amount.toFixed(4);\n if (amount < 1000000) return formatNumber(amount, { decimals: 2 });\n return formatNumber(amount, { decimals: 2, compact: true });\n}\n\n// ===== Date & Time Utilities =====\nexport function formatDate(\n date: string | Date,\n options: Intl.DateTimeFormatOptions = {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n }\n): string {\n const d = typeof date === 'string' ? new Date(date) : date;\n return d.toLocaleDateString('en-US', options);\n}\n\nexport function formatDateTime(date: string | Date): string {\n const d = typeof date === 'string' ? new Date(date) : date;\n return d.toLocaleString('en-US', {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: '2-digit',\n minute: '2-digit',\n });\n}\n\nexport function formatRelativeTime(date: string | Date): string {\n const d = typeof date === 'string' ? new Date(date) : date;\n const now = new Date();\n const diffMs = now.getTime() - d.getTime();\n const diffSec = Math.floor(diffMs / 1000);\n const diffMin = Math.floor(diffSec / 60);\n const diffHour = Math.floor(diffMin / 60);\n const diffDay = Math.floor(diffHour / 24);\n\n if (diffSec < 60) return 'just now';\n if (diffMin < 60) return `${diffMin}m ago`;\n if (diffHour < 24) return `${diffHour}h ago`;\n if (diffDay < 7) return `${diffDay}d ago`;\n\n return formatDate(d);\n}\n\n// ===== Validation Utilities =====\nexport function isValidEmail(email: string): boolean {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n return emailRegex.test(email);\n}\n\nexport function isValidPhone(phone: string): boolean {\n const phoneRegex = /^\\+?[1-9]\\d{1,14}$/;\n return phoneRegex.test(phone.replace(/[\\s-()]/g, ''));\n}\n\n// ===== String Utilities =====\nexport function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();\n}\n\nexport function truncate(str: string, length: number): string {\n if (str.length <= length) return str;\n return `${str.slice(0, length)}...`;\n}\n\nexport function slugify(str: string): string {\n return str\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/(^-|-$)/g, '');\n}\n\n// ===== Async Utilities =====\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport async function retry<T>(\n fn: () => Promise<T>,\n options: { maxAttempts?: number; delay?: number; backoff?: number } = {}\n): Promise<T> {\n const { maxAttempts = 3, delay = 1000, backoff = 2 } = options;\n\n let lastError: Error | undefined;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await fn();\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n\n if (attempt < maxAttempts) {\n await sleep(delay * Math.pow(backoff, attempt - 1));\n }\n }\n }\n\n throw lastError;\n}\n\n// ===== Object Utilities =====\nexport function omit<T extends Record<string, any>, K extends keyof T>(\n obj: T,\n keys: K[]\n): Omit<T, K> {\n const result = { ...obj };\n for (const key of keys) {\n delete result[key];\n }\n return result;\n}\n\nexport function pick<T extends Record<string, any>, K extends keyof T>(\n obj: T,\n keys: K[]\n): Pick<T, K> {\n const result = {} as Pick<T, K>;\n for (const key of keys) {\n if (key in obj) {\n result[key] = obj[key];\n }\n }\n return result;\n}\n\n// ===== Error Handling =====\nexport class OneSDKError extends Error {\n code: string;\n details?: any;\n\n constructor(message: string, code: string, details?: any) {\n super(message);\n this.name = 'OneSDKError';\n this.code = code;\n this.details = details;\n }\n}\n\nexport function isOneSDKError(error: unknown): error is OneSDKError {\n return error instanceof OneSDKError;\n}\n"]}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// src/utils/index.ts
|
|
2
|
+
function shortenAddress(address, chars = 4) {
|
|
3
|
+
if (!address) return "";
|
|
4
|
+
return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
|
|
5
|
+
}
|
|
6
|
+
function isValidAddress(address) {
|
|
7
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
8
|
+
}
|
|
9
|
+
function checksumAddress(address) {
|
|
10
|
+
return address.toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
function formatNumber(value, options = {}) {
|
|
13
|
+
const { decimals = 2, compact = false, currency, locale = "en-US" } = options;
|
|
14
|
+
if (currency) {
|
|
15
|
+
return new Intl.NumberFormat(locale, {
|
|
16
|
+
style: "currency",
|
|
17
|
+
currency,
|
|
18
|
+
minimumFractionDigits: decimals,
|
|
19
|
+
maximumFractionDigits: decimals,
|
|
20
|
+
notation: compact ? "compact" : "standard"
|
|
21
|
+
}).format(value);
|
|
22
|
+
}
|
|
23
|
+
return new Intl.NumberFormat(locale, {
|
|
24
|
+
minimumFractionDigits: decimals,
|
|
25
|
+
maximumFractionDigits: decimals,
|
|
26
|
+
notation: compact ? "compact" : "standard"
|
|
27
|
+
}).format(value);
|
|
28
|
+
}
|
|
29
|
+
function formatUSD(value, compact = false) {
|
|
30
|
+
return formatNumber(value, { currency: "USD", compact });
|
|
31
|
+
}
|
|
32
|
+
function formatPercent(value, decimals = 2) {
|
|
33
|
+
const sign = value >= 0 ? "+" : "";
|
|
34
|
+
return `${sign}${value.toFixed(decimals)}%`;
|
|
35
|
+
}
|
|
36
|
+
function formatTokenAmount(amount, decimals = 6) {
|
|
37
|
+
if (amount === 0) return "0";
|
|
38
|
+
if (amount < 1e-6) return "<0.000001";
|
|
39
|
+
if (amount < 1) return amount.toFixed(decimals);
|
|
40
|
+
if (amount < 1e3) return amount.toFixed(4);
|
|
41
|
+
if (amount < 1e6) return formatNumber(amount, { decimals: 2 });
|
|
42
|
+
return formatNumber(amount, { decimals: 2, compact: true });
|
|
43
|
+
}
|
|
44
|
+
function formatDate(date, options = {
|
|
45
|
+
year: "numeric",
|
|
46
|
+
month: "short",
|
|
47
|
+
day: "numeric"
|
|
48
|
+
}) {
|
|
49
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
50
|
+
return d.toLocaleDateString("en-US", options);
|
|
51
|
+
}
|
|
52
|
+
function formatDateTime(date) {
|
|
53
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
54
|
+
return d.toLocaleString("en-US", {
|
|
55
|
+
year: "numeric",
|
|
56
|
+
month: "short",
|
|
57
|
+
day: "numeric",
|
|
58
|
+
hour: "2-digit",
|
|
59
|
+
minute: "2-digit"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function formatRelativeTime(date) {
|
|
63
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
64
|
+
const now = /* @__PURE__ */ new Date();
|
|
65
|
+
const diffMs = now.getTime() - d.getTime();
|
|
66
|
+
const diffSec = Math.floor(diffMs / 1e3);
|
|
67
|
+
const diffMin = Math.floor(diffSec / 60);
|
|
68
|
+
const diffHour = Math.floor(diffMin / 60);
|
|
69
|
+
const diffDay = Math.floor(diffHour / 24);
|
|
70
|
+
if (diffSec < 60) return "just now";
|
|
71
|
+
if (diffMin < 60) return `${diffMin}m ago`;
|
|
72
|
+
if (diffHour < 24) return `${diffHour}h ago`;
|
|
73
|
+
if (diffDay < 7) return `${diffDay}d ago`;
|
|
74
|
+
return formatDate(d);
|
|
75
|
+
}
|
|
76
|
+
function isValidEmail(email) {
|
|
77
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
78
|
+
return emailRegex.test(email);
|
|
79
|
+
}
|
|
80
|
+
function isValidPhone(phone) {
|
|
81
|
+
const phoneRegex = /^\+?[1-9]\d{1,14}$/;
|
|
82
|
+
return phoneRegex.test(phone.replace(/[\s-()]/g, ""));
|
|
83
|
+
}
|
|
84
|
+
function capitalize(str) {
|
|
85
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
86
|
+
}
|
|
87
|
+
function truncate(str, length) {
|
|
88
|
+
if (str.length <= length) return str;
|
|
89
|
+
return `${str.slice(0, length)}...`;
|
|
90
|
+
}
|
|
91
|
+
function slugify(str) {
|
|
92
|
+
return str.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
93
|
+
}
|
|
94
|
+
function sleep(ms) {
|
|
95
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
96
|
+
}
|
|
97
|
+
async function retry(fn, options = {}) {
|
|
98
|
+
const { maxAttempts = 3, delay = 1e3, backoff = 2 } = options;
|
|
99
|
+
let lastError;
|
|
100
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
101
|
+
try {
|
|
102
|
+
return await fn();
|
|
103
|
+
} catch (error) {
|
|
104
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
105
|
+
if (attempt < maxAttempts) {
|
|
106
|
+
await sleep(delay * Math.pow(backoff, attempt - 1));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw lastError;
|
|
111
|
+
}
|
|
112
|
+
function omit(obj, keys) {
|
|
113
|
+
const result = { ...obj };
|
|
114
|
+
for (const key of keys) {
|
|
115
|
+
delete result[key];
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
function pick(obj, keys) {
|
|
120
|
+
const result = {};
|
|
121
|
+
for (const key of keys) {
|
|
122
|
+
if (key in obj) {
|
|
123
|
+
result[key] = obj[key];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
var OneSDKError = class extends Error {
|
|
129
|
+
constructor(message, code, details) {
|
|
130
|
+
super(message);
|
|
131
|
+
this.name = "OneSDKError";
|
|
132
|
+
this.code = code;
|
|
133
|
+
this.details = details;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
function isOneSDKError(error) {
|
|
137
|
+
return error instanceof OneSDKError;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export { OneSDKError, capitalize, checksumAddress, formatDate, formatDateTime, formatNumber, formatPercent, formatRelativeTime, formatTokenAmount, formatUSD, isOneSDKError, isValidAddress, isValidEmail, isValidPhone, omit, pick, retry, shortenAddress, sleep, slugify, truncate };
|
|
141
|
+
//# sourceMappingURL=index.mjs.map
|
|
142
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"names":[],"mappings":";AACO,SAAS,cAAA,CAAe,OAAA,EAAiB,KAAA,GAAQ,CAAA,EAAW;AACjE,EAAA,IAAI,CAAC,SAAS,OAAO,EAAA;AACrB,EAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,KAAA,GAAQ,CAAC,CAAC,CAAA,GAAA,EAAM,OAAA,CAAQ,KAAA,CAAM,CAAC,KAAK,CAAC,CAAA,CAAA;AAClE;AAEO,SAAS,eAAe,OAAA,EAA0B;AACvD,EAAA,OAAO,qBAAA,CAAsB,KAAK,OAAO,CAAA;AAC3C;AAEO,SAAS,gBAAgB,OAAA,EAAyB;AAEvD,EAAA,OAAO,QAAQ,WAAA,EAAY;AAC7B;AAGO,SAAS,YAAA,CACd,KAAA,EACA,OAAA,GAKI,EAAC,EACG;AACR,EAAA,MAAM,EAAE,WAAW,CAAA,EAAG,OAAA,GAAU,OAAO,QAAA,EAAU,MAAA,GAAS,SAAQ,GAAI,OAAA;AAEtE,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,OAAO,IAAI,IAAA,CAAK,YAAA,CAAa,MAAA,EAAQ;AAAA,MACnC,KAAA,E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,OAAO,MAAA;AACT;AAGO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EAIrC,WAAA,CAAY,OAAA,EAAiB,IAAA,EAAc,OAAA,EAAe;AACxD,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AACF;AAEO,SAAS,cAAc,KAAA,EAAsC;AAClE,EAAA,OAAO,KAAA,YAAiB,WAAA;AAC1B","file":"index.mjs","sourcesContent":["// ===== Address Utilities =====\nexport function shortenAddress(address: string, chars = 4): string {\n if (!address) return '';\n return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;\n}\n\nexport function isValidAddress(address: string): boolean {\n return /^0x[a-fA-F0-9]{40}$/.test(address);\n}\n\nexport function checksumAddress(address: string): string {\n // Basic checksum - for proper checksum use ethers/viem\n return address.toLowerCase();\n}\n\n// ===== Number Formatting =====\nexport function formatNumber(\n value: number,\n options: {\n decimals?: number;\n compact?: boolean;\n currency?: string;\n locale?: string;\n } = {}\n): string {\n const { decimals = 2, compact = false, currency, locale = 'en-US' } = options;\n\n if (currency) {\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency,\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n notation: compact ? 'compact' : 'standard',\n }).format(value);\n }\n\n return new Intl.NumberFormat(locale, {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n notation: compact ? 'compact' : 'standard',\n }).format(value);\n}\n\nexport function formatUSD(value: number, compact = false): string {\n return formatNumber(value, { currency: 'USD', compact });\n}\n\nexport function formatPercent(value: number, decimals = 2): string {\n const sign = value >= 0 ? '+' : '';\n return `${sign}${value.toFixed(decimals)}%`;\n}\n\nexport function formatTokenAmount(amount: number, decimals = 6): string {\n if (amount === 0) return '0';\n if (amount < 0.000001) return '<0.000001';\n if (amount < 1) return amount.toFixed(decimals);\n if (amount < 1000) return amount.toFixed(4);\n if (amount < 1000000) return formatNumber(amount, { decimals: 2 });\n return formatNumber(amount, { decimals: 2, compact: true });\n}\n\n// ===== Date & Time Utilities =====\nexport function formatDate(\n date: string | Date,\n options: Intl.DateTimeFormatOptions = {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n }\n): string {\n const d = typeof date === 'string' ? new Date(date) : date;\n return d.toLocaleDateString('en-US', options);\n}\n\nexport function formatDateTime(date: string | Date): string {\n const d = typeof date === 'string' ? new Date(date) : date;\n return d.toLocaleString('en-US', {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: '2-digit',\n minute: '2-digit',\n });\n}\n\nexport function formatRelativeTime(date: string | Date): string {\n const d = typeof date === 'string' ? new Date(date) : date;\n const now = new Date();\n const diffMs = now.getTime() - d.getTime();\n const diffSec = Math.floor(diffMs / 1000);\n const diffMin = Math.floor(diffSec / 60);\n const diffHour = Math.floor(diffMin / 60);\n const diffDay = Math.floor(diffHour / 24);\n\n if (diffSec < 60) return 'just now';\n if (diffMin < 60) return `${diffMin}m ago`;\n if (diffHour < 24) return `${diffHour}h ago`;\n if (diffDay < 7) return `${diffDay}d ago`;\n\n return formatDate(d);\n}\n\n// ===== Validation Utilities =====\nexport function isValidEmail(email: string): boolean {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n return emailRegex.test(email);\n}\n\nexport function isValidPhone(phone: string): boolean {\n const phoneRegex = /^\\+?[1-9]\\d{1,14}$/;\n return phoneRegex.test(phone.replace(/[\\s-()]/g, ''));\n}\n\n// ===== String Utilities =====\nexport function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();\n}\n\nexport function truncate(str: string, length: number): string {\n if (str.length <= length) return str;\n return `${str.slice(0, length)}...`;\n}\n\nexport function slugify(str: string): string {\n return str\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/(^-|-$)/g, '');\n}\n\n// ===== Async Utilities =====\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport async function retry<T>(\n fn: () => Promise<T>,\n options: { maxAttempts?: number; delay?: number; backoff?: number } = {}\n): Promise<T> {\n const { maxAttempts = 3, delay = 1000, backoff = 2 } = options;\n\n let lastError: Error | undefined;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await fn();\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n\n if (attempt < maxAttempts) {\n await sleep(delay * Math.pow(backoff, attempt - 1));\n }\n }\n }\n\n throw lastError;\n}\n\n// ===== Object Utilities =====\nexport function omit<T extends Record<string, any>, K extends keyof T>(\n obj: T,\n keys: K[]\n): Omit<T, K> {\n const result = { ...obj };\n for (const key of keys) {\n delete result[key];\n }\n return result;\n}\n\nexport function pick<T extends Record<string, any>, K extends keyof T>(\n obj: T,\n keys: K[]\n): Pick<T, K> {\n const result = {} as Pick<T, K>;\n for (const key of keys) {\n if (key in obj) {\n result[key] = obj[key];\n }\n }\n return result;\n}\n\n// ===== Error Handling =====\nexport class OneSDKError extends Error {\n code: string;\n details?: any;\n\n constructor(message: string, code: string, details?: any) {\n super(message);\n this.name = 'OneSDKError';\n this.code = code;\n this.details = details;\n }\n}\n\nexport function isOneSDKError(error: unknown): error is OneSDKError {\n return error instanceof OneSDKError;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@one_deploy/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "ONE Ecosystem SDK - Shared services, types, utilities, and React providers",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./services": {
|
|
16
|
+
"import": "./dist/services/index.mjs",
|
|
17
|
+
"require": "./dist/services/index.js",
|
|
18
|
+
"types": "./dist/services/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./types": {
|
|
21
|
+
"import": "./dist/types/index.mjs",
|
|
22
|
+
"require": "./dist/types/index.js",
|
|
23
|
+
"types": "./dist/types/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./utils": {
|
|
26
|
+
"import": "./dist/utils/index.mjs",
|
|
27
|
+
"require": "./dist/utils/index.js",
|
|
28
|
+
"types": "./dist/utils/index.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./config": {
|
|
31
|
+
"import": "./dist/config/index.mjs",
|
|
32
|
+
"require": "./dist/config/index.js",
|
|
33
|
+
"types": "./dist/config/index.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"./providers": {
|
|
36
|
+
"import": "./dist/providers/index.mjs",
|
|
37
|
+
"require": "./dist/providers/index.js",
|
|
38
|
+
"types": "./dist/providers/index.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./hooks": {
|
|
41
|
+
"import": "./dist/hooks/index.mjs",
|
|
42
|
+
"require": "./dist/hooks/index.js",
|
|
43
|
+
"types": "./dist/hooks/index.d.ts"
|
|
44
|
+
},
|
|
45
|
+
"./components": {
|
|
46
|
+
"import": "./dist/components/index.mjs",
|
|
47
|
+
"require": "./dist/components/index.js",
|
|
48
|
+
"types": "./dist/components/index.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"./react-native": {
|
|
51
|
+
"import": "./dist/react-native.mjs",
|
|
52
|
+
"require": "./dist/react-native.js",
|
|
53
|
+
"types": "./dist/react-native.d.ts"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"react-native": "./dist/react-native.js",
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup",
|
|
59
|
+
"dev": "tsup --watch",
|
|
60
|
+
"clean": "rm -rf dist",
|
|
61
|
+
"type-check": "tsc --noEmit",
|
|
62
|
+
"lint": "eslint src --ext .ts,.tsx"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@supabase/supabase-js": "^2.45.0",
|
|
66
|
+
"zod": "^3.23.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/node": "^22.0.0",
|
|
70
|
+
"@types/react": "^18.3.0",
|
|
71
|
+
"thirdweb": "^5.116.1",
|
|
72
|
+
"tsup": "^8.3.0",
|
|
73
|
+
"typescript": "^5.6.0"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"react": ">=18.0.0",
|
|
77
|
+
"react-native": ">=0.72.0",
|
|
78
|
+
"thirdweb": ">=5.0.0"
|
|
79
|
+
},
|
|
80
|
+
"peerDependenciesMeta": {
|
|
81
|
+
"react": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"react-native": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"thirdweb": {
|
|
88
|
+
"optional": true
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"keywords": [
|
|
92
|
+
"one-ecosystem",
|
|
93
|
+
"web3",
|
|
94
|
+
"wallet",
|
|
95
|
+
"thirdweb",
|
|
96
|
+
"supabase",
|
|
97
|
+
"onramp",
|
|
98
|
+
"swap"
|
|
99
|
+
],
|
|
100
|
+
"license": "MIT"
|
|
101
|
+
}
|