turing-wallet-provider 1.5.3 → 1.5.4
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 +65 -0
- package/dist/types/providerTypes.d.ts +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,6 +65,71 @@ const {name,platform,version} = await wallet.getInfo();
|
|
|
65
65
|
{Turing,android,1.0.0}//示例的返回值
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
+
## getNetwork
|
|
69
|
+
|
|
70
|
+
获取已连接账户当前激活的网络。
|
|
71
|
+
|
|
72
|
+
### 用法
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const wallet = useTuringWallet();
|
|
76
|
+
const network = await wallet.getNetwork();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 参数
|
|
80
|
+
|
|
81
|
+
该方法不接受任何参数。
|
|
82
|
+
|
|
83
|
+
### 返回值
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
interface GetNetworkResponse {
|
|
87
|
+
network: "tbc" | "btc" | "eth" | "bnb" | "all";
|
|
88
|
+
type: "mainnet" | "testnet";
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
| 字段 | 类型 | 说明 |
|
|
93
|
+
| --- | --- | --- |
|
|
94
|
+
| `network` | `"tbc" \| "btc" \| "eth" \| "bnb" \| "all"` | 当前激活的链。`"all"` 表示用户处于钱包的"所有网络"视图,未选择具体的链。 |
|
|
95
|
+
| `type` | `"mainnet" \| "testnet"` | 主网 / 测试网。仅 `tbc` 可能为 `"testnet"`,其余链恒为 `"mainnet"`。 |
|
|
96
|
+
|
|
97
|
+
### 错误处理
|
|
98
|
+
|
|
99
|
+
| 错误 | 原因 |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `User not connected` | 尚未调用 `wallet.connect()`,或用户已断开连接。 |
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
const wallet = useTuringWallet();
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const info = await wallet.getNetwork();
|
|
108
|
+
console.log(info);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error("Failed to get network:", error);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 订阅变化
|
|
115
|
+
|
|
116
|
+
钱包内切换网络时,dapp 会收到 `TuringNetworkChanged` 事件并附带新的网络信息,无需轮询 `getNetwork()`。
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
window.addEventListener("TuringNetworkChanged", (event) => {
|
|
120
|
+
const { network } = event.detail;
|
|
121
|
+
// `network` 与 wallet.getNetwork() 的返回值同结构
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
interface TuringNetworkChangedDetail {
|
|
127
|
+
network: GetNetworkResponse;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
仅在 dapp 已连接期间触发,且只推送 `connect()` 之后的变化(初始网络可通过 `wallet.getNetwork()` 获取)。
|
|
132
|
+
|
|
68
133
|
## signMessage
|
|
69
134
|
|
|
70
135
|
```ts
|
|
@@ -17,6 +17,15 @@ export type Info = {
|
|
|
17
17
|
version: string;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
export type GetNetworkResponse = {
|
|
21
|
+
network: "tbc" | "btc" | "eth" | "bnb" | "all";
|
|
22
|
+
type: "mainnet" | "testnet";
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type TuringNetworkChangedDetail = {
|
|
26
|
+
network: GetNetworkResponse;
|
|
27
|
+
};
|
|
28
|
+
|
|
20
29
|
export type TransactionFlag =
|
|
21
30
|
| "P2PKH"
|
|
22
31
|
| "COLLECTION_CREATE"
|
|
@@ -241,6 +250,7 @@ export type TuringProviderType = {
|
|
|
241
250
|
getPubKey: () => Promise<PubKey | undefined>;
|
|
242
251
|
getAddress: () => Promise<Address | undefined>;
|
|
243
252
|
getInfo: () => Promise<Info | undefined>;
|
|
253
|
+
getNetwork: () => Promise<GetNetworkResponse | undefined>;
|
|
244
254
|
sendTransaction: (
|
|
245
255
|
params: SendTransaction[]
|
|
246
256
|
) => Promise<SendTransactionResponse | undefined>;
|