Update in order to user price per byte

This commit is contained in:
Arnaud 2025-02-10 22:56:29 +01:00
parent df09719bb3
commit 799db86cc2
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
7 changed files with 43 additions and 34 deletions

8
package-lock.json generated
View File

@ -10,7 +10,7 @@
"license": "MIT",
"dependencies": {
"@codex-storage/marketplace-ui-components": "^0.0.51",
"@codex-storage/sdk-js": "^0.0.18",
"@codex-storage/sdk-js": "^0.0.19",
"@sentry/browser": "^8.32.0",
"@sentry/react": "^8.31.0",
"@tanstack/react-query": "^5.51.15",
@ -433,9 +433,9 @@
}
},
"node_modules/@codex-storage/sdk-js": {
"version": "0.0.18",
"resolved": "https://registry.npmjs.org/@codex-storage/sdk-js/-/sdk-js-0.0.18.tgz",
"integrity": "sha512-FbQFRJgSuol6P00Wk76XShSGDIlQpTEr4Zgt3Ze1uRxC8gVpVRiHME2Z5/EOq7Fm25So9aCSD7MSKDULanHDpQ==",
"version": "0.0.19",
"resolved": "https://registry.npmjs.org/@codex-storage/sdk-js/-/sdk-js-0.0.19.tgz",
"integrity": "sha512-MLA7Q593pzLszcpaaZ5gu62jKCItXub1FpN19/sWlqEvQ9e1kzAMsN+pl915EQCuNT/sf5nmR3PVELde3l/yIA==",
"license": "MIT",
"dependencies": {
"valibot": "^0.32.0"

View File

@ -27,7 +27,7 @@
],
"dependencies": {
"@codex-storage/marketplace-ui-components": "^0.0.51",
"@codex-storage/sdk-js": "^0.0.18",
"@codex-storage/sdk-js": "^0.0.19",
"@sentry/browser": "^8.32.0",
"@sentry/react": "^8.31.0",
"@tanstack/react-query": "^5.51.15",

View File

@ -80,7 +80,7 @@ export function PurchasesTable() {
["request id"],
["duration", onSortByDuration],
["slots"],
["reward", onSortByReward],
["price per byte", onSortByReward],
["proof probability"],
["state", onSortByState],
] satisfies [string, ((state: TabSortState) => void)?][];
@ -92,7 +92,6 @@ export function PurchasesTable() {
const ask = p.request.ask;
const duration = parseInt(ask.duration, 10);
const pf = parseInt(ask.proofProbability, 10);
const reward = PurchaseUtils.calculatePrice(p.request);
return (
<Row
cells={[
@ -105,7 +104,7 @@ export function PurchasesTable() {
<TruncateCell value={r.id} />,
<Cell>{Times.pretty(duration)}</Cell>,
<Cell>{ask.slots.toString()}</Cell>,
<Cell>{reward + " CDX"}</Cell>,
<Cell>{p.request.ask.pricePerBytePerSecond + " CDX"}</Cell>,
<Cell>{pf.toString()}</Cell>,
<CustomStateCellRender state={p.state} message={p.error} />,
]}></Row>

View File

@ -21,12 +21,11 @@ export const PurchaseUtils = {
? Number(b.request.ask.duration) - Number(a.request.ask.duration)
: Number(a.request.ask.duration) - Number(b.request.ask.duration),
sortByReward:
(state: TabSortState) => (a: CodexPurchase, b: CodexPurchase) =>
state === "desc"
? PurchaseUtils.calculatePrice(b.request) -
PurchaseUtils.calculatePrice(a.request)
: PurchaseUtils.calculatePrice(a.request) -
PurchaseUtils.calculatePrice(b.request),
(state: TabSortState) => (a: CodexPurchase, b: CodexPurchase) => {
const aPrice = parseInt(a.request.ask.pricePerBytePerSecond, 10);
const bPrice = parseInt(b.request.ask.pricePerBytePerSecond, 10);
return state === "desc" ? bPrice - aPrice : aPrice - bPrice;
},
sortByUploadedAt:
(state: TabSortState, table: Record<string, number>) =>
(a: CodexPurchase, b: CodexPurchase) => {

View File

@ -83,13 +83,26 @@ export function StorageRequestCreate() {
WebStorage.set("storage-request-step", step);
if (step == CONFIRM_STATE) {
const { availability, availabilityUnit, expiration, reward, ...rest } =
storageRequest;
const {
availability,
availabilityUnit,
expiration,
reward,
collateral,
proofProbability,
cid,
nodes,
tolerance,
} = storageRequest;
mutateAsync({
...rest,
pricePerBytePerSecond: reward,
duration: Math.trunc(availability * Times.value(availabilityUnit)),
pricePerBytePerSecond: reward,
proofProbability,
collateralPerByte: collateral,
expiry: expiration * 60,
cid,
nodes,
tolerance,
});
} else {
dispatch({

View File

@ -282,7 +282,7 @@ export function StorageRequestReview({
onChange={onAvailabilityChange}
onValidation={isInvalidAvailability}></Commitment>
<CardNumbers
helper="Represents how much collateral is asked from hosts if they don't fulfill the contract."
helper="Represents how much collateral is asked from hosts per byte if they don't fulfill the contract."
id="collateral"
unit={"Collateral"}
value={storageRequest.collateral.toString()}

View File

@ -7,10 +7,7 @@ import {
import { CodexSdk as Sdk } from "./sdk/codex";
import { WebStorage } from "./utils/web-storage";
class CodexDataMock extends CodexData {
}
class CodexDataMock extends CodexData {}
class CodexMarketplaceMock extends CodexMarketplace {
// override async purchases(): Promise<SafeValue<CodexPurchase[]>> {
@ -31,26 +28,29 @@ class CodexMarketplaceMock extends CodexMarketplace {
// }
/**
* Maintains a temporary link between the CID and the file metadata.
* When the metadata is available in the manifest, the CID link
* should still be maintained, but the metadata should be retrieved
* Maintains a temporary link between the CID and the file metadata.
* When the metadata is available in the manifest, the CID link
* should still be maintained, but the metadata should be retrieved
* using a REST API call.
*/
override async createStorageRequest(input: CodexCreateStorageRequestInput): Promise<SafeValue<string>> {
const res = await super.createStorageRequest(input)
override async createStorageRequest(
input: CodexCreateStorageRequestInput
): Promise<SafeValue<string>> {
console.info(input);
const res = await super.createStorageRequest(input);
if (res.error) {
return res
console.error(res.data);
return res;
}
await WebStorage.purchases.set("0x" + res.data, input.cid)
await WebStorage.purchases.set("0x" + res.data, input.cid);
// await PurchaseDatesStorage.set(res.data, new Date().toJSON())
return res
return res;
}
// override createStorageRequest(
// input: CodexCreateStorageRequestInput
// ): Promise<SafeValue<string>> {
@ -139,5 +139,3 @@ export const CodexSdk = {
marketplace: () => new CodexMarketplaceMock(CodexSdk.url()),
data: () => new CodexDataMock(CodexSdk.url()),
};