@keplr-wallet/background 0.13.1 → 0.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/keyring-cosmos/handler.js +16 -0
- package/build/keyring-cosmos/handler.js.map +1 -1
- package/build/keyring-cosmos/init.js +2 -0
- package/build/keyring-cosmos/init.js.map +1 -1
- package/build/keyring-cosmos/messages.d.ts +38 -0
- package/build/keyring-cosmos/messages.js +69 -1
- package/build/keyring-cosmos/messages.js.map +1 -1
- package/build/keyring-cosmos/service.d.ts +28 -2
- package/build/keyring-cosmos/service.js +221 -1
- package/build/keyring-cosmos/service.js.map +1 -1
- package/build/tx/service.d.ts +1 -0
- package/build/tx/service.js +41 -33
- package/build/tx/service.js.map +1 -1
- package/package.json +13 -13
- package/src/index.ts +1 -0
- package/src/keyring-cosmos/handler.ts +61 -0
- package/src/keyring-cosmos/init.ts +4 -0
- package/src/keyring-cosmos/messages.ts +94 -0
- package/src/keyring-cosmos/service.ts +351 -1
- package/src/tx/service.ts +52 -44
package/src/tx/service.ts
CHANGED
|
@@ -36,6 +36,7 @@ export class BackgroundTxService {
|
|
|
36
36
|
options: {
|
|
37
37
|
silent?: boolean;
|
|
38
38
|
skipTracingTxResult?: boolean;
|
|
39
|
+
waitFulfillment?: boolean;
|
|
39
40
|
onFulfill?: (tx: any) => void;
|
|
40
41
|
}
|
|
41
42
|
): Promise<Uint8Array> {
|
|
@@ -97,55 +98,62 @@ export class BackgroundTxService {
|
|
|
97
98
|
return txHash;
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
const waitFulfillment = () => {
|
|
102
|
+
return retry(
|
|
103
|
+
() => {
|
|
104
|
+
return new Promise<void>((resolve, reject) => {
|
|
105
|
+
const txTracer = new TendermintTxTracer(
|
|
106
|
+
chainInfo.rpc,
|
|
107
|
+
"/websocket"
|
|
108
|
+
);
|
|
109
|
+
txTracer.addEventListener("close", () => {
|
|
110
|
+
// reject if ws closed before fulfilled
|
|
111
|
+
// 하지만 로직상 fulfill 되기 전에 ws가 닫히는게 되기 때문에
|
|
112
|
+
// delay를 좀 준다.
|
|
113
|
+
// trace 이후 로직은 동기적인 로직밖에 없기 때문에 문제될 게 없다.
|
|
114
|
+
// 문제될게 없다.
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
reject();
|
|
117
|
+
}, 500);
|
|
118
|
+
});
|
|
119
|
+
txTracer.addEventListener("error", () => {
|
|
116
120
|
reject();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (!tx.hash) {
|
|
127
|
-
tx.hash = txHash;
|
|
121
|
+
});
|
|
122
|
+
txTracer.traceTx(txHash).then((tx) => {
|
|
123
|
+
txTracer.close();
|
|
124
|
+
|
|
125
|
+
if (options.onFulfill) {
|
|
126
|
+
if (!tx.hash) {
|
|
127
|
+
tx.hash = txHash;
|
|
128
|
+
}
|
|
129
|
+
options.onFulfill(tx);
|
|
128
130
|
}
|
|
129
|
-
options.onFulfill(tx);
|
|
130
|
-
}
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
if (!options.silent) {
|
|
133
|
+
BackgroundTxService.processTxResultNotification(
|
|
134
|
+
this.notification,
|
|
135
|
+
tx
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
resolve();
|
|
140
|
+
});
|
|
140
141
|
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
maxRetries: 10,
|
|
145
|
+
waitMsAfterError: 10 * 1000, // 10sec
|
|
146
|
+
maxWaitMsAfterError: 5 * 60 * 1000, // 5min
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
if (options.waitFulfillment) {
|
|
151
|
+
await waitFulfillment();
|
|
152
|
+
} else {
|
|
153
|
+
// 이 기능은 tx commit일때 notification을 띄울 뿐이다.
|
|
154
|
+
// 실제 로직 처리와는 관계가 없어야하기 때문에 여기서 await을 하면 안된다!!
|
|
155
|
+
waitFulfillment();
|
|
156
|
+
}
|
|
149
157
|
|
|
150
158
|
return txHash;
|
|
151
159
|
} catch (e) {
|