Skip to content

Commit db653bd

Browse files
fix: atb modal showed based on user balance and basket total (#6213)
* fix: atb modal showed based on user balance and basket total * fix: pr tweak
1 parent 887ec0e commit db653bd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/components/WwwFrame/Header/KvAtbModalContainer.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ const myKivaFlagEnabled = ref(false);
7575
const tierTable = ref({});
7676
const milestonesProgress = ref({});
7777
const hasEverLoggedIn = ref(false);
78+
const basketTotal = ref(0);
7879
7980
const basketCount = computed(() => {
8081
return addedLoan.value?.basketSize ?? 0;
8182
});
8283
8384
const isGuest = computed(() => !userData.value?.my);
84-
const hasUserBalance = computed(() => Boolean(Math.floor(userData.value?.my?.userAccount?.balance)));
8585
8686
const resetModal = () => {
8787
showModalContent.value = false;
@@ -116,6 +116,9 @@ const fetchBasketData = async () => {
116116
},
117117
}).then(({ data }) => {
118118
basketData.value = data?.shop?.basket?.items?.values ?? [];
119+
basketTotal.value = basketData.value.reduce((total, item) => {
120+
return total + (parseFloat(item.price) || 0);
121+
}, 0);
119122
}).catch(e => {
120123
logFormatter(e, 'Modal ATB Basket Data');
121124
});
@@ -126,6 +129,11 @@ const loansIdsInBasket = computed(() => {
126129
return basketData.value.filter(item => item.__typename === 'LoanReservation').map(item => item.id);
127130
});
128131
132+
const showBasedOnUserBalance = computed(() => {
133+
const userBalance = Math.floor(userData.value?.my?.userAccount?.balance ?? 0);
134+
return userBalance - basketTotal.value < 25;
135+
});
136+
129137
const isFirstLoan = computed(() => {
130138
return myKivaExperimentEnabled.value
131139
&& ((isGuest.value && !hasEverLoggedIn.value) || (!isGuest.value && !userData.value?.my?.loans?.totalCount))
@@ -174,7 +182,7 @@ const fetchPostCheckoutAchievements = async loanIds => {
174182
oneAwayText.value = `${target - 1} of ${target}`;
175183
showModalContent.value = true;
176184
modalVisible.value = true;
177-
} else if ((basketSize < BASKET_LIMIT_SIZE_FOR_EXP || achievementReached) && !hasUserBalance.value) {
185+
} else if ((basketSize < BASKET_LIMIT_SIZE_FOR_EXP || achievementReached) && showBasedOnUserBalance.value) {
178186
showModalContent.value = !!contributingAchievements.value.length;
179187
modalVisible.value = true;
180188
}
@@ -202,7 +210,7 @@ watch(addedLoan, async () => {
202210
if (myKivaExperimentEnabled.value && !isGuest.value) {
203211
await fetchBasketData();
204212
fetchPostCheckoutAchievements(loansIdsInBasket.value);
205-
} else if (addedLoan.value?.basketSize < BASKET_LIMIT_SIZE_FOR_EXP && !hasUserBalance.value) {
213+
} else if (addedLoan.value?.basketSize < BASKET_LIMIT_SIZE_FOR_EXP) {
206214
modalVisible.value = true;
207215
}
208216
});

src/graphql/query/basketItems.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ query basketItems($basketId: String) {
88
items {
99
values {
1010
id
11+
... on LoanReservation {
12+
price
13+
}
1114
}
1215
}
1316
}

0 commit comments

Comments
 (0)