@dipansrimany/mlink-sdk 0.1.0 → 0.3.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/README.md +5 -5
- package/dist/adapters/express.d.mts +2 -1
- package/dist/adapters/express.d.ts +2 -1
- package/dist/adapters/next.d.mts +2 -1
- package/dist/adapters/next.d.ts +2 -1
- package/dist/builders-CJNt88dM.d.ts +19 -0
- package/dist/builders-CN5ijFpW.d.mts +19 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/react/index.d.mts +208 -0
- package/dist/react/index.d.ts +208 -0
- package/dist/react/index.js +580 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +565 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/styles.css +339 -0
- package/dist/{builders-OoJ5KB_g.d.mts → types-CAnUIaVe.d.mts} +1 -17
- package/dist/{builders-OoJ5KB_g.d.ts → types-CAnUIaVe.d.ts} +1 -17
- package/package.json +27 -7
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @mlink/sdk
|
|
2
2
|
|
|
3
3
|
SDK for building Mantle Blinks - shareable blockchain transaction URLs for Mantle Network.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @
|
|
8
|
+
npm install @dipansrimany/mlink-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
@@ -13,7 +13,7 @@ npm install @mantle-blinks/sdk
|
|
|
13
13
|
### 1. Create an Action
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
import { createAction, button, input, parseEther } from '@
|
|
16
|
+
import { createAction, button, input, parseEther } from '@dipansrimany/mlink-sdk';
|
|
17
17
|
|
|
18
18
|
export const tipAction = createAction({
|
|
19
19
|
title: 'Tip the Developer',
|
|
@@ -46,7 +46,7 @@ export const tipAction = createAction({
|
|
|
46
46
|
|
|
47
47
|
```typescript
|
|
48
48
|
// app/api/actions/tip/route.ts
|
|
49
|
-
import { createNextHandler } from '@
|
|
49
|
+
import { createNextHandler } from '@dipansrimany/mlink-sdk/next';
|
|
50
50
|
import { tipAction } from './action';
|
|
51
51
|
|
|
52
52
|
export const { GET, POST, OPTIONS } = createNextHandler(tipAction);
|
|
@@ -56,7 +56,7 @@ export const { GET, POST, OPTIONS } = createNextHandler(tipAction);
|
|
|
56
56
|
|
|
57
57
|
```typescript
|
|
58
58
|
import express from 'express';
|
|
59
|
-
import { createExpressHandler } from '@
|
|
59
|
+
import { createExpressHandler } from '@dipansrimany/mlink-sdk/express';
|
|
60
60
|
import { tipAction } from './action';
|
|
61
61
|
|
|
62
62
|
const app = express();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { A as Action } from '../builders-CN5ijFpW.mjs';
|
|
3
|
+
import '../types-CAnUIaVe.mjs';
|
|
3
4
|
|
|
4
5
|
declare function createExpressHandler(action: Action, RouterClass: new () => Router): Router;
|
|
5
6
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { A as Action } from '../builders-CJNt88dM.js';
|
|
3
|
+
import '../types-CAnUIaVe.js';
|
|
3
4
|
|
|
4
5
|
declare function createExpressHandler(action: Action, RouterClass: new () => Router): Router;
|
|
5
6
|
|
package/dist/adapters/next.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as ActionMetadata, a as TransactionResponse } from '../types-CAnUIaVe.mjs';
|
|
2
2
|
import { NextResponse, NextRequest } from 'next/server';
|
|
3
|
+
import { A as Action } from '../builders-CN5ijFpW.mjs';
|
|
3
4
|
|
|
4
5
|
declare function createNextHandler(action: Action): {
|
|
5
6
|
GET: () => Promise<NextResponse<ActionMetadata> | NextResponse<{
|
package/dist/adapters/next.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as ActionMetadata, a as TransactionResponse } from '../types-CAnUIaVe.js';
|
|
2
2
|
import { NextResponse, NextRequest } from 'next/server';
|
|
3
|
+
import { A as Action } from '../builders-CJNt88dM.js';
|
|
3
4
|
|
|
4
5
|
declare function createNextHandler(action: Action): {
|
|
5
6
|
GET: () => Promise<NextResponse<ActionMetadata> | NextResponse<{
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { f as ActionDefinition, A as ActionMetadata, T as TransactionRequest, a as TransactionResponse, c as ActionButton } from './types-CAnUIaVe.js';
|
|
2
|
+
|
|
3
|
+
declare function button(config: {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}): ActionButton;
|
|
8
|
+
declare function input(config: {
|
|
9
|
+
label: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}): ActionButton;
|
|
13
|
+
interface Action {
|
|
14
|
+
getMetadata(): ActionMetadata;
|
|
15
|
+
handleRequest(request: TransactionRequest): Promise<TransactionResponse>;
|
|
16
|
+
}
|
|
17
|
+
declare function createAction(definition: ActionDefinition): Action;
|
|
18
|
+
|
|
19
|
+
export { type Action as A, button as b, createAction as c, input as i };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { f as ActionDefinition, A as ActionMetadata, T as TransactionRequest, a as TransactionResponse, c as ActionButton } from './types-CAnUIaVe.mjs';
|
|
2
|
+
|
|
3
|
+
declare function button(config: {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}): ActionButton;
|
|
8
|
+
declare function input(config: {
|
|
9
|
+
label: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}): ActionButton;
|
|
13
|
+
interface Action {
|
|
14
|
+
getMetadata(): ActionMetadata;
|
|
15
|
+
handleRequest(request: TransactionRequest): Promise<TransactionResponse>;
|
|
16
|
+
}
|
|
17
|
+
declare function createAction(definition: ActionDefinition): Action;
|
|
18
|
+
|
|
19
|
+
export { type Action as A, button as b, createAction as c, input as i };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { V as ValidationResult, A as ActionMetadata, T as TransactionRequest, a as TransactionResponse, C as ChainConfig } from './
|
|
2
|
-
export {
|
|
1
|
+
import { V as ValidationResult, A as ActionMetadata, T as TransactionRequest, a as TransactionResponse, C as ChainConfig } from './types-CAnUIaVe.mjs';
|
|
2
|
+
export { c as ActionButton, g as ActionContext, f as ActionDefinition, d as ActionError, e as ActionHandler, b as ActionType, E as EVMTransaction } from './types-CAnUIaVe.mjs';
|
|
3
|
+
export { A as Action, b as button, c as createAction, i as input } from './builders-CN5ijFpW.mjs';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
declare const ActionMetadataSchema: z.ZodObject<{
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { V as ValidationResult, A as ActionMetadata, T as TransactionRequest, a as TransactionResponse, C as ChainConfig } from './
|
|
2
|
-
export {
|
|
1
|
+
import { V as ValidationResult, A as ActionMetadata, T as TransactionRequest, a as TransactionResponse, C as ChainConfig } from './types-CAnUIaVe.js';
|
|
2
|
+
export { c as ActionButton, g as ActionContext, f as ActionDefinition, d as ActionError, e as ActionHandler, b as ActionType, E as EVMTransaction } from './types-CAnUIaVe.js';
|
|
3
|
+
export { A as Action, b as button, c as createAction, i as input } from './builders-CJNt88dM.js';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
declare const ActionMetadataSchema: z.ZodObject<{
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { E as EVMTransaction, C as ChainConfig, A as ActionMetadata } from '../types-CAnUIaVe.mjs';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
type MlinkStatus = 'idle' | 'loading' | 'ready' | 'executing' | 'success' | 'error';
|
|
6
|
+
interface MlinkInstance {
|
|
7
|
+
status: MlinkStatus;
|
|
8
|
+
metadata: ActionMetadata | null;
|
|
9
|
+
error: string | null;
|
|
10
|
+
url: string;
|
|
11
|
+
refresh: () => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
interface MlinkAdapter {
|
|
14
|
+
connect: () => Promise<string>;
|
|
15
|
+
signAndSendTransaction: (transaction: EVMTransaction) => Promise<string>;
|
|
16
|
+
isConnected: () => boolean;
|
|
17
|
+
getAddress: () => string | null;
|
|
18
|
+
}
|
|
19
|
+
interface WagmiAdapterConfig {
|
|
20
|
+
sendTransaction: (args: {
|
|
21
|
+
to: `0x${string}`;
|
|
22
|
+
value: bigint;
|
|
23
|
+
data: `0x${string}`;
|
|
24
|
+
chainId: number;
|
|
25
|
+
}) => Promise<`0x${string}`>;
|
|
26
|
+
address: `0x${string}` | undefined;
|
|
27
|
+
isConnected: boolean;
|
|
28
|
+
connect: () => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
interface EthersAdapterConfig {
|
|
31
|
+
signer: {
|
|
32
|
+
getAddress: () => Promise<string>;
|
|
33
|
+
sendTransaction: (tx: {
|
|
34
|
+
to: string;
|
|
35
|
+
value: bigint;
|
|
36
|
+
data: string;
|
|
37
|
+
chainId: number;
|
|
38
|
+
}) => Promise<{
|
|
39
|
+
hash: string;
|
|
40
|
+
wait: () => Promise<unknown>;
|
|
41
|
+
}>;
|
|
42
|
+
} | null;
|
|
43
|
+
connect: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
interface MlinkTheme {
|
|
46
|
+
'--mlink-bg-primary': string;
|
|
47
|
+
'--mlink-bg-secondary': string;
|
|
48
|
+
'--mlink-border-color': string;
|
|
49
|
+
'--mlink-text-primary': string;
|
|
50
|
+
'--mlink-text-secondary': string;
|
|
51
|
+
'--mlink-text-link': string;
|
|
52
|
+
'--mlink-button-bg': string;
|
|
53
|
+
'--mlink-button-text': string;
|
|
54
|
+
'--mlink-button-hover': string;
|
|
55
|
+
'--mlink-button-disabled': string;
|
|
56
|
+
'--mlink-input-bg': string;
|
|
57
|
+
'--mlink-input-border': string;
|
|
58
|
+
'--mlink-input-text': string;
|
|
59
|
+
'--mlink-input-placeholder': string;
|
|
60
|
+
'--mlink-success': string;
|
|
61
|
+
'--mlink-error': string;
|
|
62
|
+
'--mlink-warning': string;
|
|
63
|
+
'--mlink-border-radius': string;
|
|
64
|
+
'--mlink-button-radius': string;
|
|
65
|
+
'--mlink-input-radius': string;
|
|
66
|
+
'--mlink-shadow': string;
|
|
67
|
+
}
|
|
68
|
+
type MlinkThemePreset = 'light' | 'dark' | 'mantle';
|
|
69
|
+
interface MlinkProviderConfig {
|
|
70
|
+
theme?: Partial<MlinkTheme> | MlinkThemePreset;
|
|
71
|
+
defaultChain?: ChainConfig;
|
|
72
|
+
}
|
|
73
|
+
interface MlinkProps {
|
|
74
|
+
url: string;
|
|
75
|
+
adapter: MlinkAdapter;
|
|
76
|
+
theme?: Partial<MlinkTheme> | MlinkThemePreset;
|
|
77
|
+
onSuccess?: (txHash: string, action: string) => void;
|
|
78
|
+
onError?: (error: string) => void;
|
|
79
|
+
className?: string;
|
|
80
|
+
stylePreset?: 'default' | 'compact' | 'minimal';
|
|
81
|
+
}
|
|
82
|
+
interface ActionButtonProps {
|
|
83
|
+
label: string;
|
|
84
|
+
value: string;
|
|
85
|
+
type: 'button' | 'input';
|
|
86
|
+
placeholder?: string;
|
|
87
|
+
disabled?: boolean;
|
|
88
|
+
loading?: boolean;
|
|
89
|
+
onClick: (value: string, input?: string) => void;
|
|
90
|
+
}
|
|
91
|
+
interface ExecutionResult {
|
|
92
|
+
success: boolean;
|
|
93
|
+
txHash?: string;
|
|
94
|
+
error?: string;
|
|
95
|
+
message?: string;
|
|
96
|
+
}
|
|
97
|
+
interface UseMlinkOptions {
|
|
98
|
+
refreshInterval?: number;
|
|
99
|
+
enabled?: boolean;
|
|
100
|
+
}
|
|
101
|
+
interface UseExecuteMlinkReturn {
|
|
102
|
+
execute: (action: string, input?: string) => Promise<ExecutionResult>;
|
|
103
|
+
status: MlinkStatus;
|
|
104
|
+
txHash: string | null;
|
|
105
|
+
error: string | null;
|
|
106
|
+
reset: () => void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare function Mlink({ url, adapter, theme: themeProp, onSuccess, onError, className, stylePreset, }: MlinkProps): react_jsx_runtime.JSX.Element;
|
|
110
|
+
|
|
111
|
+
interface MlinkContextValue {
|
|
112
|
+
theme: MlinkTheme;
|
|
113
|
+
defaultChain: ChainConfig;
|
|
114
|
+
}
|
|
115
|
+
interface MlinkProviderProps extends MlinkProviderConfig {
|
|
116
|
+
children: React.ReactNode;
|
|
117
|
+
}
|
|
118
|
+
declare function MlinkProvider({ children, theme, defaultChain, }: MlinkProviderProps): react_jsx_runtime.JSX.Element;
|
|
119
|
+
declare function useMlinkContext(): MlinkContextValue;
|
|
120
|
+
|
|
121
|
+
declare function useMlink(url: string, options?: UseMlinkOptions): MlinkInstance;
|
|
122
|
+
|
|
123
|
+
interface UseExecuteMlinkOptions {
|
|
124
|
+
adapter: MlinkAdapter;
|
|
125
|
+
actionUrl: string;
|
|
126
|
+
onSuccess?: (txHash: string, action: string) => void;
|
|
127
|
+
onError?: (error: string) => void;
|
|
128
|
+
}
|
|
129
|
+
declare function useExecuteMlink(options: UseExecuteMlinkOptions): UseExecuteMlinkReturn;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Create a Mlink adapter from wagmi hooks
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```tsx
|
|
136
|
+
* import { useAccount, useConnect, useSendTransaction } from 'wagmi';
|
|
137
|
+
* import { useMlinkWagmiAdapter } from '@dipansrimany/mlink-sdk/react';
|
|
138
|
+
*
|
|
139
|
+
* function MyComponent() {
|
|
140
|
+
* const { address, isConnected } = useAccount();
|
|
141
|
+
* const { connectAsync, connectors } = useConnect();
|
|
142
|
+
* const { sendTransactionAsync } = useSendTransaction();
|
|
143
|
+
*
|
|
144
|
+
* const adapter = useMlinkWagmiAdapter({
|
|
145
|
+
* address,
|
|
146
|
+
* isConnected,
|
|
147
|
+
* connect: async () => {
|
|
148
|
+
* await connectAsync({ connector: connectors[0] });
|
|
149
|
+
* },
|
|
150
|
+
* sendTransaction: sendTransactionAsync,
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* return <Mlink url="..." adapter={adapter} />;
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function useMlinkWagmiAdapter(config: WagmiAdapterConfig): MlinkAdapter;
|
|
158
|
+
/**
|
|
159
|
+
* Create a Mlink adapter from ethers.js signer
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```tsx
|
|
163
|
+
* import { useSigner } from 'some-ethers-provider';
|
|
164
|
+
* import { useMlinkEthersAdapter } from '@dipansrimany/mlink-sdk/react';
|
|
165
|
+
*
|
|
166
|
+
* function MyComponent() {
|
|
167
|
+
* const { signer, connect } = useSigner();
|
|
168
|
+
*
|
|
169
|
+
* const adapter = useMlinkEthersAdapter({
|
|
170
|
+
* signer,
|
|
171
|
+
* connect,
|
|
172
|
+
* });
|
|
173
|
+
*
|
|
174
|
+
* return <Mlink url="..." adapter={adapter} />;
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function useMlinkEthersAdapter(config: EthersAdapterConfig): MlinkAdapter;
|
|
179
|
+
/**
|
|
180
|
+
* Create a custom Mlink adapter
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```tsx
|
|
184
|
+
* import { createMlinkAdapter } from '@dipansrimany/mlink-sdk/react';
|
|
185
|
+
*
|
|
186
|
+
* const adapter = createMlinkAdapter({
|
|
187
|
+
* connect: async () => {
|
|
188
|
+
* // Your connect logic
|
|
189
|
+
* return '0x...';
|
|
190
|
+
* },
|
|
191
|
+
* signAndSendTransaction: async (tx) => {
|
|
192
|
+
* // Your transaction logic
|
|
193
|
+
* return '0x...txHash';
|
|
194
|
+
* },
|
|
195
|
+
* isConnected: () => true,
|
|
196
|
+
* getAddress: () => '0x...',
|
|
197
|
+
* });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
declare function createMlinkAdapter(adapter: MlinkAdapter): MlinkAdapter;
|
|
201
|
+
|
|
202
|
+
declare const lightTheme: MlinkTheme;
|
|
203
|
+
declare const darkTheme: MlinkTheme;
|
|
204
|
+
declare const mantleTheme: MlinkTheme;
|
|
205
|
+
declare const themePresets: Record<MlinkThemePreset, MlinkTheme>;
|
|
206
|
+
declare function resolveTheme(theme?: Partial<MlinkTheme> | MlinkThemePreset): MlinkTheme;
|
|
207
|
+
|
|
208
|
+
export { type ActionButtonProps, type EthersAdapterConfig, type ExecutionResult, Mlink, type MlinkAdapter, Mlink as MlinkComponent, type MlinkInstance, type MlinkProps, MlinkProvider, type MlinkProviderConfig, type MlinkStatus, type MlinkTheme, type MlinkThemePreset, type UseExecuteMlinkReturn, type UseMlinkOptions, type WagmiAdapterConfig, createMlinkAdapter, darkTheme, lightTheme, mantleTheme, resolveTheme, themePresets, useExecuteMlink, useMlink, useMlinkContext, useMlinkEthersAdapter, useMlinkWagmiAdapter };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { E as EVMTransaction, C as ChainConfig, A as ActionMetadata } from '../types-CAnUIaVe.js';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
type MlinkStatus = 'idle' | 'loading' | 'ready' | 'executing' | 'success' | 'error';
|
|
6
|
+
interface MlinkInstance {
|
|
7
|
+
status: MlinkStatus;
|
|
8
|
+
metadata: ActionMetadata | null;
|
|
9
|
+
error: string | null;
|
|
10
|
+
url: string;
|
|
11
|
+
refresh: () => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
interface MlinkAdapter {
|
|
14
|
+
connect: () => Promise<string>;
|
|
15
|
+
signAndSendTransaction: (transaction: EVMTransaction) => Promise<string>;
|
|
16
|
+
isConnected: () => boolean;
|
|
17
|
+
getAddress: () => string | null;
|
|
18
|
+
}
|
|
19
|
+
interface WagmiAdapterConfig {
|
|
20
|
+
sendTransaction: (args: {
|
|
21
|
+
to: `0x${string}`;
|
|
22
|
+
value: bigint;
|
|
23
|
+
data: `0x${string}`;
|
|
24
|
+
chainId: number;
|
|
25
|
+
}) => Promise<`0x${string}`>;
|
|
26
|
+
address: `0x${string}` | undefined;
|
|
27
|
+
isConnected: boolean;
|
|
28
|
+
connect: () => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
interface EthersAdapterConfig {
|
|
31
|
+
signer: {
|
|
32
|
+
getAddress: () => Promise<string>;
|
|
33
|
+
sendTransaction: (tx: {
|
|
34
|
+
to: string;
|
|
35
|
+
value: bigint;
|
|
36
|
+
data: string;
|
|
37
|
+
chainId: number;
|
|
38
|
+
}) => Promise<{
|
|
39
|
+
hash: string;
|
|
40
|
+
wait: () => Promise<unknown>;
|
|
41
|
+
}>;
|
|
42
|
+
} | null;
|
|
43
|
+
connect: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
interface MlinkTheme {
|
|
46
|
+
'--mlink-bg-primary': string;
|
|
47
|
+
'--mlink-bg-secondary': string;
|
|
48
|
+
'--mlink-border-color': string;
|
|
49
|
+
'--mlink-text-primary': string;
|
|
50
|
+
'--mlink-text-secondary': string;
|
|
51
|
+
'--mlink-text-link': string;
|
|
52
|
+
'--mlink-button-bg': string;
|
|
53
|
+
'--mlink-button-text': string;
|
|
54
|
+
'--mlink-button-hover': string;
|
|
55
|
+
'--mlink-button-disabled': string;
|
|
56
|
+
'--mlink-input-bg': string;
|
|
57
|
+
'--mlink-input-border': string;
|
|
58
|
+
'--mlink-input-text': string;
|
|
59
|
+
'--mlink-input-placeholder': string;
|
|
60
|
+
'--mlink-success': string;
|
|
61
|
+
'--mlink-error': string;
|
|
62
|
+
'--mlink-warning': string;
|
|
63
|
+
'--mlink-border-radius': string;
|
|
64
|
+
'--mlink-button-radius': string;
|
|
65
|
+
'--mlink-input-radius': string;
|
|
66
|
+
'--mlink-shadow': string;
|
|
67
|
+
}
|
|
68
|
+
type MlinkThemePreset = 'light' | 'dark' | 'mantle';
|
|
69
|
+
interface MlinkProviderConfig {
|
|
70
|
+
theme?: Partial<MlinkTheme> | MlinkThemePreset;
|
|
71
|
+
defaultChain?: ChainConfig;
|
|
72
|
+
}
|
|
73
|
+
interface MlinkProps {
|
|
74
|
+
url: string;
|
|
75
|
+
adapter: MlinkAdapter;
|
|
76
|
+
theme?: Partial<MlinkTheme> | MlinkThemePreset;
|
|
77
|
+
onSuccess?: (txHash: string, action: string) => void;
|
|
78
|
+
onError?: (error: string) => void;
|
|
79
|
+
className?: string;
|
|
80
|
+
stylePreset?: 'default' | 'compact' | 'minimal';
|
|
81
|
+
}
|
|
82
|
+
interface ActionButtonProps {
|
|
83
|
+
label: string;
|
|
84
|
+
value: string;
|
|
85
|
+
type: 'button' | 'input';
|
|
86
|
+
placeholder?: string;
|
|
87
|
+
disabled?: boolean;
|
|
88
|
+
loading?: boolean;
|
|
89
|
+
onClick: (value: string, input?: string) => void;
|
|
90
|
+
}
|
|
91
|
+
interface ExecutionResult {
|
|
92
|
+
success: boolean;
|
|
93
|
+
txHash?: string;
|
|
94
|
+
error?: string;
|
|
95
|
+
message?: string;
|
|
96
|
+
}
|
|
97
|
+
interface UseMlinkOptions {
|
|
98
|
+
refreshInterval?: number;
|
|
99
|
+
enabled?: boolean;
|
|
100
|
+
}
|
|
101
|
+
interface UseExecuteMlinkReturn {
|
|
102
|
+
execute: (action: string, input?: string) => Promise<ExecutionResult>;
|
|
103
|
+
status: MlinkStatus;
|
|
104
|
+
txHash: string | null;
|
|
105
|
+
error: string | null;
|
|
106
|
+
reset: () => void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare function Mlink({ url, adapter, theme: themeProp, onSuccess, onError, className, stylePreset, }: MlinkProps): react_jsx_runtime.JSX.Element;
|
|
110
|
+
|
|
111
|
+
interface MlinkContextValue {
|
|
112
|
+
theme: MlinkTheme;
|
|
113
|
+
defaultChain: ChainConfig;
|
|
114
|
+
}
|
|
115
|
+
interface MlinkProviderProps extends MlinkProviderConfig {
|
|
116
|
+
children: React.ReactNode;
|
|
117
|
+
}
|
|
118
|
+
declare function MlinkProvider({ children, theme, defaultChain, }: MlinkProviderProps): react_jsx_runtime.JSX.Element;
|
|
119
|
+
declare function useMlinkContext(): MlinkContextValue;
|
|
120
|
+
|
|
121
|
+
declare function useMlink(url: string, options?: UseMlinkOptions): MlinkInstance;
|
|
122
|
+
|
|
123
|
+
interface UseExecuteMlinkOptions {
|
|
124
|
+
adapter: MlinkAdapter;
|
|
125
|
+
actionUrl: string;
|
|
126
|
+
onSuccess?: (txHash: string, action: string) => void;
|
|
127
|
+
onError?: (error: string) => void;
|
|
128
|
+
}
|
|
129
|
+
declare function useExecuteMlink(options: UseExecuteMlinkOptions): UseExecuteMlinkReturn;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Create a Mlink adapter from wagmi hooks
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```tsx
|
|
136
|
+
* import { useAccount, useConnect, useSendTransaction } from 'wagmi';
|
|
137
|
+
* import { useMlinkWagmiAdapter } from '@dipansrimany/mlink-sdk/react';
|
|
138
|
+
*
|
|
139
|
+
* function MyComponent() {
|
|
140
|
+
* const { address, isConnected } = useAccount();
|
|
141
|
+
* const { connectAsync, connectors } = useConnect();
|
|
142
|
+
* const { sendTransactionAsync } = useSendTransaction();
|
|
143
|
+
*
|
|
144
|
+
* const adapter = useMlinkWagmiAdapter({
|
|
145
|
+
* address,
|
|
146
|
+
* isConnected,
|
|
147
|
+
* connect: async () => {
|
|
148
|
+
* await connectAsync({ connector: connectors[0] });
|
|
149
|
+
* },
|
|
150
|
+
* sendTransaction: sendTransactionAsync,
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* return <Mlink url="..." adapter={adapter} />;
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function useMlinkWagmiAdapter(config: WagmiAdapterConfig): MlinkAdapter;
|
|
158
|
+
/**
|
|
159
|
+
* Create a Mlink adapter from ethers.js signer
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```tsx
|
|
163
|
+
* import { useSigner } from 'some-ethers-provider';
|
|
164
|
+
* import { useMlinkEthersAdapter } from '@dipansrimany/mlink-sdk/react';
|
|
165
|
+
*
|
|
166
|
+
* function MyComponent() {
|
|
167
|
+
* const { signer, connect } = useSigner();
|
|
168
|
+
*
|
|
169
|
+
* const adapter = useMlinkEthersAdapter({
|
|
170
|
+
* signer,
|
|
171
|
+
* connect,
|
|
172
|
+
* });
|
|
173
|
+
*
|
|
174
|
+
* return <Mlink url="..." adapter={adapter} />;
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function useMlinkEthersAdapter(config: EthersAdapterConfig): MlinkAdapter;
|
|
179
|
+
/**
|
|
180
|
+
* Create a custom Mlink adapter
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```tsx
|
|
184
|
+
* import { createMlinkAdapter } from '@dipansrimany/mlink-sdk/react';
|
|
185
|
+
*
|
|
186
|
+
* const adapter = createMlinkAdapter({
|
|
187
|
+
* connect: async () => {
|
|
188
|
+
* // Your connect logic
|
|
189
|
+
* return '0x...';
|
|
190
|
+
* },
|
|
191
|
+
* signAndSendTransaction: async (tx) => {
|
|
192
|
+
* // Your transaction logic
|
|
193
|
+
* return '0x...txHash';
|
|
194
|
+
* },
|
|
195
|
+
* isConnected: () => true,
|
|
196
|
+
* getAddress: () => '0x...',
|
|
197
|
+
* });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
declare function createMlinkAdapter(adapter: MlinkAdapter): MlinkAdapter;
|
|
201
|
+
|
|
202
|
+
declare const lightTheme: MlinkTheme;
|
|
203
|
+
declare const darkTheme: MlinkTheme;
|
|
204
|
+
declare const mantleTheme: MlinkTheme;
|
|
205
|
+
declare const themePresets: Record<MlinkThemePreset, MlinkTheme>;
|
|
206
|
+
declare function resolveTheme(theme?: Partial<MlinkTheme> | MlinkThemePreset): MlinkTheme;
|
|
207
|
+
|
|
208
|
+
export { type ActionButtonProps, type EthersAdapterConfig, type ExecutionResult, Mlink, type MlinkAdapter, Mlink as MlinkComponent, type MlinkInstance, type MlinkProps, MlinkProvider, type MlinkProviderConfig, type MlinkStatus, type MlinkTheme, type MlinkThemePreset, type UseExecuteMlinkReturn, type UseMlinkOptions, type WagmiAdapterConfig, createMlinkAdapter, darkTheme, lightTheme, mantleTheme, resolveTheme, themePresets, useExecuteMlink, useMlink, useMlinkContext, useMlinkEthersAdapter, useMlinkWagmiAdapter };
|