Skip to content

Commit 38ede16

Browse files
committed
Revert "constructor support wallet as public client"
This reverts commit 21cd32b.
1 parent 21cd32b commit 38ede16

File tree

1 file changed

+34
-83
lines changed

1 file changed

+34
-83
lines changed

sdk/typescript/SecureOwnable.tsx

Lines changed: 34 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,21 @@
1-
import {
2-
Address,
3-
PublicClient,
4-
WalletClient,
5-
Chain,
6-
Hex,
7-
createPublicClient,
8-
custom,
9-
http,
10-
EIP1193Provider
11-
} from 'viem';
1+
import { Address, PublicClient, WalletClient, Chain, Hex } from 'viem';
122
import SecureOwnableABIJson from '../../abi/SecureOwnable.abi.json';
133
import { TransactionOptions, TransactionResult } from './interfaces/base.index';
144
import { ISecureOwnable } from './interfaces/core.access.index';
155
import { TxRecord, MetaTransaction, MetaTxParams } from './interfaces/lib.index';
166
import { ExecutionType } from './types/lib.index';
177

18-
declare global {
19-
interface Window {
20-
ethereum?: EIP1193Provider;
21-
}
22-
}
23-
24-
export interface SecureOwnableConfig {
25-
walletClient?: WalletClient;
26-
publicClient?: PublicClient;
27-
contractAddress: Address;
28-
chain: Chain;
29-
useWalletAsProvider?: boolean;
30-
fallbackRpcUrl?: string;
31-
}
32-
338
/**
349
* @title SecureOwnable
35-
* @notice TypeScript wrapper for SecureOwnable smart contract with optional wallet-based provider
10+
* @notice TypeScript wrapper for SecureOwnable smart contract
3611
*/
3712
export class SecureOwnable implements ISecureOwnable {
38-
protected publicClient: PublicClient;
39-
protected walletClient?: WalletClient;
40-
protected contractAddress: Address;
41-
protected chain: Chain;
42-
43-
constructor(config: SecureOwnableConfig) {
44-
this.contractAddress = config.contractAddress;
45-
this.chain = config.chain;
46-
this.walletClient = config.walletClient;
47-
48-
// Initialize public client based on configuration
49-
if (config.publicClient) {
50-
// Use provided public client
51-
this.publicClient = config.publicClient;
52-
} else if (typeof window !== 'undefined' && window.ethereum) {
53-
// Use window.ethereum if available
54-
this.publicClient = createPublicClient({
55-
chain: this.chain,
56-
transport: custom(window.ethereum)
57-
});
58-
} else if (config.fallbackRpcUrl) {
59-
// Use fallback RPC URL if provided
60-
this.publicClient = createPublicClient({
61-
chain: this.chain,
62-
transport: http(config.fallbackRpcUrl)
63-
});
64-
} else {
65-
throw new Error('Either publicClient must be provided, window.ethereum must be available, or fallbackRpcUrl must be provided');
66-
}
67-
}
13+
constructor(
14+
protected client: PublicClient,
15+
protected walletClient: WalletClient | undefined,
16+
protected contractAddress: Address,
17+
protected chain: Chain
18+
) {}
6819

6920
// Ownership Management
7021
async transferOwnershipRequest(options: TransactionOptions): Promise<TransactionResult> {
@@ -80,7 +31,7 @@ export class SecureOwnable implements ISecureOwnable {
8031

8132
return {
8233
hash,
83-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
34+
wait: () => this.client.waitForTransactionReceipt({ hash })
8435
};
8536
}
8637

@@ -98,7 +49,7 @@ export class SecureOwnable implements ISecureOwnable {
9849

9950
return {
10051
hash,
101-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
52+
wait: () => this.client.waitForTransactionReceipt({ hash })
10253
};
10354
}
10455

@@ -116,7 +67,7 @@ export class SecureOwnable implements ISecureOwnable {
11667

11768
return {
11869
hash,
119-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
70+
wait: () => this.client.waitForTransactionReceipt({ hash })
12071
};
12172
}
12273

@@ -134,7 +85,7 @@ export class SecureOwnable implements ISecureOwnable {
13485

13586
return {
13687
hash,
137-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
88+
wait: () => this.client.waitForTransactionReceipt({ hash })
13889
};
13990
}
14091

@@ -152,7 +103,7 @@ export class SecureOwnable implements ISecureOwnable {
152103

153104
return {
154105
hash,
155-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
106+
wait: () => this.client.waitForTransactionReceipt({ hash })
156107
};
157108
}
158109

@@ -171,7 +122,7 @@ export class SecureOwnable implements ISecureOwnable {
171122

172123
return {
173124
hash,
174-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
125+
wait: () => this.client.waitForTransactionReceipt({ hash })
175126
};
176127
}
177128

@@ -194,7 +145,7 @@ export class SecureOwnable implements ISecureOwnable {
194145
console.log('hash', hash);
195146
return {
196147
hash,
197-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
148+
wait: () => this.client.waitForTransactionReceipt({ hash })
198149
};
199150
}
200151

@@ -212,7 +163,7 @@ export class SecureOwnable implements ISecureOwnable {
212163

213164
return {
214165
hash,
215-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
166+
wait: () => this.client.waitForTransactionReceipt({ hash })
216167
};
217168
}
218169

@@ -230,7 +181,7 @@ export class SecureOwnable implements ISecureOwnable {
230181

231182
return {
232183
hash,
233-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
184+
wait: () => this.client.waitForTransactionReceipt({ hash })
234185
};
235186
}
236187

@@ -248,13 +199,13 @@ export class SecureOwnable implements ISecureOwnable {
248199

249200
return {
250201
hash,
251-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
202+
wait: () => this.client.waitForTransactionReceipt({ hash })
252203
};
253204
}
254205

255206
// Recovery Management
256207
async updateRecoveryExecutionOptions(newRecoveryAddress: Address): Promise<Hex> {
257-
return await this.publicClient.readContract({
208+
return await this.client.readContract({
258209
address: this.contractAddress,
259210
abi: SecureOwnableABIJson,
260211
functionName: 'updateRecoveryExecutionOptions',
@@ -276,13 +227,13 @@ export class SecureOwnable implements ISecureOwnable {
276227

277228
return {
278229
hash,
279-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
230+
wait: () => this.client.waitForTransactionReceipt({ hash })
280231
};
281232
}
282233

283234
// TimeLock Management
284235
async updateTimeLockExecutionOptions(newTimeLockPeriodInMinutes: bigint): Promise<Hex> {
285-
return await this.publicClient.readContract({
236+
return await this.client.readContract({
286237
address: this.contractAddress,
287238
abi: SecureOwnableABIJson,
288239
functionName: 'updateTimeLockExecutionOptions',
@@ -304,7 +255,7 @@ export class SecureOwnable implements ISecureOwnable {
304255

305256
return {
306257
hash,
307-
wait: () => this.publicClient.waitForTransactionReceipt({ hash })
258+
wait: () => this.client.waitForTransactionReceipt({ hash })
308259
};
309260
}
310261

@@ -316,7 +267,7 @@ export class SecureOwnable implements ISecureOwnable {
316267
maxGasPrice: bigint,
317268
signer: Address
318269
): Promise<MetaTxParams> {
319-
return await this.publicClient.readContract({
270+
return await this.client.readContract({
320271
address: this.contractAddress,
321272
abi: SecureOwnableABIJson,
322273
functionName: 'createMetaTxParams',
@@ -334,7 +285,7 @@ export class SecureOwnable implements ISecureOwnable {
334285
executionOptions: Hex,
335286
metaTxParams: MetaTxParams
336287
): Promise<MetaTransaction> {
337-
return await this.publicClient.readContract({
288+
return await this.client.readContract({
338289
address: this.contractAddress,
339290
abi: SecureOwnableABIJson,
340291
functionName: 'generateUnsignedMetaTransactionForNew',
@@ -355,7 +306,7 @@ export class SecureOwnable implements ISecureOwnable {
355306
txId: bigint,
356307
metaTxParams: MetaTxParams
357308
): Promise<MetaTransaction> {
358-
return await this.publicClient.readContract({
309+
return await this.client.readContract({
359310
address: this.contractAddress,
360311
abi: SecureOwnableABIJson,
361312
functionName: 'generateUnsignedMetaTransactionForExisting',
@@ -365,15 +316,15 @@ export class SecureOwnable implements ISecureOwnable {
365316

366317
// Getters
367318
async getOperationHistory(): Promise<TxRecord[]> {
368-
return await this.publicClient.readContract({
319+
return await this.client.readContract({
369320
address: this.contractAddress,
370321
abi: SecureOwnableABIJson,
371322
functionName: 'getOperationHistory'
372323
}) as TxRecord[];
373324
}
374325

375326
async getOperation(txId: bigint): Promise<TxRecord> {
376-
return await this.publicClient.readContract({
327+
return await this.client.readContract({
377328
address: this.contractAddress,
378329
abi: SecureOwnableABIJson,
379330
functionName: 'getOperation',
@@ -382,47 +333,47 @@ export class SecureOwnable implements ISecureOwnable {
382333
}
383334

384335
async getBroadcaster(): Promise<Address> {
385-
return await this.publicClient.readContract({
336+
return await this.client.readContract({
386337
address: this.contractAddress,
387338
abi: SecureOwnableABIJson,
388339
functionName: 'getBroadcaster'
389340
}) as Address;
390341
}
391342

392343
async getRecoveryAddress(): Promise<Address> {
393-
return await this.publicClient.readContract({
344+
return await this.client.readContract({
394345
address: this.contractAddress,
395346
abi: SecureOwnableABIJson,
396347
functionName: 'getRecoveryAddress'
397348
}) as Address;
398349
}
399350

400351
async getTimeLockPeriodInMinutes(): Promise<bigint> {
401-
return await this.publicClient.readContract({
352+
return await this.client.readContract({
402353
address: this.contractAddress,
403354
abi: SecureOwnableABIJson,
404355
functionName: 'getTimeLockPeriodInMinutes'
405356
}) as bigint;
406357
}
407358

408359
async owner(): Promise<Address> {
409-
return await this.publicClient.readContract({
360+
return await this.client.readContract({
410361
address: this.contractAddress,
411362
abi: SecureOwnableABIJson,
412363
functionName: 'owner'
413364
}) as Address;
414365
}
415366

416367
async getSupportedOperationTypes(): Promise<Array<{ operationType: Hex; name: string }>> {
417-
return await this.publicClient.readContract({
368+
return await this.client.readContract({
418369
address: this.contractAddress,
419370
abi: SecureOwnableABIJson,
420371
functionName: 'getSupportedOperationTypes'
421372
}) as Array<{ operationType: Hex; name: string }>;
422373
}
423374

424375
async isOperationTypeSupported(operationType: Hex): Promise<boolean> {
425-
return await this.publicClient.readContract({
376+
return await this.client.readContract({
426377
address: this.contractAddress,
427378
abi: SecureOwnableABIJson,
428379
functionName: 'isOperationTypeSupported',
@@ -431,7 +382,7 @@ export class SecureOwnable implements ISecureOwnable {
431382
}
432383

433384
async supportsInterface(interfaceId: Hex): Promise<boolean> {
434-
return await this.publicClient.readContract({
385+
return await this.client.readContract({
435386
address: this.contractAddress,
436387
abi: SecureOwnableABIJson,
437388
functionName: 'supportsInterface',

0 commit comments

Comments
 (0)