decane-connect-kit 1.0.0 → 1.0.1
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/dist/index.cjs +90 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +90 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1104,7 +1104,14 @@ async function getSolanaAddress(wallet) {
|
|
|
1104
1104
|
}
|
|
1105
1105
|
|
|
1106
1106
|
// src/tron/adapter.ts
|
|
1107
|
+
function getTronWeb() {
|
|
1108
|
+
if (typeof window === "undefined") return void 0;
|
|
1109
|
+
const win = window;
|
|
1110
|
+
return win.tronLink?.tronWeb ?? win.tronWeb;
|
|
1111
|
+
}
|
|
1107
1112
|
async function getTronAddress(provider) {
|
|
1113
|
+
const addr = getTronWeb()?.defaultAddress?.base58;
|
|
1114
|
+
if (addr) return addr;
|
|
1108
1115
|
try {
|
|
1109
1116
|
const result = await provider.request({ method: "tron_requestAccounts" });
|
|
1110
1117
|
const accounts = result;
|
|
@@ -1123,11 +1130,80 @@ async function tronRequest(provider, method, payload, account) {
|
|
|
1123
1130
|
method: "tron_signMessage",
|
|
1124
1131
|
params: { message: payload }
|
|
1125
1132
|
});
|
|
1126
|
-
case "wallet_sendTransaction":
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1133
|
+
case "wallet_sendTransaction": {
|
|
1134
|
+
const tronWeb = getTronWeb();
|
|
1135
|
+
const p = payload;
|
|
1136
|
+
const toAddress = p.to;
|
|
1137
|
+
const sunAmount = typeof p.value === "string" ? parseInt(p.value, 10) : p.value ?? 0;
|
|
1138
|
+
let unsignedTx;
|
|
1139
|
+
if (tronWeb?.transactionBuilder?.sendTrx) {
|
|
1140
|
+
if (p.data && p.data !== "0x") {
|
|
1141
|
+
const res = await tronWeb.transactionBuilder.triggerSmartContract(
|
|
1142
|
+
toAddress,
|
|
1143
|
+
"transfer(address,uint256)",
|
|
1144
|
+
{ callValue: 0, feeLimit: 1e8 },
|
|
1145
|
+
[],
|
|
1146
|
+
account
|
|
1147
|
+
);
|
|
1148
|
+
unsignedTx = res.transaction;
|
|
1149
|
+
} else {
|
|
1150
|
+
unsignedTx = await tronWeb.transactionBuilder.sendTrx(toAddress, sunAmount, account);
|
|
1151
|
+
}
|
|
1152
|
+
} else {
|
|
1153
|
+
const host = tronWeb?.fullNode?.host ?? "https://api.trongrid.io";
|
|
1154
|
+
const endpoint = p.data && p.data !== "0x" ? `${host}/wallet/triggersmartcontract` : `${host}/wallet/createtransaction`;
|
|
1155
|
+
const body = p.data && p.data !== "0x" ? {
|
|
1156
|
+
owner_address: account,
|
|
1157
|
+
contract_address: toAddress,
|
|
1158
|
+
function_selector: "transfer(address,uint256)",
|
|
1159
|
+
fee_limit: 1e8,
|
|
1160
|
+
call_value: 0,
|
|
1161
|
+
visible: true
|
|
1162
|
+
} : {
|
|
1163
|
+
owner_address: account,
|
|
1164
|
+
to_address: toAddress,
|
|
1165
|
+
amount: sunAmount,
|
|
1166
|
+
visible: true
|
|
1167
|
+
};
|
|
1168
|
+
const res = await fetch(endpoint, {
|
|
1169
|
+
method: "POST",
|
|
1170
|
+
headers: { "Content-Type": "application/json" },
|
|
1171
|
+
body: JSON.stringify(body)
|
|
1172
|
+
});
|
|
1173
|
+
if (!res.ok) {
|
|
1174
|
+
throw new DecaneError(
|
|
1175
|
+
5022 /* PROVIDER_ERROR */,
|
|
1176
|
+
`Failed to build Tron transaction: ${res.statusText}`
|
|
1177
|
+
);
|
|
1178
|
+
}
|
|
1179
|
+
const json = await res.json();
|
|
1180
|
+
unsignedTx = json.transaction ?? json;
|
|
1181
|
+
}
|
|
1182
|
+
let signedTx;
|
|
1183
|
+
if (tronWeb?.trx?.sign) {
|
|
1184
|
+
signedTx = await tronWeb.trx.sign(unsignedTx);
|
|
1185
|
+
} else {
|
|
1186
|
+
signedTx = await provider.request({
|
|
1187
|
+
method: "tron_signTransaction",
|
|
1188
|
+
params: unsignedTx
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
let txid;
|
|
1192
|
+
if (tronWeb?.trx?.sendRawTransaction) {
|
|
1193
|
+
const result = await tronWeb.trx.sendRawTransaction(signedTx);
|
|
1194
|
+
txid = result?.txid;
|
|
1195
|
+
} else {
|
|
1196
|
+
const result = await provider.request({
|
|
1197
|
+
method: "tron_sendRawTransaction",
|
|
1198
|
+
params: signedTx
|
|
1199
|
+
});
|
|
1200
|
+
txid = result?.txid;
|
|
1201
|
+
}
|
|
1202
|
+
if (!txid) {
|
|
1203
|
+
throw new DecaneError(5022 /* PROVIDER_ERROR */, "Tron transaction broadcast failed");
|
|
1204
|
+
}
|
|
1205
|
+
return txid;
|
|
1206
|
+
}
|
|
1131
1207
|
default:
|
|
1132
1208
|
throw new DecaneError(
|
|
1133
1209
|
5030 /* METHOD_NOT_SUPPORTED */,
|
|
@@ -2425,6 +2501,11 @@ function useDecaneContext() {
|
|
|
2425
2501
|
|
|
2426
2502
|
// src/ui/hooks.ts
|
|
2427
2503
|
var import_react4 = require("react");
|
|
2504
|
+
function toDecaneError(err) {
|
|
2505
|
+
if (err instanceof DecaneError) return err;
|
|
2506
|
+
const msg = err instanceof Error ? err.message : err?.message != null ? String(err.message) : String(err);
|
|
2507
|
+
return new DecaneError(5022 /* PROVIDER_ERROR */, msg);
|
|
2508
|
+
}
|
|
2428
2509
|
function useDecane() {
|
|
2429
2510
|
const { provider, theme, setTheme } = useDecaneContext();
|
|
2430
2511
|
const [, forceUpdate] = (0, import_react4.useState)(0);
|
|
@@ -2502,7 +2583,7 @@ function useChainSwitch() {
|
|
|
2502
2583
|
});
|
|
2503
2584
|
forceUpdate((n) => n + 1);
|
|
2504
2585
|
} catch (err) {
|
|
2505
|
-
const e =
|
|
2586
|
+
const e = toDecaneError(err);
|
|
2506
2587
|
setError(e);
|
|
2507
2588
|
throw err;
|
|
2508
2589
|
} finally {
|
|
@@ -2553,7 +2634,7 @@ function useSignMessage() {
|
|
|
2553
2634
|
setSignature(sig);
|
|
2554
2635
|
return sig;
|
|
2555
2636
|
} catch (err) {
|
|
2556
|
-
const e =
|
|
2637
|
+
const e = toDecaneError(err);
|
|
2557
2638
|
setError(e);
|
|
2558
2639
|
throw err;
|
|
2559
2640
|
} finally {
|
|
@@ -2591,7 +2672,7 @@ function useSendTransaction() {
|
|
|
2591
2672
|
setTxHash(hash);
|
|
2592
2673
|
return hash;
|
|
2593
2674
|
} catch (err) {
|
|
2594
|
-
const e =
|
|
2675
|
+
const e = toDecaneError(err);
|
|
2595
2676
|
setError(e);
|
|
2596
2677
|
throw err;
|
|
2597
2678
|
} finally {
|
|
@@ -2628,7 +2709,7 @@ function useSignTypedData() {
|
|
|
2628
2709
|
setSignature(sig);
|
|
2629
2710
|
return sig;
|
|
2630
2711
|
} catch (err) {
|
|
2631
|
-
const e =
|
|
2712
|
+
const e = toDecaneError(err);
|
|
2632
2713
|
setError(e);
|
|
2633
2714
|
throw err;
|
|
2634
2715
|
} finally {
|