Skip to content

Commit 38684a6

Browse files
authored
feat: make RPC endpoint configurable for wallet provider (#16)
1 parent 981b130 commit 38684a6

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const DEFAULT_RPC_URL = 'https://rpc.gno.land:443';

packages/sdk/src/core/providers/tm2-wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Wallet as TM2Wallet } from '@gnolang/tm2-js-client';
22
import { WalletProvider } from './wallet';
33

44
export interface TM2WalletProvider extends WalletProvider {
5-
connect(): Promise<boolean>;
5+
connect(rpcUrl?: string): Promise<boolean>;
66

77
disconnect(): Promise<boolean>;
88

packages/sdk/src/providers/gno-wallet/gno-wallet.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,23 @@ import {
2525
} from '../../core/types/methods';
2626
import { encodeTransaction } from '../../core/utils/encode.utils';
2727
import { makeResponseMessage } from '../../core/utils/message.utils';
28+
import { DEFAULT_RPC_URL } from '../../core/constants/chains.constant';
2829

2930
export class GnoWalletProvider implements TM2WalletProvider {
3031
protected wallet: TM2Wallet | null;
32+
protected rpcUrl: string | null;
3133

3234
constructor(wallet?: TM2Wallet) {
3335
this.wallet = wallet || null;
36+
this.rpcUrl = null;
3437
}
3538

3639
public getWallet(): TM2Wallet | null {
3740
return this.wallet;
3841
}
3942

40-
async connect(): Promise<boolean> {
41-
return this.connectProvider();
43+
async connect(rpcUrl?: string): Promise<boolean> {
44+
return this.connectProvider(rpcUrl);
4245
}
4346

4447
async disconnect(): Promise<boolean> {
@@ -136,12 +139,12 @@ export class GnoWalletProvider implements TM2WalletProvider {
136139
throw new Error('not supported');
137140
}
138141

139-
protected connectProvider(): boolean {
142+
protected connectProvider(rpcUrl?: string): boolean {
140143
if (!this.wallet) {
141144
return false;
142145
}
143146

144-
const provider = new JSONRPCProvider('https://rpc.gno.land:443');
147+
const provider = new JSONRPCProvider(rpcUrl || DEFAULT_RPC_URL);
145148
this.wallet.connect(provider);
146149
return true;
147150
}

0 commit comments

Comments
 (0)