Skip to content

Commit fb0ccb9

Browse files
snadrusLexLuthr
andauthored
wallet friendly names (#317)
* friendly wallet names * short name and clipboard copy --------- Co-authored-by: LexLuthr <[email protected]>
1 parent 53e0da3 commit fb0ccb9

File tree

19 files changed

+467
-34
lines changed

19 files changed

+467
-34
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE TABLE wallet_names (
2+
wallet VARCHAR PRIMARY KEY,
3+
name VARCHAR(60) NOT NULL UNIQUE
4+
);

web/api/webrpc/market_filters.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/filecoin-project/go-state-types/builtin"
1414
"github.com/filecoin-project/go-state-types/builtin/v15/market"
1515

16-
"github.com/filecoin-project/lotus/chain/types"
1716
"github.com/filecoin-project/lotus/node/modules/dtypes"
1817
)
1918

@@ -112,11 +111,7 @@ func (a *WebRPC) SetClientFilters(ctx context.Context, name string, active bool,
112111
if err != nil {
113112
return xerrors.Errorf("invalid wallet address: %w", err)
114113
}
115-
client, err := a.deps.Chain.StateLookupID(ctx, w, types.EmptyTSK)
116-
if err != nil {
117-
return xerrors.Errorf("wallet not found: %w", err)
118-
}
119-
clients = append(clients, client.String())
114+
clients = append(clients, w.String())
120115
}
121116
}
122117

@@ -258,11 +253,7 @@ func (a *WebRPC) AddClientFilters(ctx context.Context, name string, active bool,
258253
if err != nil {
259254
return xerrors.Errorf("invalid wallet address: %w", err)
260255
}
261-
client, err := a.deps.Chain.StateLookupID(ctx, w, types.EmptyTSK)
262-
if err != nil {
263-
return xerrors.Errorf("wallet not found: %w", err)
264-
}
265-
clients = append(clients, client.String())
256+
clients = append(clients, w.String())
266257
}
267258
}
268259

@@ -382,12 +373,7 @@ func (a *WebRPC) AddAllowDenyList(ctx context.Context, wallet string, status boo
382373
return xerrors.Errorf("invalid wallet address: %w", err)
383374
}
384375

385-
client, err := a.deps.Chain.StateLookupID(ctx, w, types.EmptyTSK)
386-
if err != nil {
387-
return xerrors.Errorf("wallet not found: %w", err)
388-
}
389-
390-
n, err := a.deps.DB.Exec(ctx, "INSERT INTO market_allow_list (wallet, status) VALUES ($1, $2)", client.String(), status)
376+
n, err := a.deps.DB.Exec(ctx, "INSERT INTO market_allow_list (wallet, status) VALUES ($1, $2)", w.String(), status)
391377
if err != nil {
392378
return err
393379
}

web/api/webrpc/wallet.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package webrpc
2+
3+
import (
4+
"context"
5+
"errors"
6+
"sync"
7+
8+
"github.com/filecoin-project/curio/harmony/harmonydb"
9+
)
10+
11+
var walletOnce sync.Once
12+
var walletFriendlyNames = map[string]string{}
13+
var walletFriendlyNamesLock sync.Mutex
14+
15+
func (a *WebRPC) WalletName(ctx context.Context, id string) (string, error) {
16+
walletOnce.Do(func() {
17+
populateWalletFriendlyNames(a.deps.DB)
18+
})
19+
walletFriendlyNamesLock.Lock()
20+
defer walletFriendlyNamesLock.Unlock()
21+
name, ok := walletFriendlyNames[id]
22+
if ok {
23+
return name, nil
24+
}
25+
return id, nil
26+
}
27+
28+
func (a *WebRPC) WalletNameChange(ctx context.Context, wallet, newName string) error {
29+
if len(newName) == 0 {
30+
return errors.New("name cannot be empty")
31+
}
32+
_, err := a.deps.DB.Exec(ctx, `UPDATE wallet_names SET name = $1 WHERE wallet = $2`, newName, wallet)
33+
if err != nil {
34+
log.Errorf("failed to set wallet name for %s: %s", wallet, err)
35+
return err
36+
}
37+
walletFriendlyNamesLock.Lock()
38+
defer walletFriendlyNamesLock.Unlock()
39+
walletFriendlyNames[wallet] = newName
40+
return nil
41+
}
42+
43+
func populateWalletFriendlyNames(db *harmonydb.DB) {
44+
// Get all wallet from DB
45+
var idNames []struct {
46+
Wallet string `db:"wallet"`
47+
Name string `db:"name"`
48+
}
49+
50+
err := db.Select(context.Background(), &idNames, `SELECT wallet, name FROM wallet_names`)
51+
if err != nil {
52+
log.Errorf("failed to get wallet names: %s", err)
53+
return
54+
}
55+
56+
walletFriendlyNamesLock.Lock()
57+
defer walletFriendlyNamesLock.Unlock()
58+
for _, idName := range idNames {
59+
walletFriendlyNames[idName.Wallet] = idName.Name
60+
}
61+
}
62+
63+
func (a *WebRPC) WalletNames(ctx context.Context) (map[string]string, error) {
64+
walletOnce.Do(func() {
65+
populateWalletFriendlyNames(a.deps.DB)
66+
})
67+
walletFriendlyNamesLock.Lock()
68+
defer walletFriendlyNamesLock.Unlock()
69+
return walletFriendlyNames, nil
70+
}
71+
72+
func (a *WebRPC) WalletAdd(ctx context.Context, wallet, name string) error {
73+
if len(name) == 0 {
74+
return errors.New("name cannot be empty")
75+
}
76+
if len(wallet) == 0 {
77+
return errors.New("wallet cannot be empty")
78+
}
79+
_, err := a.deps.DB.Exec(ctx, `INSERT INTO wallet_names (wallet, name) VALUES ($1, $2)`, wallet, name)
80+
if err != nil {
81+
log.Errorf("failed to add wallet name for %s: %s", wallet, err)
82+
return err
83+
}
84+
85+
walletFriendlyNamesLock.Lock()
86+
walletFriendlyNames[wallet] = name
87+
defer walletFriendlyNamesLock.Unlock()
88+
return nil
89+
}
90+
91+
func (a *WebRPC) WalletRemove(ctx context.Context, wallet string) error {
92+
_, err := a.deps.DB.Exec(ctx, `DELETE FROM wallet_names WHERE wallet = $1`, wallet)
93+
if err != nil {
94+
log.Errorf("failed to remove wallet name for %s: %s", wallet, err)
95+
return err
96+
}
97+
walletFriendlyNamesLock.Lock()
98+
defer walletFriendlyNamesLock.Unlock()
99+
delete(walletFriendlyNames, wallet)
100+
return nil
101+
}

web/static/lib/cu-wallet.mjs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { LitElement, html } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/all/lit-all.min.js';
2+
import RPCCall from '/lib/jsonrpc.mjs';
3+
import '/lib/clipboard-copy.mjs';
4+
5+
class CuWallet extends LitElement {
6+
static properties = {
7+
wallet_id: { type: String },
8+
name: { state: true },
9+
havername: { state: true }
10+
};
11+
12+
constructor() {
13+
super();
14+
this.wallet_id = '';
15+
this.name = '';
16+
this.havename = false;
17+
}
18+
19+
connectedCallback() {
20+
super.connectedCallback();
21+
this.loadWallet();
22+
}
23+
24+
async loadWallet() {
25+
if (!this.wallet_id) return;
26+
27+
try {
28+
const result = await RPCCall('WalletName', [this.wallet_id]);
29+
console.log('WalletName result:', result);
30+
this.name = result || this.wallet_id;
31+
this.havename = (this.name !== this.wallet_id);
32+
} catch (err) {
33+
console.error('Error during WalletName operation:', err);
34+
this.name = this.wallet_id; // fallback
35+
}
36+
}
37+
38+
createRenderRoot() {
39+
// Render in light DOM so the text can be styled normally and picked up by parent CSS
40+
return this;
41+
}
42+
43+
render() {
44+
if (!this.havename){
45+
const shortened = `${this.wallet_id.slice(0, 6)}...${this.wallet_id.slice(-6)}`;
46+
return html`
47+
<span title="${this.wallet_id}">${shortened}</span>
48+
<clipboard-copy .text=${this.wallet_id}></clipboard-copy>
49+
</span>
50+
`;
51+
}
52+
return html`
53+
<a href="/pages/wallet/?id=${this.wallet_id}"><span title="${this.wallet_id}">${this.name}</span></a>
54+
`;
55+
}
56+
}
57+
58+
customElements.define('cu-wallet', CuWallet);

web/static/pages/actor/actor-detail.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/all/lit-all.min.js';
22
import '/actor-summary.mjs'; // <sector-expirations>
33
import RPCCall from '/lib/jsonrpc.mjs';
4+
import '/lib/cu-wallet.mjs';
45

56
customElements.define('actor-detail', class Actor extends LitElement {
67
connectedCallback() {
@@ -138,19 +139,19 @@ customElements.define('actor-detail', class Actor extends LitElement {
138139
</tr>
139140
<tr>
140141
<td>Owner Address:</td>
141-
<td>${actorInfo.OwnerAddress}</td>
142+
<td><cu-wallet wallet_id=${actorInfo.OwnerAddress}></cu-wallet></td>
142143
</tr>
143144
<tr>
144145
<td>Beneficiary:</td>
145-
<td>${actorInfo.Beneficiary}</td>
146+
<td><cu-wallet wallet_id=${actorInfo.Beneficiary}></cu-wallet></td>
146147
</tr>
147148
<tr>
148149
<td>Worker Address:</td>
149-
<td>${actorInfo.WorkerAddress}</td>
150+
<td><cu-wallet wallet_id=${actorInfo.WorkerAddress}></cu-wallet></td>
150151
</tr>
151152
<tr>
152153
<td>Peer ID:</td>
153-
<td>${actorInfo.PeerID}</td>
154+
<td><cu-wallet wallet_id=${actorInfo.PeerID}></cu-wallet></td>
154155
</tr>
155156
156157
<tr>
@@ -206,7 +207,7 @@ customElements.define('actor-detail', class Actor extends LitElement {
206207
${actorInfo.PendingOwnerAddress ? html`
207208
<tr>
208209
<td>PendingOwnerAddress:</td>
209-
<td>${actorInfo.PendingOwnerAddress}</td>
210+
<td><cu-wallet wallet_id=${actorInfo.PendingOwnerAddress}></cu-wallet></td>
210211
</tr>
211212
`
212213
: null
@@ -265,7 +266,7 @@ customElements.define('actor-detail', class Actor extends LitElement {
265266
${actorInfo.Wallets.map(wallet => html`
266267
<tr>
267268
<td>${wallet.Type}</td>
268-
<td>${wallet.Address}</td>
269+
<td><cu-wallet wallet_id=${wallet.Address}></cu-wallet></td>
269270
<td>${wallet.Balance}</td>
270271
</tr>
271272
`)

web/static/pages/actor/index.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<script type="module" src="/ux/curio-ux.mjs"></script>
88
<script type="module" src="/ux/components/Drawer.mjs"></script>
99
<script type="module" src="actor-detail.mjs"></script>
10+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
11+
integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
12+
crossorigin="anonymous" />
1013
</head>
1114
<body style="visibility:hidden" data-bs-theme="dark">
1215
<curio-ux>
@@ -25,10 +28,5 @@ <h1>Miner Info</h1>
2528
</section>
2629
</div>
2730
</curio-ux>
28-
<!--<script>-->
29-
<!-- let d = document.createElement('actor-detail');-->
30-
<!-- d.id = new URLSearchParams(window.location.search).get('id');-->
31-
<!-- document.querySelector('curio-ux').appendChild(d);-->
32-
<!--</script>-->
3331
</body>
3432
</html>

web/static/pages/ipni/ipni_status.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class IpniStatus extends LitElement {
107107
data-bs-parent="#ipniStatusAccordion"
108108
>
109109
<div class="accordion-body">
110-
<p><strong>PeerID:</strong> ${provider.peer_id}</p>
110+
<p><strong>PeerID:</strong>${provider.peer_id}></p>
111111
<p><strong>Head:</strong> <a href="/pages/ipni/?ad_cid=${provider.head}">${provider.head}</a></p>
112112
${provider.sync_status && provider.sync_status.length > 0 ? provider.sync_status.map((status) => html`
113113
<div class="sync-status">

web/static/pages/market-settings/allow-list.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/all/lit-all.min.js';
22
import RPCCall from '/lib/jsonrpc.mjs';
3+
import '/lib/cu-wallet.mjs';
34

45
class AllowList extends LitElement {
56
static properties = {
@@ -89,8 +90,10 @@ class AllowList extends LitElement {
8990
<link
9091
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
9192
rel="stylesheet"
93+
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
9294
crossorigin="anonymous"
9395
/>
96+
<link rel="stylesheet" href="/ux/main.css" onload="document.body.style.visibility = 'initial'" />
9497
<div class="container">
9598
<h2>Allow/Deny List
9699
<button class="info-btn">
@@ -125,9 +128,10 @@ class AllowList extends LitElement {
125128
${this.allowList.map(
126129
(entry) => html`
127130
<tr>
128-
<td>${entry.wallet}</td>
131+
<td><cu-wallet wallet_id=${entry.wallet}></cu-wallet></td>
129132
<td>${entry.status ? 'Allow' : 'Deny'}</td>
130133
<td>
134+
<div class="d-flex gap-2">
131135
<button
132136
class="btn btn-secondary btn-sm"
133137
@click="${() => this.editAllowListEntry(entry)}"
@@ -140,6 +144,7 @@ class AllowList extends LitElement {
140144
>
141145
Remove
142146
</button>
147+
</div>
143148
</td>
144149
</tr>
145150
`

web/static/pages/market-settings/client-filters.mjs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/all/lit-all.min.js';
22
import RPCCall from '/lib/jsonrpc.mjs';
3+
import '/lib/cu-wallet.mjs';
34

45
class ClientFilters extends LitElement {
56
static properties = {
@@ -108,6 +109,7 @@ class ClientFilters extends LitElement {
108109
rel="stylesheet"
109110
crossorigin="anonymous"
110111
/>
112+
<link rel="stylesheet" href="/ux/main.css" onload="document.body.style.visibility = 'initial'" />
111113
<div class="container">
112114
<h2>Client Filters
113115
<button class="info-btn">
@@ -150,13 +152,30 @@ class ClientFilters extends LitElement {
150152
<tr>
151153
<td>${filter.name}</td>
152154
<td>${filter.active ? 'Yes' : 'No'}</td>
153-
<td>${(filter.wallets || []).join(', ')}</td>
154-
<td>${(filter.peers || []).join(', ')}</td>
155+
<td>
156+
${(filter.wallets || []).length === 0
157+
? html`-`
158+
: filter.wallets.map(
159+
(w, i, arr) => html`
160+
<cu-wallet wallet_id="${w}"></cu-wallet>${i < arr.length - 1 ? ', ' : ''}
161+
`
162+
)}
163+
</td>
164+
<td>
165+
${(filter.peers || []).length === 0
166+
? html`-`
167+
: filter.peers.map(
168+
(p, i, arr) => html`
169+
<cu-wallet wallet_id="${p}"></cu-wallet>${i < arr.length - 1 ? ', ' : ''}
170+
`
171+
)}
172+
</td>
155173
<td>${(filter.pricing_filters || []).join(', ')}</td>
156174
<td>${filter.max_deals_per_hour}</td>
157175
<td>${this.formatBytes(filter.max_deal_size_per_hour)}</td>
158176
<td>${filter.info || ''}</td>
159177
<td>
178+
<div class="d-flex gap-2">
160179
<button
161180
class="btn btn-secondary btn-sm"
162181
@click="${() => this.editClientFilter(filter)}"
@@ -169,6 +188,7 @@ class ClientFilters extends LitElement {
169188
>
170189
Remove
171190
</button>
191+
</div>
172192
</td>
173193
</tr>
174194
`

web/static/pages/market-settings/defaults.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class DefaultMarketFilters extends LitElement {
3333
rel="stylesheet"
3434
crossorigin="anonymous"
3535
/>
36+
<link rel="stylesheet" href="/ux/main.css" onload="document.body.style.visibility = 'initial'" />
3637
<div class="container">
3738
<h2>Filter Settings</h2>
3839
<table class="table table-dark table-striped">

0 commit comments

Comments
 (0)