Skip to content

Commit b93dfb7

Browse files
committed
fix: Various fixes
- Include full transaction data in TX completed event - Fix race condition when deep linking onboarding cards
1 parent e7a92c8 commit b93dfb7

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

javascript/engine-js/src/ITokenScript.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {ViewController} from './view/ViewController';
1818
import {ViewStyles} from './view/ViewStyles';
1919

2020
import {ScriptInfo} from './repo/sources/SourceInterface';
21+
import {TransactionResponse} from "ethers";
2122

2223
export interface ITokenContext extends ITokenCollection {
2324
originId: string;
@@ -103,7 +104,7 @@ export interface ITokenScript {
103104
id?: string,
104105
): void;
105106
getAsnModuleDefinition(name: string): Element | null;
106-
executeTransaction(transaction: Transaction, listener?: ITransactionListener, waitForConfirmation?: boolean): Promise<any | false>;
107+
executeTransaction(transaction: Transaction, listener?: ITransactionListener, waitForConfirmation?: boolean): Promise<ITransactionStatus | false>;
107108

108109
// Only for full TokenScript
109110
getViewController(viewBinding?: IViewBinding): ViewController;

javascript/engine-js/src/view/ViewController.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export class ViewController {
110110

111111
this.dispatchViewEvent(ViewEvent.GET_USER_INPUT, null, null);
112112

113-
const processed = await this.currentCard.executeTransaction(listener, txName);
113+
const txStatus = await this.currentCard.executeTransaction(listener, txName);
114114

115-
if (processed === false)
115+
if (txStatus === false)
116116
return;
117117

118118
// Pause to let token discovery service update
@@ -132,8 +132,12 @@ export class ViewController {
132132
if (reloadCard && updateViewData && (!context || tokens[context.originId]?.tokenDetails?.[context.selectedTokenIndex]))
133133
await this.updateCardData();
134134

135-
if (listener)
136-
listener({status: "completed"})
135+
if (listener) {
136+
listener({
137+
...txStatus,
138+
status: 'completed',
139+
});
140+
}
137141
}
138142

139143
/**

javascript/engine-js/src/wallet/EthersAdapter.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
ethers,
77
EventLog,
88
getBigInt,
9-
Network, Overrides, ZeroAddress
9+
Network, Overrides, TransactionResponse, ZeroAddress
1010
} from "ethers";
11-
import {ITransactionListener} from "../ITokenScript";
11+
import {ITransactionListener, ITransactionStatus} from "../ITokenScript";
1212
import {ErrorDecoder, ErrorType} from "ethers-decode-error";
1313
import {WaterfallFallbackProvider} from "./WaterfallFallbackProvider";
1414

@@ -59,7 +59,7 @@ export class EthersAdapter implements IWalletAdapter {
5959
return (await contract.getFunction(method).staticCall(...(args.map((arg: any) => arg.value))));
6060
}
6161

62-
async sendTransaction(chain: number, contractAddr: string, method: string, args: any[], outputTypes: string[], value?: bigint, waitForConfirmation: boolean = true, listener?: ITransactionListener, errorAbi: any[] = []){
62+
async sendTransaction(chain: number, contractAddr: string, method: string, args: any[], outputTypes: string[], value?: bigint, waitForConfirmation: boolean = true, listener?: ITransactionListener, errorAbi: any[] = []): Promise<ITransactionStatus|false> {
6363

6464
console.log("Send ethereum transaction. chain " + chain + "; contract " + contractAddr + "; method " + method + "; value " + value + "; args", args);
6565

@@ -81,7 +81,7 @@ export class EthersAdapter implements IWalletAdapter {
8181
if (value)
8282
overrides.value = value;
8383

84-
let tx;
84+
let tx: TransactionResponse;
8585

8686
// Getting a function only by name could be ambiguous, so we try the full signature first
8787
// TODO: Add support for struct/tuple method signatures
@@ -96,7 +96,7 @@ export class EthersAdapter implements IWalletAdapter {
9696
}
9797

9898
try {
99-
tx = await contractMethod(...(args.map((arg: any) => arg.value)), overrides) as ContractTransaction;
99+
tx = await contractMethod(...(args.map((arg: any) => arg.value)), overrides);
100100
} catch (e: any){
101101

102102
if (EthersAdapter.isTransactionRejection(e))
@@ -141,7 +141,7 @@ export class EthersAdapter implements IWalletAdapter {
141141
});
142142

143143
if (waitForConfirmation)
144-
await tx.wait().then((transactionReceipt) => {
144+
await tx.wait(1).then((transactionReceipt) => {
145145

146146
if (transactionReceipt.status !== 1) {
147147
console.error(transactionReceipt);
@@ -159,7 +159,11 @@ export class EthersAdapter implements IWalletAdapter {
159159
return transactionReceipt;
160160
});
161161

162-
return tx;
162+
return {
163+
status: 'confirmed',
164+
txNumber: tx.hash,
165+
txLink
166+
}
163167
}
164168

165169
private static isTransactionRejection(e: any){

javascript/engine-js/src/wallet/IWalletAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {EventLog, Log} from "ethers";
2-
import {ITransactionListener} from "../ITokenScript";
2+
import {ITransactionListener, ITransactionStatus} from "../ITokenScript";
33
import {IChainConfig} from "./EthersAdapter";
44

55
export interface RpcRequest {
@@ -47,7 +47,7 @@ export interface IWalletAdapter {
4747
waitForConfirmation?: boolean,
4848
listener?: ITransactionListener,
4949
errorAbi?: any[]
50-
): Promise<any|false>;
50+
): Promise<ITransactionStatus|false>;
5151
getChain(): Promise<number>;
5252
getRpcUrls(chainId: number): string[];
5353
rpcProxy(request: RpcRequest): Promise<any>;

javascript/tokenscript-viewer/src/components/common/card-view/card-popover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class CardPopover implements IViewBinding {
4848
}) showToast: EventEmitter<ShowToastEventArgs>;
4949

5050
@Watch('tokenScript')
51-
async loadTs(){
51+
loadTs(){
5252
this.tokenScript.setViewBinding(this);
5353
this.tokenScript.on("TX_STATUS", (data: ITransactionStatus) => {
5454
if (data.status !== "error"){

javascript/tokenscript-viewer/src/components/common/tokens-grid/tokens-grid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class TokensGrid {
132132
await cardRes.card.isEnabledOrReason() === true
133133
) {
134134
this.urlActionInvoked = true;
135-
this.showCard(cardRes.card);
135+
setTimeout(() => this.showCard(cardRes.card), 100);
136136
return;
137137
}
138138
}

0 commit comments

Comments
 (0)