hodl-wallet 1.8.0 → 1.8.2
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.
|
@@ -47,7 +47,26 @@ export default class BaseNetwork {
|
|
|
47
47
|
throw new Error("Method 'validateMnemonic' must be implemented.");
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
async getTokenBalance(address, tokenSymbol) {
|
|
51
|
+
throw new Error("Method 'getTokenBalance' must be implemented.");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getTokenBalances(address) {
|
|
55
|
+
const balances = [];
|
|
56
|
+
|
|
57
|
+
// Get native token balance
|
|
58
|
+
const nativeBalance = await this.getBalance(address);
|
|
59
|
+
balances.push([this.config.nativeToken, parseFloat(nativeBalance)]);
|
|
60
|
+
|
|
61
|
+
// Get balances for all configured tokens
|
|
62
|
+
for (const symbol of Object.keys(this.config.tokens)) {
|
|
63
|
+
const tokenBalance = await this.getTokenBalance(address, symbol);
|
|
64
|
+
balances.push([symbol, tokenBalance]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return balances;
|
|
68
|
+
}
|
|
69
|
+
|
|
51
70
|
async sendSignedTransaction(signedTx) {
|
|
52
71
|
throw new Error("Method 'sendSignedTransaction' must be implemented.");
|
|
53
72
|
}
|
|
@@ -30,14 +30,11 @@ export default class BitcoinNetwork extends BaseNetwork {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
balances.push([this.config.nativeToken, nativeBalance]);
|
|
39
|
-
|
|
40
|
-
return balances;
|
|
33
|
+
async getTokenBalance(address, tokenSymbol) {
|
|
34
|
+
if (tokenSymbol === this.config.nativeToken) {
|
|
35
|
+
return await this.getBalance(address);
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Token ${tokenSymbol} not supported on Bitcoin network`);
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
async transfer(from, to, amount, options = {}) {
|
|
@@ -137,32 +137,6 @@ export default class TONNetwork extends BaseNetwork {
|
|
|
137
137
|
}));
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
async getTokenBalances(address) {
|
|
141
|
-
const balances = [];
|
|
142
|
-
|
|
143
|
-
// Add native TON balance
|
|
144
|
-
try {
|
|
145
|
-
const nativeBalance = await this.getBalance(address);
|
|
146
|
-
balances.push([this.config.nativeToken, nativeBalance]);
|
|
147
|
-
} catch (error) {
|
|
148
|
-
console.error('Failed to get TON balance:', error);
|
|
149
|
-
balances.push([this.config.nativeToken, 0]);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Add token balances (not implemented yet)
|
|
153
|
-
for (const tokenSymbol in this.config.tokens) {
|
|
154
|
-
try {
|
|
155
|
-
const tokenBalance = await this.getTokenBalance(address, tokenSymbol);
|
|
156
|
-
balances.push([tokenSymbol, tokenBalance]);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
console.error(`Failed to get ${tokenSymbol} balance:`, error);
|
|
159
|
-
balances.push([tokenSymbol, 0]);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return balances;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
140
|
async sendSignedTransaction(signedTx) {
|
|
167
141
|
// For TON, the transaction is already sent and signedTx contains the result
|
|
168
142
|
let transactionHash;
|
|
@@ -98,30 +98,21 @@ export default class Web3Network extends BaseNetwork {
|
|
|
98
98
|
return this.transfer(account, recipient, amount, { gasLimit, gasPrice });
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
async
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// Get native token balance
|
|
105
|
-
const nativeBalance = await this.getBalance(address);
|
|
106
|
-
balances.push([this.config.nativeToken, parseFloat(nativeBalance)]);
|
|
107
|
-
|
|
108
|
-
// Get balances for all configured tokens
|
|
109
|
-
for (const [symbol, tokenConfig] of Object.entries(this.config.tokens)) {
|
|
110
|
-
const contract = new this.web3.eth.Contract(
|
|
111
|
-
ERC20_ABI,
|
|
112
|
-
tokenConfig.address
|
|
113
|
-
);
|
|
114
|
-
const balance = await contract.methods.balanceOf(address).call();
|
|
115
|
-
const decimals = await contract.methods.decimals().call();
|
|
116
|
-
|
|
117
|
-
const formattedBalance = Number(
|
|
118
|
-
(BigInt(balance) * 100n) / (10n ** BigInt(decimals))
|
|
119
|
-
) / 100;
|
|
120
|
-
|
|
121
|
-
balances.push([symbol, formattedBalance]);
|
|
101
|
+
async getTokenBalance(address, tokenSymbol) {
|
|
102
|
+
if (tokenSymbol === this.config.nativeToken) {
|
|
103
|
+
return await this.getBalance(address);
|
|
122
104
|
}
|
|
123
105
|
|
|
124
|
-
|
|
106
|
+
const tokenConfig = this.config.tokens[tokenSymbol];
|
|
107
|
+
if (!tokenConfig) throw new Error(`Token ${tokenSymbol} not supported`);
|
|
108
|
+
|
|
109
|
+
const contract = new this.web3.eth.Contract(ERC20_ABI, tokenConfig.address);
|
|
110
|
+
const balance = await contract.methods.balanceOf(address).call();
|
|
111
|
+
const decimals = await contract.methods.decimals().call();
|
|
112
|
+
|
|
113
|
+
return Number(
|
|
114
|
+
(BigInt(balance) * 100n) / (10n ** BigInt(decimals))
|
|
115
|
+
) / 100;
|
|
125
116
|
}
|
|
126
117
|
|
|
127
118
|
async privateKeyToAccount(privateKey) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hodl-wallet",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "🧊 HODL Wallet - Fast CLI crypto wallet!",
|
|
5
5
|
"author": "Martin Clasen",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"bep20",
|
|
30
30
|
"bnb",
|
|
31
31
|
"eth",
|
|
32
|
+
"ton",
|
|
32
33
|
"binance",
|
|
33
34
|
"trust",
|
|
34
35
|
"blockchain",
|