clawmoney 0.15.38 → 0.15.39
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/commands/wallet.js +34 -7
- package/package.json +1 -1
package/dist/commands/wallet.js
CHANGED
|
@@ -2,7 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import ora from 'ora';
|
|
3
3
|
import { awalExec } from '../utils/awal.js';
|
|
4
4
|
import { apiGet } from '../utils/api.js';
|
|
5
|
-
import { loadConfig } from '../utils/config.js';
|
|
5
|
+
import { loadConfig, saveConfig } from '../utils/config.js';
|
|
6
6
|
// Base mainnet USDC contract + balanceOf(address) ABI selector.
|
|
7
7
|
// Keeping on-chain reads as a first-class path lets `wallet balance`
|
|
8
8
|
// skip the awal Electron bridge entirely, which is notorious for
|
|
@@ -88,21 +88,47 @@ export async function walletBalanceCommand() {
|
|
|
88
88
|
// Either half is allowed to fail — we print "(unavailable)" for the
|
|
89
89
|
// broken section and keep going.
|
|
90
90
|
const config = loadConfig();
|
|
91
|
+
// Wallet address lookup order:
|
|
92
|
+
// 1. ~/.clawmoney/config.yaml cache (instant)
|
|
93
|
+
// 2. Backend /api/v1/claw-agents/me (authoritative, ~200ms)
|
|
94
|
+
// 3. awal address (Electron cold-start, last resort, 5s cap)
|
|
95
|
+
// After a successful #2 we write the result back to the config so
|
|
96
|
+
// every future `wallet balance` hits path #1.
|
|
91
97
|
let walletAddress = config?.wallet_address ?? null;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
let addressSource = 'config';
|
|
99
|
+
let addressError = null;
|
|
100
|
+
if (!walletAddress && config?.api_key) {
|
|
101
|
+
try {
|
|
102
|
+
const resp = await apiGet('/api/v1/claw-agents/me', config.api_key);
|
|
103
|
+
if (resp.ok && typeof resp.data?.wallet_address === 'string' && resp.data.wallet_address) {
|
|
104
|
+
walletAddress = resp.data.wallet_address;
|
|
105
|
+
addressSource = 'api';
|
|
106
|
+
// Cache it so the next run is instant.
|
|
107
|
+
try {
|
|
108
|
+
saveConfig({ wallet_address: walletAddress });
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Non-fatal — we still have the address for THIS run.
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
addressError = err.message;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
96
119
|
if (!walletAddress) {
|
|
120
|
+
// Last resort: cold-start awal. Capped at 5s so a wedged wallet
|
|
121
|
+
// daemon can't block the command forever.
|
|
97
122
|
try {
|
|
98
123
|
const awalResult = await withTimeout(awalExec(['address']), 5_000, 'awal address');
|
|
99
124
|
const data = awalResult.data;
|
|
100
125
|
if (typeof data?.address === 'string' && data.address) {
|
|
101
126
|
walletAddress = data.address;
|
|
127
|
+
addressSource = 'awal';
|
|
102
128
|
}
|
|
103
129
|
}
|
|
104
130
|
catch (err) {
|
|
105
|
-
|
|
131
|
+
addressError = err.message;
|
|
106
132
|
}
|
|
107
133
|
}
|
|
108
134
|
const relayPromise = config?.api_key
|
|
@@ -121,8 +147,9 @@ export async function walletBalanceCommand() {
|
|
|
121
147
|
}
|
|
122
148
|
}
|
|
123
149
|
else {
|
|
124
|
-
onchainError =
|
|
150
|
+
onchainError = addressError ?? 'no wallet address in config';
|
|
125
151
|
}
|
|
152
|
+
void addressSource; // reserved for future debug display
|
|
126
153
|
const relayRows = await relayPromise;
|
|
127
154
|
spinner.stop();
|
|
128
155
|
console.log('');
|