Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TAS-2273] 🔥 Remove book payment price api calls #1842

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions src/components/EventModal/Collect/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,29 +228,6 @@
@input="onInputCollectMessage"
/>
</div>
<template v-if="nftIsNFTBook">
<Label
preset="p6"
align="left"
class="text-medium-gray mt-[12px] mb-[6px]"
:text="$t('nft_collect_modal_email')"
/>
<div
class="flex w-full py-[10px] px-[16px] gap-[12px] bg-shade-gray rounded-[12px]"
>
<IconEmail class="w-[20px] text-dark-gray" />
<input
v-model="email"
type="input"
class="w-full bg-transparent border-0 text-dark-gray focus-visible:outline-none"
:placeholder="
$t('nft_collect_modal_email_placeholder', {
name: creatorDisplayName,
})
"
/>
</div>
</template>
</section>

<section v-if="paymentMethod === undefined">
Expand Down Expand Up @@ -530,8 +507,7 @@ export default {
const notSupportedPlatforms = [];
return (
this.nftPriceInLIKE > 0 &&
!notSupportedPlatforms.includes(this.walletMethodType) &&
!(this.nftIsNFTBook && !this.isValidEmail)
!notSupportedPlatforms.includes(this.walletMethodType)
);
},
mintedFreeNFT() {
Expand Down
10 changes: 2 additions & 8 deletions src/components/ShoppingCart/ListRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,9 @@ export default {
try {
this.isFetching = true;
if (this.collectionId) {
await Promise.all([
this.lazyFetchNFTCollectionInfo(),
this.lazyFetchNFTCollectionPaymentPriceInfo(),
]);
await this.lazyFetchNFTCollectionInfo();
} else {
await Promise.all([
this.lazyFetchNFTClassAggregatedData(),
this.lazyFetchNFTBookPaymentPriceInfo(),
]);
await this.lazyFetchNFTClassAggregatedData();
}
} finally {
this.isFetching = false;
Expand Down
17 changes: 2 additions & 15 deletions src/mixins/nft-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default {
'getCanViewNFTBookBeforeClaimByClassId',
'getNFTCollectionInfoByCollectionId',
'getIsHideNFTBookDownload',
'getNFTClassPaymentPriceById',
'getNFTCollectionDefaultPaymentCurrency',
]),
classIds() {
Expand Down Expand Up @@ -98,15 +97,11 @@ export default {
},
collectionPrice() {
const priceInDecimal = this.collection?.priceInDecimal || 0;
const price =
this.getNFTClassPaymentPriceById(this.collectionId)?.fiatPrice ||
// eslint-disable-next-line prettier/prettier
(priceInDecimal / 100);
const price = priceInDecimal / 100;
return price;
},
collectionDefaultPrice() {
return this.getNFTClassPaymentPriceById(this.collectionId)
?.fiatPricePrediscount;
return this.collectionPrice;
},
collectionAvailablePriceLabel() {
return formatNumberWithUSD(this.collectionPrice);
Expand All @@ -127,7 +122,6 @@ export default {
...mapActions([
'lazyGetUserInfoByAddress',
'lazyFetchNFTCollectionInfoByCollectionId',
'lazyFetchNFTCollectionPaymentPriceInfoByCollectionId',
]),
async lazyFetchNFTCollectionInfo() {
await catchAxiosError(
Expand All @@ -136,12 +130,5 @@ export default {
})
);
},
async lazyFetchNFTCollectionPaymentPriceInfo() {
await catchAxiosError(
this.lazyFetchNFTCollectionPaymentPriceInfoByCollectionId({
collectionId: this.collectionId,
})
);
},
},
};
10 changes: 2 additions & 8 deletions src/mixins/nft-or-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,9 @@ export default {
methods: {
async lazyFetchProductInfo() {
if (this.isCollection) {
await Promise.all([
this.lazyFetchNFTCollectionInfo(),
this.lazyFetchNFTCollectionPaymentPriceInfo(),
]);
await this.lazyFetchNFTCollectionInfo();
} else {
Promise.all([
this.lazyFetchNFTClassAggregatedData(),
this.lazyFetchNFTBookPaymentPriceInfoForAllEditions(),
]);
await this.lazyFetchNFTClassAggregatedData();
}
},
},
Expand Down
68 changes: 14 additions & 54 deletions src/mixins/nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default {
'getCollectedNFTClassesByAddress',
'getCreatedNFTClassesByAddress',
'getNFTBookStorePricesByClassId',
'getNFTBookStorePriceByClassIdAndIndex',
'getNFTCollectionInfoByClassId',
'getNFTBookStoreBookDefaultPaymentCurrency',
'getCanViewNFTBookBeforeClaimByClassId',
Expand Down Expand Up @@ -290,11 +291,10 @@ export default {
return this.NFTPrice !== undefined && this.NFTPrice !== -1;
},
paymentInfo() {
const result =
this.getNFTClassPaymentPriceById(
this.classId,
this.editionPriceIndex
) || {};
if (this.nftIsNFTBook) {
return null;
}
const result = this.getNFTClassPaymentPriceById(this.classId);
return result;
},
nftPriceInLIKE() {
Expand All @@ -316,16 +316,16 @@ export default {
},
nftPaymentPriceInUSD() {
if (this.nftIsNFTBook) {
if (this.priceIndex !== undefined) {
const edition = this.getNFTBookStorePriceByClassIdAndIndex(
this.classId,
this.priceIndex
);
if (edition) return edition.price;
}
const result = this.getNFTBookStorePricesByClassId(this.classId);
if (!result || !result.length) return undefined;

const [price, ...prices] = result;
if (this.priceIndex !== undefined) {
const foundPrice = result.find(p => p.index === this.priceIndex);
if (foundPrice) {
return foundPrice.price;
}
}
return prices.reduce((acc, p) => Math.min(acc, p.price), price.price);
}

Expand Down Expand Up @@ -783,8 +783,6 @@ export default {
'fetchNFTDisplayStateListByAddress',
'fetchNFTBookInfoByClassId',
'lazyFetchNFTBookInfoByClassId',
'fetchNFTBookPaymentPriceInfoByClassIdAndPriceIndex',
'lazyFetchNFTBookPaymentPriceInfoByClassIdAndPriceIndex',
'fetchNFTCollectionInfoByClassId',
]),
async fetchISCNMetadata() {
Expand All @@ -805,42 +803,7 @@ export default {
},
async fetchNFTPrices() {
await catchAxiosError(
this.nftIsNFTBook
? this.fetchNFTBookPaymentPriceInfoByClassIdAndPriceIndex({
classId: this.classId,
priceIndex: this.editionPriceIndex,
})
: this.fetchNFTPaymentPriceInfoByClassId(this.classId)
);
},
async fetchNFTBookPaymentPriceInfo() {
await catchAxiosError(
this.fetchNFTBookPaymentPriceInfoByClassIdAndPriceIndex({
classId: this.classId,
priceIndex: this.editionPriceIndex,
})
);
},
async lazyFetchNFTBookPaymentPriceInfo() {
await catchAxiosError(
this.lazyFetchNFTBookPaymentPriceInfoByClassIdAndPriceIndex({
classId: this.classId,
priceIndex: this.editionPriceIndex,
})
);
},
async lazyFetchNFTBookPaymentPriceInfoForAllEditions() {
const prices = this.getNFTBookStorePricesByClassId(this.classId);
await Promise.all(
prices.map((p, i) => {
const index = p.index ?? i;
return catchAxiosError(
this.lazyFetchNFTBookPaymentPriceInfoByClassIdAndPriceIndex({
classId: this.classId,
priceIndex: index,
})
);
})
this.fetchNFTPaymentPriceInfoByClassId(this.classId)
);
},
async fetchRelatedNFTCollection({ type } = {}) {
Expand Down Expand Up @@ -1476,10 +1439,7 @@ export default {
this.isRecommendationLoading = false;
},
getEditionByIndex(index) {
const editions = this.getNFTBookStorePricesByClassId(this.classId) || {};
const edition =
editions.find(e => e.index === Number(index)) || editions[index];
return edition;
return this.getNFTBookStorePriceByClassIdAndIndex(this.classId, index);
},
},
};
13 changes: 0 additions & 13 deletions src/pages/nft/class/_classId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ export default {
this.fetchUserCollectedCount();
if (this.nftClassCollectionType === nftClassCollectionType.NFTBook) {
this.lazyFetchNFTBookInfoByClassId(this.classId).catch();
this.lazyFetchNFTBookPaymentPriceInfoForAllEditions();
this.fetchRelatedNFTCollection({ type: 'book' });
}
const blockingPromises = [this.fetchISCNMetadata()];
Expand Down Expand Up @@ -1202,18 +1201,6 @@ export default {
},
})
);
// gift does not support LIKE payment for now
} else if (
!giftInfo &&
edition.price > 0 &&
this.nftPriceInLIKE > 0
) {
await this.initIfNecessary();
if (this.hasConnectedWallet) {
this.fetchUserCollectedCount();
this.walletFetchLIKEBalance();
}
this.uiToggleCollectModal({ classId: this.classId });
} else {
const customPriceInDecimal = this.customPrice
? this.formatCustomPrice(this.customPrice, edition.price)
Expand Down
1 change: 0 additions & 1 deletion src/pages/nft/collection/_collectionId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ export default {
} finally {
this.isLoading = false;
}
this.lazyFetchNFTCollectionPaymentPriceInfo();
const { hash } = this.$route;
if (hash) {
this.$nextTick(() => {
Expand Down
22 changes: 15 additions & 7 deletions src/pages/shopping-cart/book.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@
computed: {
...mapGetters([
'getNFTClassMetadataById',
'getNFTClassPaymentPriceById',
'getNFTCollectionInfoByCollectionId',
'getNFTCollectionPriceByCollectionId',
'getNFTBookStorePriceByClassIdAndIndex',
'shoppingCartBookProductList',
'shoppingCartBookItems',
]),
Expand Down Expand Up @@ -193,12 +194,19 @@
},
totalNFTPriceInUSD() {
return this.shoppingCartBookItems.reduce((totalPrice, item) => {
const priceInfo = this.getNFTClassPaymentPriceById(
item.productId,
item.classId ? item.priceIndex : undefined
);
const unitPrice =
item.customPriceInDecimal / 100 || priceInfo?.fiatPrice;
let itemPrice = 0;
if (item.collectionId) {
itemPrice = this.getNFTCollectionPriceByCollectionId(
item.collectionId
);
} else {
const edition = this.getNFTBookStorePriceByClassIdAndIndex(
item.productId,
item.classId ? item.priceIndex : undefined
);
itemPrice = edition?.price;
}
const unitPrice = item.customPriceInDecimal / 100 || itemPrice || 0;
return totalPrice + (unitPrice * item.quantity || 0);
}, 0);
},
Expand Down Expand Up @@ -352,7 +360,7 @@
'BookCart',
'shopping_cart_click_empty_notice_button',
this.getAddress,
1

Check warning on line 363 in src/pages/shopping-cart/book.vue

View workflow job for this annotation

GitHub Actions / CI

Unexpected console statement
);
},
},
Expand Down
23 changes: 14 additions & 9 deletions src/store/modules/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,20 @@ const getters = {
shoppingCartBookProductList: (state, getter) => {
const list = Object.values(state.shoppingCartBookProductByIdMap).filter(
item => {
const priceInfo = getter.getNFTClassPaymentPriceById(
item.productId,
item.priceIndex
);
return (
!priceInfo ||
priceInfo?.fiatPrice > 0 ||
item.customPriceInDecimal > 0
);
let itemPrice = 0;
if (item.collectionId) {
const price = getter.getNFTCollectionPriceByCollectionId(
item.collectionId
);
itemPrice = price;
} else {
const edition = getter.getNFTBookStorePriceByClassIdAndIndex(
item.classId,
item.priceIndex || 0
);
itemPrice = edition?.price;
}
return itemPrice || item.customPriceInDecimal > 0;
}
);
list.sort((a, b) => a.timestamp - b.timestamp);
Expand Down
Loading
Loading