mirror of
https://github.com/aljazceru/hypergolic.git
synced 2025-12-18 14:04:21 +01:00
problem: can't set product start time
This commit is contained in:
@@ -16,9 +16,9 @@
|
||||
export let product: Product;
|
||||
export let rocket: Rocket;
|
||||
|
||||
|
||||
let price: number = 0;
|
||||
let max: number = 0;
|
||||
let validAfter: number = 0;
|
||||
|
||||
let o = false;
|
||||
|
||||
@@ -33,12 +33,18 @@
|
||||
if (rocket.Event.author.pubkey != author.pubkey) {
|
||||
throw new Error(`${author.pubkey} is not the creator of this rocket`);
|
||||
}
|
||||
let event = rocket.UpsertProduct(product.ID(), price, max);
|
||||
event.ndk = $ndk
|
||||
event.publish().then((x) => {
|
||||
console.log(x);
|
||||
o = false
|
||||
}).catch(()=>{ console.log("failed to publish", event.rawEvent())});
|
||||
console.log(37, validAfter);
|
||||
let event = rocket.UpsertProduct(product.ID(), price, max, validAfter);
|
||||
event.ndk = $ndk;
|
||||
event
|
||||
.publish()
|
||||
.then((x) => {
|
||||
console.log(x);
|
||||
o = false;
|
||||
})
|
||||
.catch(() => {
|
||||
console.log('failed to publish', event.rawEvent());
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -74,6 +80,15 @@
|
||||
class="col-span-3"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label for="validAfter" class="text-right">Valid After</Label>
|
||||
<Input
|
||||
bind:value={validAfter}
|
||||
id="validAfter"
|
||||
placeholder="Cannot be purchased before this time (unix)"
|
||||
class="col-span-3"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Todo text={['validate input is a number']} />
|
||||
<Dialog.Footer>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
}
|
||||
|
||||
function checkNewZaps() {
|
||||
console.log(39);
|
||||
const currentTime = Date.now() / 1000;
|
||||
const recentZaps = Array.from(unratifiedZaps.values()).filter(
|
||||
(zap) =>
|
||||
|
||||
@@ -23,9 +23,24 @@
|
||||
if (!product.Validate()) {
|
||||
throw new Error('this should not happen');
|
||||
}
|
||||
//productFromRocket = rocket.Products().get(product.ID());
|
||||
});
|
||||
|
||||
function disabled(productFromRocket: RocketProduct): boolean {
|
||||
let disabled = false;
|
||||
if (!productFromRocket?.ValidNow()) {
|
||||
disabled = true;
|
||||
}
|
||||
if (
|
||||
productFromRocket.MaxPurchases() > 0 &&
|
||||
productFromRocket.MaxPurchases() - zapsForThisProduct(productFromRocket!).size == 0
|
||||
) {
|
||||
disabled = true;
|
||||
}
|
||||
return disabled;
|
||||
// productFromRocket.MaxPurchases() > 0 &&
|
||||
// productFromRocket.MaxPurchases() - zapsForThisProduct(productFromRocket).size == 0 && !productFromRocket.ValidNow()
|
||||
}
|
||||
|
||||
function zapsForThisProduct(product: RocketProduct): Map<string, ZapPurchase> {
|
||||
let m = new Map<string, ZapPurchase>();
|
||||
if (unratifiedZaps) {
|
||||
@@ -84,8 +99,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
<PayNow
|
||||
disabled={productFromRocket.MaxPurchases() > 0 &&
|
||||
productFromRocket.MaxPurchases() - zapsForThisProduct(productFromRocket).size == 0}
|
||||
disabled={disabled(productFromRocket)}
|
||||
{product}
|
||||
rocketProduct={rocket.Products().get(product.ID())}
|
||||
{rocket}
|
||||
@@ -102,7 +116,13 @@
|
||||
'max purchases',
|
||||
productFromRocket.MaxPurchases(),
|
||||
'price',
|
||||
productFromRocket.Price()
|
||||
productFromRocket.Price(),
|
||||
'valid after',
|
||||
productFromRocket.ValidAfter(),
|
||||
'seconds till valid',
|
||||
productFromRocket.TimeTillValid(),
|
||||
'validNow',
|
||||
productFromRocket.ValidNow()
|
||||
);
|
||||
}
|
||||
}}>print product</a
|
||||
|
||||
@@ -384,7 +384,7 @@ export class Rocket {
|
||||
}
|
||||
return event;
|
||||
}
|
||||
UpsertProduct(id: string, price: number, maxSales?: number): NDKEvent {
|
||||
UpsertProduct(id: string, price: number, maxSales?: number, validAfter?: number): NDKEvent {
|
||||
this.PrepareForUpdate(id);
|
||||
let event = new NDKEvent(this.Event.ndk, this.Event.rawEvent());
|
||||
event.created_at = Math.floor(new Date().getTime() / 1000);
|
||||
@@ -394,9 +394,14 @@ export class Rocket {
|
||||
if (existingProduct) {
|
||||
purchases = existingProduct.PurchasesJSON();
|
||||
}
|
||||
let _validAfter = event.created_at;
|
||||
if (validAfter) {
|
||||
_validAfter = validAfter;
|
||||
}
|
||||
console.log(401, _validAfter);
|
||||
event.tags.push([
|
||||
'product',
|
||||
`${id}:${price}:${event.created_at}:${maxSales}`,
|
||||
`${id}:${price}:${_validAfter}:${maxSales}`,
|
||||
'wss://relay.nostrocket.org',
|
||||
purchases
|
||||
]);
|
||||
@@ -571,6 +576,13 @@ export class RocketProduct {
|
||||
ValidAfter(): number {
|
||||
return parseInt(this.tag[1].split(':')[2], 10);
|
||||
}
|
||||
TimeTillValid(): number {
|
||||
return this.ValidAfter() - Math.floor(new Date().getTime() / 1000);
|
||||
}
|
||||
ValidNow(): boolean {
|
||||
let valid = this.TimeTillValid() < 1;
|
||||
return valid;
|
||||
}
|
||||
MaxPurchases(): number {
|
||||
return parseInt(this.tag[1].split(':')[3], 10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user