@fivenorth/loop-sdk 0.7.6 → 0.8.0
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/README.md +7 -1
- package/dist/index.js +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ import { loop } from '@fivenorth/loop-sdk';
|
|
|
29
29
|
Note that, If you don't want to implement a build process, you can include the file directly with `unpkg` such as
|
|
30
30
|
|
|
31
31
|
```javascript
|
|
32
|
-
import { loop } from 'https://unpkg.com/@fivenorth/loop-sdk@0.
|
|
32
|
+
import { loop } from 'https://unpkg.com/@fivenorth/loop-sdk@0.8.0/dist';
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
An example of how we use it in that manner is on our [loopsdk demo](https://codepen.io/kureikain/pen/KwVGgLX)
|
|
@@ -42,6 +42,9 @@ Before you can connect, you need to initialize the SDK. This is typically done o
|
|
|
42
42
|
loop.init({
|
|
43
43
|
appName: 'My Awesome dApp',
|
|
44
44
|
network: 'local', // or 'devnet', 'mainnet'
|
|
45
|
+
onTransactionUpdate: (payload) => {
|
|
46
|
+
console.log('Transaction update:', payload);
|
|
47
|
+
},
|
|
45
48
|
options: {
|
|
46
49
|
openMode: 'popup', // 'popup' (default) or 'tab'
|
|
47
50
|
requestSigningMode: 'popup', // 'popup' (default) or 'tab'
|
|
@@ -60,6 +63,7 @@ loop.init({
|
|
|
60
63
|
The `init` method takes a configuration object with the following properties:
|
|
61
64
|
- `appName`: The name of your application, which will be displayed to the user in the Loop wallet.
|
|
62
65
|
- `network`: The network to connect to. Can be `local`, `devnet`, or `mainnet`.
|
|
66
|
+
- `onTransactionUpdate`: Called when a transaction update is finalized (includes `update_id` and optional `update_data`).
|
|
63
67
|
- `options`: Optional object containing:
|
|
64
68
|
- `openMode`: Controls how Loop opens: `'popup'` (default) or `'tab'`.
|
|
65
69
|
- `requestSigningMode`: Controls how signing/transaction requests open the wallet UI after you're connected: `'popup'` (default) or `'tab'`.
|
|
@@ -145,6 +149,8 @@ try {
|
|
|
145
149
|
}
|
|
146
150
|
```
|
|
147
151
|
|
|
152
|
+
Transaction responses include `command_id`, `submission_id`, `transaction_data`, and `update_id` when available. For token transfers, `update_id` may arrive later (once indexed), in which case `onTransactionUpdate` fires with the finalized `update_id`. Non-transfer transactions do not receive an `update_id` via this mechanism.
|
|
153
|
+
|
|
148
154
|
#### Sign a Message
|
|
149
155
|
|
|
150
156
|
You can request the user to sign an arbitrary message:
|
package/dist/index.js
CHANGED
|
@@ -2321,7 +2321,7 @@ var MessageType;
|
|
|
2321
2321
|
MessageType2["HANDSHAKE_ACCEPT"] = "handshake_accept";
|
|
2322
2322
|
MessageType2["HANDSHAKE_REJECT"] = "handshake_reject";
|
|
2323
2323
|
MessageType2["RUN_TRANSACTION"] = "run_transaction";
|
|
2324
|
-
MessageType2["
|
|
2324
|
+
MessageType2["TRANSACTION_COMPLETED"] = "transaction_completed";
|
|
2325
2325
|
MessageType2["SIGN_RAW_MESSAGE"] = "sign_raw_message";
|
|
2326
2326
|
MessageType2["SIGN_RAW_MESSAGE_RESPONSE"] = "sign_raw_message_response";
|
|
2327
2327
|
MessageType2["REJECT_REQUEST"] = "reject_request";
|
|
@@ -2375,6 +2375,9 @@ class Provider {
|
|
|
2375
2375
|
}
|
|
2376
2376
|
handleResponse(message) {
|
|
2377
2377
|
console.log("Received response:", message);
|
|
2378
|
+
if (message?.type === "transaction_completed" /* TRANSACTION_COMPLETED */ && message?.payload?.update_id) {
|
|
2379
|
+
this.hooks?.onTransactionUpdate?.(message.payload, message);
|
|
2380
|
+
}
|
|
2378
2381
|
if (message.request_id) {
|
|
2379
2382
|
this.requests.set(message.request_id, message);
|
|
2380
2383
|
}
|
|
@@ -2705,6 +2708,7 @@ class LoopSDK {
|
|
|
2705
2708
|
redirectUrl;
|
|
2706
2709
|
onAccept = null;
|
|
2707
2710
|
onReject = null;
|
|
2711
|
+
onTransactionUpdate = null;
|
|
2708
2712
|
overlay = null;
|
|
2709
2713
|
wallet;
|
|
2710
2714
|
constructor() {
|
|
@@ -2717,6 +2721,7 @@ class LoopSDK {
|
|
|
2717
2721
|
apiUrl,
|
|
2718
2722
|
onAccept,
|
|
2719
2723
|
onReject,
|
|
2724
|
+
onTransactionUpdate,
|
|
2720
2725
|
options
|
|
2721
2726
|
}) {
|
|
2722
2727
|
if (typeof window === "undefined" || typeof document === "undefined" || typeof localStorage === "undefined") {
|
|
@@ -2725,6 +2730,7 @@ class LoopSDK {
|
|
|
2725
2730
|
this.appName = appName;
|
|
2726
2731
|
this.onAccept = onAccept || null;
|
|
2727
2732
|
this.onReject = onReject || null;
|
|
2733
|
+
this.onTransactionUpdate = onTransactionUpdate || null;
|
|
2728
2734
|
const resolvedOptions = {
|
|
2729
2735
|
openMode: "popup",
|
|
2730
2736
|
requestSigningMode: "popup",
|
|
@@ -3115,7 +3121,8 @@ class LoopSDK {
|
|
|
3115
3121
|
this.closePopupIfExists();
|
|
3116
3122
|
}, 800);
|
|
3117
3123
|
}
|
|
3118
|
-
}
|
|
3124
|
+
},
|
|
3125
|
+
onTransactionUpdate: this.onTransactionUpdate ?? undefined
|
|
3119
3126
|
};
|
|
3120
3127
|
}
|
|
3121
3128
|
}
|