Skip to content

Commit 8acf564

Browse files
authored
[TSv4] Fix caching logic, avoid fetch when abi passed (thirdweb-dev#3236)
1 parent dbf74aa commit 8acf564

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

.changeset/sweet-shoes-sit.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@thirdweb-dev/unity-js-bridge": patch
3+
"@thirdweb-dev/sdk": patch
4+
---
5+
6+
Fix caching logic for getContract/getContractFromAbi

legacy_packages/sdk/src/evm/core/sdk.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,13 @@ export class ThirdwebSDK extends RPCConnectionHandler {
587587
);
588588
newContract = await this.getContractFromAbi(
589589
resolvedAddress,
590-
metadata.abi,
590+
await getCompositeABI(
591+
resolvedAddress,
592+
AbiSchema.parse(metadata.abi),
593+
this.getProvider(),
594+
this.options,
595+
this.storage,
596+
),
591597
);
592598
} catch (e) {
593599
// fallback to
@@ -601,7 +607,13 @@ export class ThirdwebSDK extends RPCConnectionHandler {
601607
].getAbi(resolvedAddress, this.getProvider(), this.storage);
602608
newContract = await this.getContractFromAbi(
603609
resolvedAddress,
604-
contractAbi,
610+
await getCompositeABI(
611+
resolvedAddress,
612+
AbiSchema.parse(contractAbi),
613+
this.getProvider(),
614+
this.options,
615+
this.storage,
616+
),
605617
);
606618
} else {
607619
// we cant fetch the ABI, and we don't know the contract type, throw the original error
@@ -843,13 +855,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
843855
const contract = new SmartContract(
844856
this.getSignerOrProvider(),
845857
resolvedAddress,
846-
await getCompositeABI(
847-
resolvedAddress,
848-
AbiSchema.parse(parsedABI),
849-
provider,
850-
this.options,
851-
this.storage,
852-
),
858+
parsedABI,
853859
this.storageHandler,
854860
this.options,
855861
(await provider.getNetwork()).chainId,

legacy_packages/unity-js-bridge/src/thirdweb-bridge.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class ThirdwebBridge implements TWBridge {
171171
// biome-ignore lint/suspicious/noExplicitAny: TODO: fix use of any
172172
(globalThis as any).X_SDK_PLATFORM = "unity";
173173
// biome-ignore lint/suspicious/noExplicitAny: TODO: fix use of any
174-
(globalThis as any).X_SDK_VERSION = "4.15.0";
174+
(globalThis as any).X_SDK_VERSION = "4.15.1";
175175
// biome-ignore lint/suspicious/noExplicitAny: TODO: fix use of any
176176
(globalThis as any).X_SDK_OS = browser?.os ?? "unknown";
177177
}
@@ -321,7 +321,6 @@ class ThirdwebBridge implements TWBridge {
321321
}
322322

323323
public async connect(
324-
// biome-ignore lint/style/useDefaultParameterLast: would change the order of parameters to fix this
325324
wallet: string,
326325
chainId: string,
327326
password?: string,
@@ -528,7 +527,8 @@ class ThirdwebBridge implements TWBridge {
528527
return arg;
529528
}
530529
});
531-
// console.debug("thirdwebSDK call:", route, parsedArgs);
530+
531+
// console.log("thirdwebSDK call:", route, parsedArgs);
532532

533533
// wallet call
534534
if (addrOrSDK.startsWith("sdk")) {
@@ -570,15 +570,21 @@ class ThirdwebBridge implements TWBridge {
570570
// contract tx
571571
if (addrOrSDK.startsWith("0x")) {
572572
let typeOrAbi: string | ContractInterface | undefined;
573+
let isAbi = false;
573574
if (firstArg.length > 1) {
574575
try {
575576
typeOrAbi = JSON.parse(firstArg[1]); // try to parse ABI
577+
isAbi = true;
576578
} catch (e) {
577579
typeOrAbi = firstArg[1];
580+
isAbi = false;
578581
}
579582
}
583+
580584
const contract = typeOrAbi
581-
? await this.activeSDK.getContract(addrOrSDK, typeOrAbi)
585+
? isAbi
586+
? await this.activeSDK.getContractFromAbi(addrOrSDK, typeOrAbi)
587+
: await this.activeSDK.getContract(addrOrSDK, typeOrAbi)
582588
: await this.activeSDK.getContract(addrOrSDK);
583589

584590
// tx

0 commit comments

Comments
 (0)