diff --git a/contract/src/offer-up.contract.js b/contract/src/offer-up.contract.js index 3e20ebb..0410dc8 100644 --- a/contract/src/offer-up.contract.js +++ b/contract/src/offer-up.contract.js @@ -102,7 +102,7 @@ export const start = async zcf => { const amountObject = AmountMath.make( brand, makeCopyBag([ - [{ serviceStarted: currentTimeRecord.absValue, serviceType }, 1n], + [{ serviceType }, 1n], ]), ); const want = { Items: amountObject }; @@ -120,7 +120,7 @@ export const start = async zcf => { ); const subscriptionKey = `${userAddress}_${serviceType}`; - subscriptions.set(subscriptionKey, want.Items); + subscriptions.set(subscriptionKey, { Items: want.Items, serviceStarted: currentTimeRecord.absValue }); buyerSeat.exit(true); newSubscription.exit(); @@ -147,9 +147,9 @@ export const start = async zcf => { ); const isSubscriptionValid = async userSubscription => { - if (!userSubscription || !userSubscription.value.payload) return false; + if (!userSubscription || !userSubscription.Items) return false; - const serviceStarted = userSubscription.value.payload[0][0].serviceStarted; + const serviceStarted = userSubscription.serviceStarted; const currentTime = await E(timerService).getCurrentTimestamp().absValue; @@ -160,8 +160,11 @@ export const start = async zcf => { const expirationTime = serviceStarted + 10n; // Check if the current time is greater than the expiration time - debugger; + if (expirationTime === 10n) return true; + if (!serviceStarted || currentTime > expirationTime) return false; + + return true; }; const getSubscriptionResources = async (userAddress, serviceType) => { @@ -171,7 +174,7 @@ export const start = async zcf => { const isValidSub = await isSubscriptionValid(userSubscription); if (isValidSub) { // User has a valid subscription, return the resources - const serviceType = userSubscription.value.payload[0][0].serviceType; + const serviceType = userSubscription.Items.value.payload[0][0].serviceType; return JSON.stringify(subscriptionResources[serviceType]); } else { // User doesn't have a valid subscription diff --git a/ui/src/App.tsx b/ui/src/App.tsx index c80a372..f2aff63 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -111,7 +111,7 @@ const makeOffer = async (giveValue: bigint, wantChoice: string, offerType: strin throw Error('brands not available'); const choiceBag = makeCopyBag([ - [{ serviceStarted: '123', serviceType: wantChoice }, 1n], + [{ serviceType: wantChoice }, 1n], ]); // want: { Items: AmountMath.make(brands.Item, choiceBag) } diff --git a/ui/src/components/Trade.tsx b/ui/src/components/Trade.tsx index 76abbf3..20bb56c 100644 --- a/ui/src/components/Trade.tsx +++ b/ui/src/components/Trade.tsx @@ -91,7 +91,7 @@ const watchUpdates = async (wallet: Wallet, offerType: string, serviceType: stri const iterator = subscribeLatest(wallet?.walletUpdatesNotifier); let flag = false; for await (const update of iterator) { - if (offerType === "VIEW_SUBSCRIPTION" && !flag && update.status.offerArgs.serviceType === serviceType && update.status.offerArgs.offerType === 'VIEW_SUBSCRIPTION') { + if (offerType === "VIEW_SUBSCRIPTION" && !flag && update.status?.offerArgs.serviceType === serviceType && update.status.offerArgs.offerType === 'VIEW_SUBSCRIPTION' && update.status.result) { flag = true; alert(update.status.result); }