Skip to content

Commit

Permalink
flakiness of wallet subscription fixed;
Browse files Browse the repository at this point in the history
  • Loading branch information
Muneeb147 committed Sep 6, 2024
1 parent d2c145f commit dd0762a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions contract/src/offer-up.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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();
Expand All @@ -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;

Expand All @@ -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) => {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/Trade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit dd0762a

Please sign in to comment.