Skip to content

Commit 591cc30

Browse files
committed
Fix first time connecting dapp
1 parent e532976 commit 591cc30

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

client/src/glue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Chain } from "./index";
1+
import { AnyChain } from "./index";
22
import { delay } from "./util";
33
import {
44
ActivateChain,
@@ -73,9 +73,9 @@ export class ManualGlue extends Glue {
7373
private readonly eventsElement: HTMLElement;
7474
private readonly instructionsElement: HTMLElement;
7575

76-
private readonly wallet: Chain;
76+
private readonly wallet: AnyChain;
7777

78-
constructor(element: HTMLElement, wallet: Chain) {
78+
constructor(element: HTMLElement, wallet: AnyChain) {
7979
super();
8080

8181
this.wallet = wallet;

client/src/index.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import * as viem from "viem";
77

88
type Eip1193Provider = Parameters<typeof viem.custom>[0];
99

10-
export interface Chain {
10+
export interface AccountChain<A extends undefined | viem.Account> {
1111
provider: Eip1193Provider;
1212
public: viem.PublicClient<viem.Transport, viem.Chain>;
13-
wallet: viem.WalletClient<viem.Transport, viem.Chain, viem.Account>;
13+
wallet: viem.WalletClient<viem.Transport, viem.Chain, A>;
1414
}
1515

16+
export type Chain = AccountChain<viem.Account>;
17+
export type AnyChain = AccountChain<undefined | viem.Account>;
18+
1619
export interface TestChain extends Chain {
1720
test: viem.TestClient<"ganache", viem.Transport, viem.Chain>;
1821
}
@@ -140,15 +143,11 @@ function main() {
140143

141144
await blockchain.test.setAutomine(false);
142145

143-
const wallet: Chain = {
146+
const unboundWallet: AccountChain<undefined> = {
144147
provider: window.ethereum,
145148
wallet: viem.createWalletClient({
146149
chain,
147150
transport: viem.custom(window.ethereum),
148-
account: {
149-
address: await getAccount(window.ethereum),
150-
type: "json-rpc",
151-
} as viem.Account,
152151
pollingInterval: 0,
153152
}),
154153
public: viem.createPublicClient({
@@ -170,7 +169,7 @@ function main() {
170169
throw "no #container element";
171170
}
172171

173-
glue = new ManualGlue(glueElem, wallet);
172+
glue = new ManualGlue(glueElem, unboundWallet);
174173
}
175174

176175
const uuid = crypto.randomUUID();
@@ -272,12 +271,30 @@ function main() {
272271
});
273272
});
274273

275-
await wallet.wallet.requestAddresses();
274+
await unboundWallet.wallet.requestAddresses();
276275
unsubscribe();
277276
if (requestAccountsPromise instanceof Promise) {
278277
await requestAccountsPromise;
279278
}
280279

280+
const wallet: Chain = {
281+
provider: window.ethereum,
282+
wallet: viem.createWalletClient({
283+
chain,
284+
transport: viem.custom(window.ethereum),
285+
account: {
286+
address: await getAccount(window.ethereum),
287+
type: "json-rpc",
288+
} as viem.Account,
289+
pollingInterval: 0,
290+
}),
291+
public: viem.createPublicClient({
292+
chain,
293+
transport: viem.custom(window.ethereum),
294+
pollingInterval: 0,
295+
}),
296+
};
297+
281298
await tests.run(blockchain, wallet);
282299
});
283300

0 commit comments

Comments
 (0)