@ab-org/predicate-market-sdk 0.0.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.
- package/README.md +246 -0
- package/dist/auth/autoReconnect.d.ts +11 -0
- package/dist/auth/autoReconnect.js +36 -0
- package/dist/auth/bundledConfig.d.ts +2 -0
- package/dist/auth/bundledConfig.js +19 -0
- package/dist/auth/config.d.ts +29 -0
- package/dist/auth/config.js +53 -0
- package/dist/auth/google.d.ts +43 -0
- package/dist/auth/google.js +147 -0
- package/dist/auth/twitter.d.ts +7 -0
- package/dist/auth/twitter.js +94 -0
- package/dist/constants/chains.d.ts +22 -0
- package/dist/constants/chains.js +23 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +19 -0
- package/dist/modules/api.d.ts +144 -0
- package/dist/modules/api.js +93 -0
- package/dist/modules/balanceQuery.d.ts +20 -0
- package/dist/modules/balanceQuery.js +58 -0
- package/dist/modules/deposit.d.ts +31 -0
- package/dist/modules/deposit.js +57 -0
- package/dist/modules/marketData.d.ts +8 -0
- package/dist/modules/marketData.js +113 -0
- package/dist/modules/withdraw.d.ts +31 -0
- package/dist/modules/withdraw.js +60 -0
- package/dist/modules/withdrawExecutor.d.ts +47 -0
- package/dist/modules/withdrawExecutor.js +208 -0
- package/dist/policyAdapter.d.ts +11 -0
- package/dist/policyAdapter.js +38 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.js +1 -0
- package/dist/ui/DepositModal.d.ts +36 -0
- package/dist/ui/DepositModal.js +326 -0
- package/dist/ui/SignInModal.d.ts +22 -0
- package/dist/ui/SignInModal.js +74 -0
- package/dist/ui/SignInModal.sections.d.ts +33 -0
- package/dist/ui/SignInModal.sections.js +45 -0
- package/dist/ui/SignInModal.shared.d.ts +15 -0
- package/dist/ui/SignInModal.shared.js +87 -0
- package/dist/ui/WalletSelectionModal.d.ts +14 -0
- package/dist/ui/WalletSelectionModal.js +54 -0
- package/dist/ui/WithdrawModal.d.ts +47 -0
- package/dist/ui/WithdrawModal.js +528 -0
- package/dist/ui/components/CloseButton.d.ts +4 -0
- package/dist/ui/components/CloseButton.js +15 -0
- package/dist/ui/components/Countdown.d.ts +16 -0
- package/dist/ui/components/Countdown.js +42 -0
- package/dist/ui/components/DepositDetailsPanel.d.ts +8 -0
- package/dist/ui/components/DepositDetailsPanel.js +117 -0
- package/dist/ui/components/DropdownField.d.ts +19 -0
- package/dist/ui/components/DropdownField.js +81 -0
- package/dist/ui/components/Field.d.ts +10 -0
- package/dist/ui/components/Field.js +21 -0
- package/dist/ui/components/LoginRequiredOverlay.d.ts +6 -0
- package/dist/ui/components/LoginRequiredOverlay.js +31 -0
- package/dist/ui/components/ModalCard.d.ts +9 -0
- package/dist/ui/components/ModalCard.js +14 -0
- package/dist/ui/components/ModalFrame.d.ts +9 -0
- package/dist/ui/components/ModalFrame.js +18 -0
- package/dist/ui/components/PrimaryButton.d.ts +2 -0
- package/dist/ui/components/PrimaryButton.js +14 -0
- package/dist/ui/components/QRCodePanel.d.ts +4 -0
- package/dist/ui/components/QRCodePanel.js +43 -0
- package/dist/ui/components/Select.d.ts +12 -0
- package/dist/ui/components/Select.js +29 -0
- package/dist/ui/components/StepIndicator.d.ts +7 -0
- package/dist/ui/components/StepIndicator.js +35 -0
- package/dist/ui/components/Success.d.ts +1 -0
- package/dist/ui/components/Success.js +4 -0
- package/dist/ui/components/Toast.d.ts +8 -0
- package/dist/ui/components/Toast.js +51 -0
- package/dist/ui/hooks/useSession.d.ts +2 -0
- package/dist/ui/hooks/useSession.js +10 -0
- package/dist/ui/signInTypes.d.ts +25 -0
- package/dist/ui/signInTypes.js +1 -0
- package/dist/ui/theme.d.ts +31 -0
- package/dist/ui/theme.js +31 -0
- package/dist/ui/useSignInModalController.d.ts +25 -0
- package/dist/ui/useSignInModalController.js +173 -0
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/env.js +61 -0
- package/dist/utils/explorer.d.ts +3 -0
- package/dist/utils/explorer.js +47 -0
- package/dist/walletUtils.d.ts +3 -0
- package/dist/walletUtils.js +3 -0
- package/package.json +41 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { colors, radii } from "../theme.js";
|
|
4
|
+
const variantStyles = {
|
|
5
|
+
success: { bg: "rgba(41, 255, 155, 0.82)", border: "rgba(41, 255, 155, 0.53)" },
|
|
6
|
+
error: { bg: "rgba(255, 107, 107, 0.82)", border: "rgba(255, 107, 107, 0.53)" },
|
|
7
|
+
info: { bg: "rgba(126, 135, 162, 0.82)", border: "rgba(126, 135, 162, 0.55)" },
|
|
8
|
+
};
|
|
9
|
+
export const Toast = ({ message, variant = "info", duration, onClose }) => {
|
|
10
|
+
const style = variantStyles[variant];
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (duration != null && duration > 0 && onClose) {
|
|
13
|
+
const timer = setTimeout(onClose, duration);
|
|
14
|
+
return () => clearTimeout(timer);
|
|
15
|
+
}
|
|
16
|
+
}, [duration, onClose]);
|
|
17
|
+
return (_jsx("div", { style: {
|
|
18
|
+
position: "fixed",
|
|
19
|
+
top: 0,
|
|
20
|
+
left: 0,
|
|
21
|
+
right: 0,
|
|
22
|
+
display: "flex",
|
|
23
|
+
justifyContent: "center",
|
|
24
|
+
paddingTop: 16,
|
|
25
|
+
zIndex: 10000,
|
|
26
|
+
pointerEvents: "none",
|
|
27
|
+
}, children: _jsxs("div", { role: "alert", style: {
|
|
28
|
+
pointerEvents: "auto",
|
|
29
|
+
display: "flex",
|
|
30
|
+
alignItems: "center",
|
|
31
|
+
gap: 10,
|
|
32
|
+
padding: "12px 16px",
|
|
33
|
+
borderRadius: radii.card,
|
|
34
|
+
background: style.bg,
|
|
35
|
+
border: `1px solid ${style.border}`,
|
|
36
|
+
color: colors.textPrimary,
|
|
37
|
+
fontSize: 14,
|
|
38
|
+
lineHeight: 1.4,
|
|
39
|
+
maxWidth: 360,
|
|
40
|
+
boxSizing: "border-box",
|
|
41
|
+
}, children: [_jsx("span", { style: { flex: 1 }, children: message }), onClose ? (_jsx("button", { type: "button", "aria-label": "Dismiss", onClick: onClose, style: {
|
|
42
|
+
padding: 4,
|
|
43
|
+
margin: -4,
|
|
44
|
+
border: "none",
|
|
45
|
+
background: "transparent",
|
|
46
|
+
color: colors.textSecondary,
|
|
47
|
+
cursor: "pointer",
|
|
48
|
+
borderRadius: 4,
|
|
49
|
+
lineHeight: 1,
|
|
50
|
+
}, children: _jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: _jsx("path", { d: "M3.5 3.5L10.5 10.5M10.5 3.5L3.5 10.5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }) }) })) : null] }) }));
|
|
51
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { sessionStore } from "@ab-org/sdk-core";
|
|
3
|
+
export function useSession() {
|
|
4
|
+
const [session, setSession] = useState(() => sessionStore.getState().session);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const unsub = sessionStore.on("session:changed", setSession);
|
|
7
|
+
return () => { unsub(); };
|
|
8
|
+
}, []);
|
|
9
|
+
return session;
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { SessionCapabilityPolicy } from "@ab-org/sdk-core";
|
|
3
|
+
export interface WalletItem {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
installed?: boolean;
|
|
8
|
+
installUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SocialProvider {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
icon?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export interface SignInUiConfig {
|
|
16
|
+
socialProviders?: SocialProvider[];
|
|
17
|
+
wallets?: WalletItem[];
|
|
18
|
+
initialVisibleCount?: number;
|
|
19
|
+
sessionConfirmation?: {
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
title?: string;
|
|
22
|
+
message?: string;
|
|
23
|
+
};
|
|
24
|
+
sessionPolicy?: Partial<SessionCapabilityPolicy>;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const colors: {
|
|
2
|
+
background: string;
|
|
3
|
+
card: string;
|
|
4
|
+
cardRaised: string;
|
|
5
|
+
border: string;
|
|
6
|
+
borderStrong: string;
|
|
7
|
+
borderFocused: string;
|
|
8
|
+
textPrimary: string;
|
|
9
|
+
textSecondary: string;
|
|
10
|
+
accent: string;
|
|
11
|
+
accentStrong: string;
|
|
12
|
+
warning: string;
|
|
13
|
+
danger: string;
|
|
14
|
+
stepActive: string;
|
|
15
|
+
stepInactive: string;
|
|
16
|
+
buttonDisabledBg: string;
|
|
17
|
+
buttonDisabledBorder: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const radii: {
|
|
20
|
+
xl: string;
|
|
21
|
+
lg: string;
|
|
22
|
+
md: string;
|
|
23
|
+
sm: string;
|
|
24
|
+
pill: string;
|
|
25
|
+
full: string;
|
|
26
|
+
card: string;
|
|
27
|
+
input: string;
|
|
28
|
+
};
|
|
29
|
+
export declare const fonts: {
|
|
30
|
+
family: string;
|
|
31
|
+
};
|
package/dist/ui/theme.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const colors = {
|
|
2
|
+
background: "#050608",
|
|
3
|
+
card: "#121214",
|
|
4
|
+
cardRaised: "#151821",
|
|
5
|
+
border: "rgba(126,135,162,0.2)",
|
|
6
|
+
borderStrong: "rgba(255,255,255,0.16)",
|
|
7
|
+
borderFocused: "#FFFFFF",
|
|
8
|
+
textPrimary: "#FFFFFF",
|
|
9
|
+
textSecondary: "#737477",
|
|
10
|
+
accent: "#29FF9B",
|
|
11
|
+
accentStrong: "#4AD481",
|
|
12
|
+
warning: "#FFB547",
|
|
13
|
+
danger: "#FF6B6B",
|
|
14
|
+
stepActive: "#FFFFFF",
|
|
15
|
+
stepInactive: "#36383D",
|
|
16
|
+
buttonDisabledBg: "rgba(255,255,255,0.14)",
|
|
17
|
+
buttonDisabledBorder: "#444444",
|
|
18
|
+
};
|
|
19
|
+
export const radii = {
|
|
20
|
+
xl: "28px",
|
|
21
|
+
lg: "20px",
|
|
22
|
+
md: "14px",
|
|
23
|
+
sm: "10px",
|
|
24
|
+
pill: "99px",
|
|
25
|
+
full: "9999px",
|
|
26
|
+
card: "12px",
|
|
27
|
+
input: "8px",
|
|
28
|
+
};
|
|
29
|
+
export const fonts = {
|
|
30
|
+
family: '"Switzer", "Inter", "SF Pro Display", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
31
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type GoogleCredential } from "../auth/google.js";
|
|
2
|
+
import { type TwitterAuthResult } from "../auth/twitter.js";
|
|
3
|
+
import { type CubeSignerSession, type WalletSession } from "@ab-org/sdk-core";
|
|
4
|
+
import type { WalletItem } from "./signInTypes.js";
|
|
5
|
+
export interface SignInModalControllerOptions {
|
|
6
|
+
wallets: WalletItem[] | undefined;
|
|
7
|
+
initialVisibleCount: number;
|
|
8
|
+
onGoogleLogin?: (credential: GoogleCredential) => void;
|
|
9
|
+
onTwitterLogin?: (result: TwitterAuthResult) => void;
|
|
10
|
+
onCubeSignerSession?: (session: CubeSignerSession) => void;
|
|
11
|
+
onWalletConnected?: (session: WalletSession, walletId: string) => void;
|
|
12
|
+
onSocialLogin?: (providerId: string) => void;
|
|
13
|
+
onWalletSelect?: (walletId: string) => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare const useSignInModalController: ({ wallets, initialVisibleCount, onGoogleLogin, onTwitterLogin, onCubeSignerSession, onWalletConnected, onSocialLogin, onWalletSelect, }: SignInModalControllerOptions) => {
|
|
16
|
+
expanded: boolean;
|
|
17
|
+
loadingProvider: string | null;
|
|
18
|
+
loadingWalletId: string | null;
|
|
19
|
+
visibleWallets: WalletItem[];
|
|
20
|
+
showExpandToggle: boolean;
|
|
21
|
+
isBusy: boolean;
|
|
22
|
+
handleSocialClick: (providerId: string) => Promise<WalletSession | null>;
|
|
23
|
+
handleWalletClick: (walletId: string) => Promise<WalletSession | null>;
|
|
24
|
+
toggleExpanded: () => void;
|
|
25
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
2
|
+
import { getSDKConfig } from "../auth/config.js";
|
|
3
|
+
import { signInWithGoogle } from "../auth/google.js";
|
|
4
|
+
import { signInWithTwitter } from "../auth/twitter.js";
|
|
5
|
+
import { CubistSocialProvider, describeSessionCapabilityPolicy, WalletConnector, createDefaultInjectedWalletRegistry, } from "@ab-org/sdk-core";
|
|
6
|
+
import { resolveWalletItems } from "./SignInModal.shared.js";
|
|
7
|
+
export const useSignInModalController = ({ wallets, initialVisibleCount, onGoogleLogin, onTwitterLogin, onCubeSignerSession, onWalletConnected, onSocialLogin, onWalletSelect, }) => {
|
|
8
|
+
const [expanded, setExpanded] = useState(false);
|
|
9
|
+
const [loadingProvider, setLoadingProvider] = useState(null);
|
|
10
|
+
const [loadingWalletId, setLoadingWalletId] = useState(null);
|
|
11
|
+
const defaultWalletRegistry = useMemo(() => createDefaultInjectedWalletRegistry(), []);
|
|
12
|
+
const sdkConfig = getSDKConfig();
|
|
13
|
+
const cubistProvider = useMemo(() => {
|
|
14
|
+
if (!sdkConfig.cubeSigner)
|
|
15
|
+
return null;
|
|
16
|
+
return new CubistSocialProvider({
|
|
17
|
+
...sdkConfig.cubeSigner,
|
|
18
|
+
defaultSessionPolicy: sdkConfig.signIn?.sessionPolicy ?? sdkConfig.cubeSigner.defaultSessionPolicy,
|
|
19
|
+
});
|
|
20
|
+
}, [sdkConfig.cubeSigner, sdkConfig.signIn?.sessionPolicy]);
|
|
21
|
+
const defaultWalletConnector = useMemo(() => new WalletConnector([
|
|
22
|
+
...defaultWalletRegistry.map((item) => item.provider),
|
|
23
|
+
...(cubistProvider ? [cubistProvider] : []),
|
|
24
|
+
]), [cubistProvider, defaultWalletRegistry]);
|
|
25
|
+
const resolvedWallets = useMemo(() => resolveWalletItems(wallets, defaultWalletRegistry), [defaultWalletRegistry, wallets]);
|
|
26
|
+
const showExpandToggle = resolvedWallets.length > initialVisibleCount;
|
|
27
|
+
const visibleWallets = expanded ? resolvedWallets : resolvedWallets.slice(0, initialVisibleCount);
|
|
28
|
+
const isBusy = !!loadingProvider || !!loadingWalletId;
|
|
29
|
+
const confirmCapabilitySession = async (providerId, cubistForPolicy) => {
|
|
30
|
+
const cubist = cubistForPolicy ?? cubistProvider;
|
|
31
|
+
const confirmation = sdkConfig.signIn?.sessionConfirmation;
|
|
32
|
+
const policy = cubist?.cubeSignerAuth.defaultSessionPolicy;
|
|
33
|
+
if (confirmation?.enabled === false || !policy) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (typeof window === "undefined" || typeof window.confirm !== "function") {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
const lines = describeSessionCapabilityPolicy(cubist?.cubeSignerAuth.defaultSessionPolicy
|
|
40
|
+
? {
|
|
41
|
+
id: "preview",
|
|
42
|
+
...cubist.cubeSignerAuth.defaultSessionPolicy,
|
|
43
|
+
}
|
|
44
|
+
: undefined);
|
|
45
|
+
const message = [
|
|
46
|
+
confirmation?.title ?? "Authorize smart-wallet session",
|
|
47
|
+
confirmation?.message ?? `Continue with ${providerId} and create a capability session?`,
|
|
48
|
+
...lines,
|
|
49
|
+
]
|
|
50
|
+
.filter(Boolean)
|
|
51
|
+
.join("\n");
|
|
52
|
+
return window.confirm(message);
|
|
53
|
+
};
|
|
54
|
+
const getCubistAndConnector = (config) => {
|
|
55
|
+
if (!config.cubeSigner)
|
|
56
|
+
return { cubist: null, connector: defaultWalletConnector };
|
|
57
|
+
if (cubistProvider)
|
|
58
|
+
return { cubist: cubistProvider, connector: defaultWalletConnector };
|
|
59
|
+
const cubist = new CubistSocialProvider({
|
|
60
|
+
...config.cubeSigner,
|
|
61
|
+
defaultSessionPolicy: config.signIn?.sessionPolicy ?? config.cubeSigner.defaultSessionPolicy,
|
|
62
|
+
});
|
|
63
|
+
const connector = new WalletConnector([
|
|
64
|
+
...defaultWalletRegistry.map((item) => item.provider),
|
|
65
|
+
cubist,
|
|
66
|
+
]);
|
|
67
|
+
return { cubist, connector };
|
|
68
|
+
};
|
|
69
|
+
const handleSocialClick = async (providerId) => {
|
|
70
|
+
setLoadingProvider(providerId);
|
|
71
|
+
try {
|
|
72
|
+
const config = getSDKConfig();
|
|
73
|
+
if (!config.cubeSigner) {
|
|
74
|
+
throw new Error("cubeSigner config is required for social login");
|
|
75
|
+
}
|
|
76
|
+
const { cubist, connector } = getCubistAndConnector(config);
|
|
77
|
+
if (!cubist) {
|
|
78
|
+
throw new Error("Cubist provider is unavailable");
|
|
79
|
+
}
|
|
80
|
+
const confirmed = await confirmCapabilitySession(providerId, cubist);
|
|
81
|
+
if (!confirmed)
|
|
82
|
+
return null;
|
|
83
|
+
if (providerId === "google") {
|
|
84
|
+
if (!config.googleClientId) {
|
|
85
|
+
throw new Error("googleClientId is required for Google sign-in");
|
|
86
|
+
}
|
|
87
|
+
const credential = await signInWithGoogle(config.googleClientId);
|
|
88
|
+
onGoogleLogin?.(credential);
|
|
89
|
+
const session = await connector.connect(cubist.id, {
|
|
90
|
+
payload: { type: "google", idToken: credential.idToken },
|
|
91
|
+
});
|
|
92
|
+
const cubeSignerSession = cubist.cubeSignerSession;
|
|
93
|
+
if (cubeSignerSession)
|
|
94
|
+
onCubeSignerSession?.(cubeSignerSession);
|
|
95
|
+
onSocialLogin?.(providerId);
|
|
96
|
+
return session;
|
|
97
|
+
}
|
|
98
|
+
if (providerId === "x") {
|
|
99
|
+
if (!config.twitterClientId) {
|
|
100
|
+
throw new Error("twitterClientId is required for X sign-in");
|
|
101
|
+
}
|
|
102
|
+
const redirectUri = config.twitterRedirectUri ??
|
|
103
|
+
(typeof window !== "undefined"
|
|
104
|
+
? `${window.location.origin}/auth/twitter-callback`
|
|
105
|
+
: undefined);
|
|
106
|
+
if (!redirectUri) {
|
|
107
|
+
throw new Error("twitterRedirectUri is required for X sign-in");
|
|
108
|
+
}
|
|
109
|
+
const result = await signInWithTwitter(config.twitterClientId, redirectUri);
|
|
110
|
+
onTwitterLogin?.(result);
|
|
111
|
+
const session = await connector.connect(cubist.id, {
|
|
112
|
+
payload: {
|
|
113
|
+
type: "twitter",
|
|
114
|
+
params: {
|
|
115
|
+
code: result.code,
|
|
116
|
+
codeVerifier: result.codeVerifier,
|
|
117
|
+
redirectUri,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
const cubeSignerSession = cubist.cubeSignerSession;
|
|
122
|
+
if (cubeSignerSession)
|
|
123
|
+
onCubeSignerSession?.(cubeSignerSession);
|
|
124
|
+
onSocialLogin?.(providerId);
|
|
125
|
+
return session;
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`Unsupported social provider: ${providerId}`);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
setLoadingProvider(null);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const handleWalletClick = async (walletId) => {
|
|
134
|
+
if (isBusy)
|
|
135
|
+
return null;
|
|
136
|
+
const targetWallet = resolvedWallets.find((wallet) => wallet.id === walletId);
|
|
137
|
+
if (!targetWallet)
|
|
138
|
+
return null;
|
|
139
|
+
if (targetWallet.installed === false && targetWallet.installUrl)
|
|
140
|
+
return null;
|
|
141
|
+
setLoadingWalletId(walletId);
|
|
142
|
+
try {
|
|
143
|
+
if (onWalletSelect) {
|
|
144
|
+
await onWalletSelect(walletId);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const builtInWallet = defaultWalletRegistry.find((item) => item.id === walletId);
|
|
148
|
+
if (!builtInWallet || !builtInWallet.installed)
|
|
149
|
+
return null;
|
|
150
|
+
const session = await defaultWalletConnector.connect(walletId);
|
|
151
|
+
onWalletConnected?.(session, walletId);
|
|
152
|
+
return session;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
console.error(`[SDK] Wallet connect failed for ${walletId}:`, error);
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
setLoadingWalletId(null);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
expanded,
|
|
164
|
+
loadingProvider,
|
|
165
|
+
loadingWalletId,
|
|
166
|
+
visibleWallets,
|
|
167
|
+
showExpandToggle,
|
|
168
|
+
isBusy,
|
|
169
|
+
handleSocialClick,
|
|
170
|
+
handleWalletClick,
|
|
171
|
+
toggleExpanded: () => setExpanded((value) => !value),
|
|
172
|
+
};
|
|
173
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEnv(key: string): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function pick(...candidates) {
|
|
2
|
+
for (const candidate of candidates) {
|
|
3
|
+
if (candidate != null && candidate !== "")
|
|
4
|
+
return candidate;
|
|
5
|
+
}
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
function nextPublicProcessEnvKey(logicalKey) {
|
|
9
|
+
return `NEXT_PUBLIC_${logicalKey}`;
|
|
10
|
+
}
|
|
11
|
+
function readProcessEnvStatic(key) {
|
|
12
|
+
if (typeof process === "undefined" || !process.env)
|
|
13
|
+
return undefined;
|
|
14
|
+
switch (key) {
|
|
15
|
+
case "STAGE":
|
|
16
|
+
return pick(process.env.NEXT_PUBLIC_STAGE, process.env.STAGE);
|
|
17
|
+
case "GOOGLE_CLIENT_ID":
|
|
18
|
+
return pick(process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID, process.env.GOOGLE_CLIENT_ID);
|
|
19
|
+
case "X_CLIENT_ID":
|
|
20
|
+
return pick(process.env.NEXT_PUBLIC_X_CLIENT_ID, process.env.X_CLIENT_ID);
|
|
21
|
+
case "MERCHANT_BASE_URL":
|
|
22
|
+
return pick(process.env.NEXT_PUBLIC_MERCHANT_BASE_URL, process.env.MERCHANT_BASE_URL);
|
|
23
|
+
case "CUBE_SIGNER_ENV":
|
|
24
|
+
return pick(process.env.NEXT_PUBLIC_CUBE_SIGNER_ENV, process.env.CUBE_SIGNER_ENV);
|
|
25
|
+
case "CUBE_SIGNER_ORG_ID":
|
|
26
|
+
return pick(process.env.NEXT_PUBLIC_CUBE_SIGNER_ORG_ID, process.env.CUBE_SIGNER_ORG_ID);
|
|
27
|
+
case "CUBE_REG":
|
|
28
|
+
return pick(process.env.NEXT_PUBLIC_CUBE_REG, process.env.CUBE_REG);
|
|
29
|
+
case "RELAY_ORIGIN":
|
|
30
|
+
return pick(process.env.NEXT_PUBLIC_RELAY_ORIGIN, process.env.RELAY_ORIGIN);
|
|
31
|
+
default:
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function getEnv(key) {
|
|
36
|
+
const staticVal = readProcessEnvStatic(key);
|
|
37
|
+
if (staticVal != null && staticVal !== "")
|
|
38
|
+
return staticVal;
|
|
39
|
+
const globalEnv = globalThis
|
|
40
|
+
.process?.env;
|
|
41
|
+
if (globalEnv) {
|
|
42
|
+
const pub = nextPublicProcessEnvKey(key);
|
|
43
|
+
const val = globalEnv[key] ?? globalEnv[pub];
|
|
44
|
+
if (val != null && val !== "")
|
|
45
|
+
return val;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const metaEnv = import.meta.env;
|
|
49
|
+
if (metaEnv) {
|
|
50
|
+
const pub = nextPublicProcessEnvKey(key);
|
|
51
|
+
const val = metaEnv[key] ?? metaEnv[pub];
|
|
52
|
+
if (val != null && val !== "")
|
|
53
|
+
return val;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Ignore unavailable import.meta.env in some runtimes.
|
|
58
|
+
}
|
|
59
|
+
console.error(`${key} is not set`);
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const explorerTemplates = {
|
|
2
|
+
"0": "",
|
|
3
|
+
"1": "https://etherscan.io/tx/{txId}",
|
|
4
|
+
"3": "https://dogechain.info/tx/{txId}",
|
|
5
|
+
"10": "https://optimistic.etherscan.io/tx/{txId}",
|
|
6
|
+
"56": "https://bscscan.com/tx/{txId}",
|
|
7
|
+
"110": "",
|
|
8
|
+
"126": "https://explorer.movementnetwork.xyz/txn/{txId}?network=mainnet",
|
|
9
|
+
"137": "https://polygonscan.com/tx/{txId}",
|
|
10
|
+
"204": "https://opbnb.bscscan.com/tx/{txId}",
|
|
11
|
+
"223": "https://explorer.bsquared.network/tx/{txId}",
|
|
12
|
+
"227": "https://promscan.io/tx/{txId}",
|
|
13
|
+
"324": "https://mainnet.era.zksync.io/tx/{txId}",
|
|
14
|
+
"400": "",
|
|
15
|
+
"420": "https://scan.merlinchain.io/tx/{txId}",
|
|
16
|
+
"480": "https://worldchain-mainnet.explorer.alchemy.com/tx/{txId}",
|
|
17
|
+
"501": "https://solscan.io/tx/{txId}",
|
|
18
|
+
"784": "",
|
|
19
|
+
"1329": "https://seitrace.com/tx/{txId}",
|
|
20
|
+
"1514": "https://mainnet.storyscan.xyz/tx/{txId}",
|
|
21
|
+
"1625": "https://explorer.gravity.xyz/tx/{txId}",
|
|
22
|
+
"2649": "https://mainnet-explorer.ailayer.xyz/tx/{txId}",
|
|
23
|
+
"3030": "https://dashboard.tenderly.co/explorer/vnet/bd8df763-9888-4be3-9a78-26f1d5ab8d3d/tx/{txId}",
|
|
24
|
+
"3131": "https://dashboard.tenderly.co/explorer/vnet/6593bc72-f548-497d-bff9-5be061436a48/tx/{txId}",
|
|
25
|
+
"5545": "https://scan.duckchain.io/tx/{txId}",
|
|
26
|
+
"8333": "https://mainnet-rpc.b3.fun/http/tx/{txId}",
|
|
27
|
+
"8453": "https://base.blockscout.com/tx/{txId}",
|
|
28
|
+
"19484": "https://tronscan.org/#/transaction/{txId}",
|
|
29
|
+
"21000": "https://maizenet-explorer.usecorn.com/tx/{txId}",
|
|
30
|
+
"42161": "https://arbiscan.io/tx/{txId}",
|
|
31
|
+
"43114": "https://snowtrace.io/tx/{txId}",
|
|
32
|
+
"47763": "https://neotube.io/transaction/{txId}",
|
|
33
|
+
"59144": "https://lineascan.build/tx/{txId}",
|
|
34
|
+
"60808": "https://rpc.gobob.xyz/tx/{txId}",
|
|
35
|
+
"80094": "https://berascan.com/tx/{txId}",
|
|
36
|
+
"81457": "https://blastscan.io/tx/{txId}",
|
|
37
|
+
"200901": "https://rpc.bitlayer.org/tx/{txId}",
|
|
38
|
+
"221122420": "https://blockscout.devnet.doge.xyz/tx/{txId}",
|
|
39
|
+
"534352": "https://scrollscan.com/tx/{txId}",
|
|
40
|
+
};
|
|
41
|
+
export function getExplorerUrl(chainId, data) {
|
|
42
|
+
const template = explorerTemplates[chainId] ?? "";
|
|
43
|
+
if (template === "") {
|
|
44
|
+
throw new Error(`chainId ${chainId} tpl not found`);
|
|
45
|
+
}
|
|
46
|
+
return template.replace("{txId}", data.txId);
|
|
47
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ab-org/predicate-market-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist/**/*",
|
|
7
|
+
"README.md"
|
|
8
|
+
],
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"module": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public",
|
|
20
|
+
"registry": "https://registry.npmjs.org/"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"axios": "^1.13.6",
|
|
24
|
+
"qrcode-generator": "^2.0.4",
|
|
25
|
+
"@ab-org/sdk-core": "0.0.1"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=18",
|
|
29
|
+
"viem": ">=2"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/react": "^18.2.66",
|
|
33
|
+
"typescript": "^5.5.4",
|
|
34
|
+
"viem": "2.21.54"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.json",
|
|
38
|
+
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
39
|
+
"test": "vitest run --passWithNoTests"
|
|
40
|
+
}
|
|
41
|
+
}
|