Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deal removal and list #428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions web/api/webrpc/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,14 @@ func (a *WebRPC) StorageDealInfo(ctx context.Context, deal string) (*StorageDeal
}

type StorageDealList struct {
ID string `db:"uuid" json:"id"`
MinerID int64 `db:"sp_id" json:"sp_id"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
PieceCid string `db:"piece_cid" json:"piece_cid"`
PieceSize int64 `db:"piece_size" json:"piece_size"`
Complete bool `db:"complete" json:"complete"`
Miner string `json:"miner"`
ID string `db:"uuid" json:"id"`
MinerID int64 `db:"sp_id" json:"sp_id"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
PieceCid string `db:"piece_cid" json:"piece_cid"`
PieceSize int64 `db:"piece_size" json:"piece_size"`
Processed bool `db:"processed" json:"processed"`
Error sql.NullString `db:"error" json:"error"`
Miner string `json:"miner"`
}

func (a *WebRPC) MK12StorageDealList(ctx context.Context, limit int, offset int) ([]*StorageDealList, error) {
Expand All @@ -400,7 +401,8 @@ func (a *WebRPC) MK12StorageDealList(ctx context.Context, limit int, offset int)
md.created_at,
md.piece_cid,
md.piece_size,
coalesce(mm12dp.complete, true) as complete
md.error,
coalesce(mm12dp.complete, true) as processed
FROM market_mk12_deals md
LEFT JOIN market_mk12_deal_pipeline mm12dp ON md.uuid = mm12dp.uuid
ORDER BY created_at DESC
Expand Down Expand Up @@ -428,7 +430,9 @@ func (a *WebRPC) LegacyStorageDealList(ctx context.Context, limit int, offset in
sp_id,
created_at,
piece_cid,
piece_size
piece_size,
NULL AS error,
TRUE AS processed
FROM market_legacy_deals
ORDER BY created_at DESC
LIMIT $1 OFFSET $2;`, limit, offset)
Expand Down Expand Up @@ -990,7 +994,7 @@ func (a *WebRPC) MK12DealPipelineRemove(ctx context.Context, uuid string) error
}

//Mark failure for deal
n, err := tx.Exec(`WITH updated AS (
_, err = tx.Exec(`WITH updated AS (
UPDATE market_mk12_deals
SET error = $1
WHERE uuid = $2
Expand All @@ -1003,9 +1007,6 @@ func (a *WebRPC) MK12DealPipelineRemove(ctx context.Context, uuid string) error
if err != nil {
return false, xerrors.Errorf("failed to mark deal %s as failed", uuid)
}
if n != 1 {
return false, xerrors.Errorf("expected 1 row to be updated, got %d", n)
}

// Remove market_mk12_deal_pipeline entry
_, err = tx.Exec(`DELETE FROM market_mk12_deal_pipeline WHERE uuid = $1`, uuid)
Expand Down Expand Up @@ -1458,7 +1459,8 @@ func (a *WebRPC) MK12DDOStorageDealList(ctx context.Context, limit int, offset i
md.created_at,
md.piece_cid,
md.piece_size,
coalesce(mm12dp.complete, true) as complete
md.error,
coalesce(mm12dp.complete, true) as processed
FROM market_direct_deals md
LEFT JOIN market_mk12_deal_pipeline mm12dp ON md.uuid = mm12dp.uuid
ORDER BY created_at DESC
Expand Down
6 changes: 4 additions & 2 deletions web/static/pages/mk12-deals/mk12-deals.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class MK12DealList extends LitElement {
<th>Provider</th>
<th>Piece CID</th>
<th>Piece Size</th>
<th>Stored</th>
<th>Processed</th>
<th>Error</th>
<!-- Add more columns as needed -->
</tr>
</thead>
Expand All @@ -93,7 +94,8 @@ class MK12DealList extends LitElement {
<td>${deal.miner}</td>
<td><a href="/pages/piece/?id=${deal.piece_cid}">${deal.piece_cid}</a></td>
<td>${this.formatBytes(deal.piece_size)}</td>
<td><done-not-done .value=${deal.complete}></done-not-done></td>
<td><done-not-done .value=${deal.processed}></done-not-done></td>
<td><error-or-not .value=${deal.error}></error-or-not></td>
</tr>
`
)}
Expand Down
6 changes: 4 additions & 2 deletions web/static/pages/mk12-deals/mk12ddo-list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class MK12DDODealList extends LitElement {
<th>Provider</th>
<th>Piece CID</th>
<th>Piece Size</th>
<th>Stored</th>
<th>Processed</th>
<th>Error</th>
<!-- Add more columns as needed -->
</tr>
</thead>
Expand All @@ -93,7 +94,8 @@ class MK12DDODealList extends LitElement {
<td>${deal.miner}</td>
<td><a href="/pages/piece/?id=${deal.piece_cid}">${deal.piece_cid}</a></td>
<td>${this.formatBytes(deal.piece_size)}</td>
<td><done-not-done .value=${deal.complete}></done-not-done></td>
<td><done-not-done .value=${deal.processed}></yes-no></td>
<td><error-or-not .value=${deal.error}></error-or-not></td>
</tr>
`
)}
Expand Down
27 changes: 27 additions & 0 deletions web/static/ux/yesno.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,30 @@ class DoneNotDone extends LitElement {

customElements.define('done-not-done', DoneNotDone);

class ErrorOrNot extends LitElement {
static properties = {
value: { type: Object }
};

static styles = css`
.no-error {
color: var(--color-success-main);
}
.error {
color: var(--color-warning-main);
}
`;

render() {
const isValidValue = this.value?.Valid && this.value?.String !== '';
const result = isValidValue ? 'Yes' : 'No';

return html`
<span class="${isValidValue ? 'error' : 'no-error'}">
${result}</span>
`;
}
}

customElements.define('error-or-not', ErrorOrNot);