Skip to content

Commit 3aabb55

Browse files
committed
feat: update getReadonlyIExec to accept chainId and retrieve provider dynamically
1 parent c227520 commit 3aabb55

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/externals/iexecSdkClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IExec, IExecConfig, Eip1193Provider } from 'iexec';
22
import { type Connector } from 'wagmi';
3+
import { getChainFromId } from '@/utils/chain.utils';
34

45
let iExec: IExec | null = null;
56
let readonlyIExec: IExec | null = null;
@@ -41,9 +42,12 @@ export function getIExec(): Promise<IExec> {
4142
return Promise.resolve(iExec);
4243
}
4344

44-
export function getReadonlyIExec(): IExec {
45+
export function getReadonlyIExec(chainId: number): IExec {
46+
const chain = getChainFromId(chainId);
47+
if (!chain) throw new Error(`Unknown chainId ${chainId}`);
48+
4549
if (!readonlyIExec) {
46-
readonlyIExec = new IExec({ ethProvider: 'bellecour' });
50+
readonlyIExec = new IExec({ ethProvider: chain?.slug });
4751
}
4852
return readonlyIExec;
4953
}

src/modules/search/SearcherBar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export function SearcherBar({
7070
let resolvedValue = value;
7171

7272
if (value.endsWith('.eth')) {
73-
const iexec = isConnected ? await getIExec() : getReadonlyIExec();
73+
const iexec = isConnected
74+
? await getIExec()
75+
: getReadonlyIExec(chainId!);
7476
const resolved = await iexec.ens.resolveName(value);
7577
if (!resolved) {
7678
throw new Error(`Fail to resolve ENS : ${value}`);

0 commit comments

Comments
 (0)