@0xobelisk/react 1.2.0-pre.64
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/LICENSE +92 -0
- package/README.md +564 -0
- package/dist/chunk-2WEYKH27.mjs +344 -0
- package/dist/chunk-2WEYKH27.mjs.map +1 -0
- package/dist/chunk-LQ3XXOG4.mjs +342 -0
- package/dist/chunk-LQ3XXOG4.mjs.map +1 -0
- package/dist/chunk-TTYSS65P.mjs +345 -0
- package/dist/chunk-TTYSS65P.mjs.map +1 -0
- package/dist/chunk-XI35QBSQ.mjs +338 -0
- package/dist/chunk-XI35QBSQ.mjs.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +374 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +27 -0
- package/dist/index.mjs.map +1 -0
- package/dist/sui/config.d.ts +52 -0
- package/dist/sui/hooks.d.ts +123 -0
- package/dist/sui/index.d.mts +353 -0
- package/dist/sui/index.d.ts +353 -0
- package/dist/sui/index.js +374 -0
- package/dist/sui/index.js.map +1 -0
- package/dist/sui/index.mjs +27 -0
- package/dist/sui/index.mjs.map +1 -0
- package/dist/sui/provider.d.ts +137 -0
- package/dist/sui/types.d.ts +87 -0
- package/dist/sui/utils.d.ts +35 -0
- package/package.json +103 -0
- package/src/index.ts +16 -0
- package/src/sui/config.ts +90 -0
- package/src/sui/hooks.ts +144 -0
- package/src/sui/index.ts +37 -0
- package/src/sui/provider.tsx +341 -0
- package/src/sui/types.ts +99 -0
- package/src/sui/utils.ts +192 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { SuiMoveNormalizedModules, Dubhe } from '@0xobelisk/sui-client';
|
|
2
|
+
import type { DubheGraphqlClient } from '@0xobelisk/graphql-client';
|
|
3
|
+
import type { DubheECSWorld } from '@0xobelisk/ecs';
|
|
4
|
+
/**
|
|
5
|
+
* Network type
|
|
6
|
+
*/
|
|
7
|
+
export type NetworkType = 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
8
|
+
/**
|
|
9
|
+
* Modern Dubhe client configuration for auto-initialization
|
|
10
|
+
*/
|
|
11
|
+
export interface DubheConfig {
|
|
12
|
+
/** Network type */
|
|
13
|
+
network: NetworkType;
|
|
14
|
+
/** Contract package ID */
|
|
15
|
+
packageId: string;
|
|
16
|
+
/** Dubhe Schema ID (optional, for enhanced features) */
|
|
17
|
+
dubheSchemaId: string;
|
|
18
|
+
/** Contract metadata (required for contract instantiation) */
|
|
19
|
+
metadata: SuiMoveNormalizedModules;
|
|
20
|
+
/** Dubhe metadata (enables GraphQL/ECS features) */
|
|
21
|
+
dubheMetadata?: any;
|
|
22
|
+
/** Authentication credentials */
|
|
23
|
+
credentials?: {
|
|
24
|
+
secretKey?: string;
|
|
25
|
+
mnemonics?: string;
|
|
26
|
+
};
|
|
27
|
+
/** Service endpoints configuration */
|
|
28
|
+
endpoints?: {
|
|
29
|
+
graphql?: string;
|
|
30
|
+
websocket?: string;
|
|
31
|
+
};
|
|
32
|
+
/** Performance and behavior options */
|
|
33
|
+
options?: {
|
|
34
|
+
/** Enable batch query optimization */
|
|
35
|
+
enableBatchOptimization?: boolean;
|
|
36
|
+
/** Default cache timeout (milliseconds) */
|
|
37
|
+
cacheTimeout?: number;
|
|
38
|
+
/** Request debounce delay (milliseconds) */
|
|
39
|
+
debounceMs?: number;
|
|
40
|
+
/** Auto-reconnect on WebSocket errors */
|
|
41
|
+
reconnectOnError?: boolean;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Return type for the main useDubhe hook
|
|
46
|
+
*/
|
|
47
|
+
export interface DubheReturn {
|
|
48
|
+
/** Dubhe contract instance with enhanced methods */
|
|
49
|
+
contract: Dubhe & {
|
|
50
|
+
/** Enhanced transaction methods with options */
|
|
51
|
+
txWithOptions?: (system: string, method: string, options?: any) => (params: any) => Promise<any>;
|
|
52
|
+
/** Enhanced query methods with options */
|
|
53
|
+
queryWithOptions?: (system: string, method: string, options?: any) => (params: any) => Promise<any>;
|
|
54
|
+
};
|
|
55
|
+
/** GraphQL client (null if dubheMetadata not provided) */
|
|
56
|
+
graphqlClient: DubheGraphqlClient | null;
|
|
57
|
+
/** ECS World instance (null if GraphQL not available) */
|
|
58
|
+
ecsWorld: DubheECSWorld | null;
|
|
59
|
+
/** Contract metadata */
|
|
60
|
+
metadata: SuiMoveNormalizedModules;
|
|
61
|
+
/** Network type */
|
|
62
|
+
network: NetworkType;
|
|
63
|
+
/** Package ID */
|
|
64
|
+
packageId: string;
|
|
65
|
+
/** Dubhe Schema ID (if provided) */
|
|
66
|
+
dubheSchemaId?: string;
|
|
67
|
+
/** User address */
|
|
68
|
+
address: string;
|
|
69
|
+
/** Configuration options used */
|
|
70
|
+
options?: {
|
|
71
|
+
enableBatchOptimization?: boolean;
|
|
72
|
+
cacheTimeout?: number;
|
|
73
|
+
debounceMs?: number;
|
|
74
|
+
reconnectOnError?: boolean;
|
|
75
|
+
};
|
|
76
|
+
/** Performance metrics */
|
|
77
|
+
metrics?: {
|
|
78
|
+
initTime?: number;
|
|
79
|
+
requestCount?: number;
|
|
80
|
+
lastActivity?: number;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Compatibility alias for DubheReturn
|
|
85
|
+
* @deprecated Use DubheReturn instead for better consistency
|
|
86
|
+
*/
|
|
87
|
+
export type ContractReturn = DubheReturn;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility Functions for Dubhe Configuration Management
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Configuration validation and error handling
|
|
6
|
+
* - Smart configuration merging with proper type safety
|
|
7
|
+
* - Type-safe configuration validation
|
|
8
|
+
*/
|
|
9
|
+
import type { DubheConfig } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Merge multiple configuration objects with proper deep merging
|
|
12
|
+
* Later configurations override earlier ones
|
|
13
|
+
*
|
|
14
|
+
* @param baseConfig - Base configuration (usually defaults)
|
|
15
|
+
* @param overrideConfig - Override configuration (user provided)
|
|
16
|
+
* @returns Merged configuration
|
|
17
|
+
*/
|
|
18
|
+
export declare function mergeConfigurations(baseConfig: Partial<DubheConfig>, overrideConfig?: Partial<DubheConfig>): Partial<DubheConfig>;
|
|
19
|
+
/**
|
|
20
|
+
* Validate configuration and ensure required fields are present
|
|
21
|
+
* Throws descriptive errors for missing required fields
|
|
22
|
+
*
|
|
23
|
+
* @param config - Configuration to validate
|
|
24
|
+
* @returns Validated and typed configuration
|
|
25
|
+
* @throws Error if required fields are missing or invalid
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateConfig(config: Partial<DubheConfig>): DubheConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Generate a configuration summary for debugging
|
|
30
|
+
* Hides sensitive information like private keys
|
|
31
|
+
*
|
|
32
|
+
* @param config - Configuration to summarize
|
|
33
|
+
* @returns Safe configuration summary
|
|
34
|
+
*/
|
|
35
|
+
export declare function getConfigSummary(config: DubheConfig): object;
|
package/package.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@0xobelisk/react",
|
|
3
|
+
"version": "1.2.0-pre.64",
|
|
4
|
+
"description": "React integration for Dubhe framework with Sui blockchain support",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dubhe",
|
|
7
|
+
"react",
|
|
8
|
+
"blockchain",
|
|
9
|
+
"sui",
|
|
10
|
+
"web3"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/0xobelisk/dubhe/tree/main/packages/react#readme",
|
|
13
|
+
"bugs": "https://github.com/0xobelisk/dubhe/issues",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/0xobelisk/dubhe.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"author": "team@obelisk.build",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"source": "./src/index.ts",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./sui": {
|
|
28
|
+
"source": "./src/sui/index.ts",
|
|
29
|
+
"import": "./dist/sui/index.mjs",
|
|
30
|
+
"require": "./dist/sui/index.js",
|
|
31
|
+
"types": "./dist/sui/index.d.ts"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"main": "./dist/index.js",
|
|
35
|
+
"module": "./dist/index.mjs",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"src"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@nanostores/react": "^0.8.0",
|
|
43
|
+
"nanostores": "^0.11.4",
|
|
44
|
+
"@0xobelisk/ecs": "1.2.0-pre.64",
|
|
45
|
+
"@0xobelisk/graphql-client": "1.2.0-pre.64"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^20.8.7",
|
|
49
|
+
"@types/react": "^19.0.0",
|
|
50
|
+
"@types/react-dom": "^19.0.0",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
52
|
+
"@typescript-eslint/parser": "^6.8.0",
|
|
53
|
+
"eslint": "^8.56.0",
|
|
54
|
+
"eslint-config-prettier": "^9.1.0",
|
|
55
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
56
|
+
"prettier": "3.3.3",
|
|
57
|
+
"react": "^18.0.0",
|
|
58
|
+
"react-dom": "^18.0.0",
|
|
59
|
+
"tsup": "^7.1.0",
|
|
60
|
+
"typescript": "^5.2.2",
|
|
61
|
+
"@0xobelisk/sui-client": "1.2.0-pre.64"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
65
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
66
|
+
"zod": "^3.25.0 || ^4.0.0",
|
|
67
|
+
"@0xobelisk/sui-client": "1.2.0-pre.64"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"@0xobelisk/sui-client": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"react": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"react-dom": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"engines": {
|
|
81
|
+
"node": ">=18.0.0"
|
|
82
|
+
},
|
|
83
|
+
"publishConfig": {
|
|
84
|
+
"access": "public"
|
|
85
|
+
},
|
|
86
|
+
"scripts": {
|
|
87
|
+
"build": "npm run build:types && npm run build:tsup",
|
|
88
|
+
"build:tsup": "tsup ./src/index.ts ./src/sui/index.ts --format esm,cjs --sourcemap --dts",
|
|
89
|
+
"build:types": "tsc --build",
|
|
90
|
+
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
91
|
+
"format": "prettier --write .",
|
|
92
|
+
"format:check": "prettier --check .",
|
|
93
|
+
"format:fix": "prettier --write '**/*.{ts,tsx,json,md}'",
|
|
94
|
+
"lint:fix": "eslint . --ext .ts,.tsx --fix",
|
|
95
|
+
"test": "pnpm test:typecheck",
|
|
96
|
+
"test:typecheck": "tsc --noEmit",
|
|
97
|
+
"type-check": "tsc --noEmit",
|
|
98
|
+
"validate": "pnpm format:check && pnpm type-check",
|
|
99
|
+
"watch": "pnpm run clean & pnpm run watch:types & pnpm run watch:tsup",
|
|
100
|
+
"watch:tsup": "tsup ./src/index.ts ./src/sui/index.ts --format esm,cjs --clean --splitting --watch --dts",
|
|
101
|
+
"watch:types": "tsc --watch"
|
|
102
|
+
}
|
|
103
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @0xobelisk/react - Modern Dubhe React Integration
|
|
3
|
+
*
|
|
4
|
+
* 🚀 Provides simple, powerful React experience for multi-chain blockchain development
|
|
5
|
+
*
|
|
6
|
+
* Currently supported:
|
|
7
|
+
* - Sui blockchain ✅
|
|
8
|
+
* - Aptos blockchain (coming soon)
|
|
9
|
+
* - Initia blockchain (coming soon)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Sui integration
|
|
13
|
+
export * from './sui/index';
|
|
14
|
+
// TODO: Future extensions
|
|
15
|
+
// export * from './aptos/index';
|
|
16
|
+
// export * from './initia/index';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Management for Dubhe React Integration
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Type-safe configuration interface
|
|
6
|
+
* - Configuration validation and error handling
|
|
7
|
+
* - Smart merging of defaults and explicit config
|
|
8
|
+
* - No environment variable handling (developers should handle environment variables themselves)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useMemo } from 'react';
|
|
12
|
+
import type { DubheConfig, NetworkType } from './types';
|
|
13
|
+
import { mergeConfigurations, validateConfig } from './utils';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Default configuration object with sensible defaults
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_CONFIG: Partial<DubheConfig> = {
|
|
19
|
+
endpoints: {
|
|
20
|
+
graphql: 'http://localhost:4000/graphql',
|
|
21
|
+
websocket: 'ws://localhost:4000/graphql'
|
|
22
|
+
},
|
|
23
|
+
options: {
|
|
24
|
+
enableBatchOptimization: true,
|
|
25
|
+
cacheTimeout: 5000,
|
|
26
|
+
debounceMs: 100,
|
|
27
|
+
reconnectOnError: true
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Configuration Hook: useDubheConfig
|
|
33
|
+
*
|
|
34
|
+
* Merges defaults with explicit configuration provided by the developer
|
|
35
|
+
*
|
|
36
|
+
* Note: Environment variables should be handled by the developer before passing to this hook
|
|
37
|
+
*
|
|
38
|
+
* @param config - Complete or partial configuration object
|
|
39
|
+
* @returns Complete, validated DubheConfig
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // Basic usage with explicit config
|
|
44
|
+
* const config = useDubheConfig({
|
|
45
|
+
* network: 'testnet',
|
|
46
|
+
* packageId: '0x123...',
|
|
47
|
+
* metadata: contractMetadata,
|
|
48
|
+
* credentials: {
|
|
49
|
+
* secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY // Handle env vars yourself
|
|
50
|
+
* }
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // With helper function to handle environment variables
|
|
54
|
+
* const getConfigFromEnv = () => ({
|
|
55
|
+
* network: process.env.NEXT_PUBLIC_NETWORK as NetworkType,
|
|
56
|
+
* packageId: process.env.NEXT_PUBLIC_PACKAGE_ID,
|
|
57
|
+
* credentials: {
|
|
58
|
+
* secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY
|
|
59
|
+
* }
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* const config = useDubheConfig({
|
|
63
|
+
* ...getConfigFromEnv(),
|
|
64
|
+
* metadata: contractMetadata
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function useDubheConfig(config: Partial<DubheConfig>): DubheConfig {
|
|
69
|
+
// Memoize the stringified config to detect actual changes
|
|
70
|
+
const configKey = useMemo(() => {
|
|
71
|
+
return JSON.stringify(config);
|
|
72
|
+
}, [config]);
|
|
73
|
+
|
|
74
|
+
return useMemo(() => {
|
|
75
|
+
// Merge configurations: defaults -> user provided config
|
|
76
|
+
const mergedConfig = mergeConfigurations(DEFAULT_CONFIG, config);
|
|
77
|
+
|
|
78
|
+
// Validate the final configuration
|
|
79
|
+
const validatedConfig = validateConfig(mergedConfig);
|
|
80
|
+
|
|
81
|
+
// if (process.env.NODE_ENV === 'development') {
|
|
82
|
+
// console.log('🔧 Dubhe Config:', {
|
|
83
|
+
// ...validatedConfig,
|
|
84
|
+
// credentials: validatedConfig.credentials?.secretKey ? '[REDACTED]' : undefined
|
|
85
|
+
// });
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
return validatedConfig;
|
|
89
|
+
}, [configKey]);
|
|
90
|
+
}
|
package/src/sui/hooks.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modern Dubhe React Hooks - Provider Pattern
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - 🎯 Simple API design with Provider pattern
|
|
6
|
+
* - ⚡ Single client initialization with useRef
|
|
7
|
+
* - 🔧 Configuration-driven setup (developers handle environment variables themselves)
|
|
8
|
+
* - 🛡️ Complete type safety with strict TypeScript
|
|
9
|
+
* - 📦 Context-based client sharing across components
|
|
10
|
+
*/
|
|
11
|
+
import { Dubhe } from '@0xobelisk/sui-client';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
useDubheContext,
|
|
15
|
+
useDubheFromProvider,
|
|
16
|
+
useDubheContractFromProvider,
|
|
17
|
+
useDubheGraphQLFromProvider,
|
|
18
|
+
useDubheECSFromProvider
|
|
19
|
+
} from './provider';
|
|
20
|
+
import type { DubheConfig, DubheReturn } from './types';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Primary Hook: useDubhe
|
|
24
|
+
*
|
|
25
|
+
* Uses Provider pattern to access shared Dubhe clients with guaranteed single initialization.
|
|
26
|
+
* Must be used within a DubheProvider.
|
|
27
|
+
*
|
|
28
|
+
* @returns Complete Dubhe ecosystem with contract, GraphQL, ECS, and metadata
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // App setup with Provider
|
|
33
|
+
* function App() {
|
|
34
|
+
* const config = {
|
|
35
|
+
* network: 'devnet',
|
|
36
|
+
* packageId: '0x123...',
|
|
37
|
+
* metadata: contractMetadata,
|
|
38
|
+
* credentials: {
|
|
39
|
+
* secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY
|
|
40
|
+
* }
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* return (
|
|
44
|
+
* <DubheProvider config={config}>
|
|
45
|
+
* <MyDApp />
|
|
46
|
+
* </DubheProvider>
|
|
47
|
+
* );
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* // Component usage
|
|
51
|
+
* function MyDApp() {
|
|
52
|
+
* const { contract, address } = useDubhe();
|
|
53
|
+
* return <div>Connected as {address}</div>;
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function useDubhe(): DubheReturn {
|
|
58
|
+
return useDubheFromProvider();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Individual Instance Hook: useDubheContract
|
|
63
|
+
*
|
|
64
|
+
* Returns only the Dubhe contract instance from Provider context.
|
|
65
|
+
* More efficient than useDubhe() when only contract access is needed.
|
|
66
|
+
*
|
|
67
|
+
* @returns Dubhe contract instance
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* function TransactionComponent() {
|
|
72
|
+
* const contract = useDubheContract();
|
|
73
|
+
*
|
|
74
|
+
* const handleTransaction = async () => {
|
|
75
|
+
* const tx = new Transaction();
|
|
76
|
+
* await contract.tx.my_system.my_method({ tx });
|
|
77
|
+
* };
|
|
78
|
+
*
|
|
79
|
+
* return <button onClick={handleTransaction}>Execute</button>;
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function useDubheContract(): Dubhe {
|
|
84
|
+
return useDubheContractFromProvider();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Individual Instance Hook: useDubheGraphQL
|
|
89
|
+
*
|
|
90
|
+
* Returns only the GraphQL client from Provider context.
|
|
91
|
+
* More efficient than useDubhe() when only GraphQL access is needed.
|
|
92
|
+
*
|
|
93
|
+
* @returns GraphQL client instance (null if dubheMetadata not provided)
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* function DataComponent() {
|
|
98
|
+
* const graphqlClient = useDubheGraphQL();
|
|
99
|
+
*
|
|
100
|
+
* useEffect(() => {
|
|
101
|
+
* if (graphqlClient) {
|
|
102
|
+
* graphqlClient.query({ ... }).then(setData);
|
|
103
|
+
* }
|
|
104
|
+
* }, [graphqlClient]);
|
|
105
|
+
*
|
|
106
|
+
* return <div>{data && JSON.stringify(data)}</div>;
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export function useDubheGraphQL(): any | null {
|
|
111
|
+
return useDubheGraphQLFromProvider();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Individual Instance Hook: useDubheECS
|
|
116
|
+
*
|
|
117
|
+
* Returns only the ECS World instance from Provider context.
|
|
118
|
+
* More efficient than useDubhe() when only ECS access is needed.
|
|
119
|
+
*
|
|
120
|
+
* @returns ECS World instance (null if GraphQL client not available)
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* function ECSComponent() {
|
|
125
|
+
* const ecsWorld = useDubheECS();
|
|
126
|
+
*
|
|
127
|
+
* useEffect(() => {
|
|
128
|
+
* if (ecsWorld) {
|
|
129
|
+
* ecsWorld.getComponent('MyComponent').then(setComponent);
|
|
130
|
+
* }
|
|
131
|
+
* }, [ecsWorld]);
|
|
132
|
+
*
|
|
133
|
+
* return <div>ECS Component Data</div>;
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export function useDubheECS(): any | null {
|
|
138
|
+
return useDubheECSFromProvider();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Compatibility alias for useDubhe
|
|
143
|
+
*/
|
|
144
|
+
export const useContract = useDubhe;
|
package/src/sui/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @0xobelisk/react/sui - Modern Dubhe React Integration
|
|
3
|
+
*
|
|
4
|
+
* 🚀 Simple, powerful, type-safe Sui blockchain development experience
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - ⚡ Auto-initialization with environment variable support
|
|
8
|
+
* - 🔧 Configuration-driven setup with smart defaults
|
|
9
|
+
* - 🛡️ Complete type safety with strict TypeScript
|
|
10
|
+
* - 📦 Direct instance access without connection state management
|
|
11
|
+
* - 🎯 Intuitive API design following React best practices
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// ============ Type Exports ============
|
|
15
|
+
export type { NetworkType, DubheConfig, DubheReturn, ContractReturn } from './types';
|
|
16
|
+
|
|
17
|
+
// ============ Configuration Management ============
|
|
18
|
+
export { useDubheConfig, DEFAULT_CONFIG } from './config';
|
|
19
|
+
|
|
20
|
+
export { mergeConfigurations, validateConfig, getConfigSummary } from './utils';
|
|
21
|
+
|
|
22
|
+
// ============ Provider Component ============
|
|
23
|
+
export { DubheProvider } from './provider';
|
|
24
|
+
|
|
25
|
+
// ============ Modern React Hooks ============
|
|
26
|
+
export {
|
|
27
|
+
// Primary Hook - Provider pattern
|
|
28
|
+
useDubhe,
|
|
29
|
+
|
|
30
|
+
// Compatibility alias
|
|
31
|
+
useContract,
|
|
32
|
+
|
|
33
|
+
// Individual Instance Hooks - optimized for specific use cases
|
|
34
|
+
useDubheContract,
|
|
35
|
+
useDubheGraphQL,
|
|
36
|
+
useDubheECS
|
|
37
|
+
} from './hooks';
|