From 0c66f2c287a13722d6aa97452031af1116d698dd Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Thu, 31 Aug 2023 23:51:07 +0800 Subject: [PATCH 01/51] feat: listing cart --- components/items/ItemsGrid/ItemsGridImage.vue | 21 ++++++ stores/listingCart.ts | 71 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 stores/listingCart.ts diff --git a/components/items/ItemsGrid/ItemsGridImage.vue b/components/items/ItemsGrid/ItemsGridImage.vue index daaa845a66..8c5c39aad9 100644 --- a/components/items/ItemsGrid/ItemsGridImage.vue +++ b/components/items/ItemsGrid/ItemsGridImage.vue @@ -30,6 +30,17 @@ +
+ + +
@@ -39,6 +50,7 @@ import { NeoButton, NeoNftCard } from '@kodadot1/brick' import type { NftCardVariant } from '@kodadot1/brick' import type { NFTWithMetadata } from '@/composables/useNft' import { useShoppingCartStore } from '@/stores/shoppingCart' +import { useListingCartStore } from '@/stores/listingCart' import { usePreferencesStore } from '@/stores/preferences' import { nftToShoppingCardItem } from '@/components/common/shoppingCart/utils' import { isOwner as checkOwner } from '@/utils/account' @@ -49,6 +61,7 @@ const { accountId, isLogIn } = useAuth() const { doAfterLogin } = useDoAfterlogin(getCurrentInstance()) const { unlockableIcon } = useUnlockableIcon() const shoppingCartStore = useShoppingCartStore() +const listingCartStore = useListingCartStore() const preferencesStore = usePreferencesStore() const { $i18n } = useNuxtApp() @@ -105,6 +118,14 @@ const onClickShoppingCart = () => { shoppingCartStore.setItem(nftToShoppingCardItem(props.nft)) } } + +const onClickListingCart = () => { + if (listingCartStore.isItemInCart(props.nft.id)) { + listingCartStore.removeItem(props.nft.id) + } else { + listingCartStore.setItem(nftToShoppingCardItem(props.nft)) + } +} diff --git a/components/items/ItemsGrid/ItemsGrid.vue b/components/items/ItemsGrid/ItemsGrid.vue index 02709f6305..6abd13ed63 100644 --- a/components/items/ItemsGrid/ItemsGrid.vue +++ b/components/items/ItemsGrid/ItemsGrid.vue @@ -36,9 +36,9 @@ (slotProps.isMobileVariant || slotProps.grid === 'small') && 'minimal' " /> - + diff --git a/components/items/ItemsGrid/ItemsGridImage.vue b/components/items/ItemsGrid/ItemsGridImage.vue index c7fdfe7070..db9a51109a 100644 --- a/components/items/ItemsGrid/ItemsGridImage.vue +++ b/components/items/ItemsGrid/ItemsGridImage.vue @@ -129,7 +129,6 @@ const onClickShoppingCart = () => { } const onClickListingCart = () => { - console.log(listLabel) if (listingCartStore.isItemInCart(props.nft.id)) { listingCartStore.removeItem(props.nft.id) } else { diff --git a/stores/listingCart.ts b/stores/listingCart.ts index d69d8197a5..60cfc50c04 100644 --- a/stores/listingCart.ts +++ b/stores/listingCart.ts @@ -13,7 +13,7 @@ export const useListingCartStore = defineStore('listingCart', { items: localStorage.value, }), getters: { - getItems: (state) => state.items, + count: (state) => state.items.length, }, actions: { getItemsByPrefix(prefix: string) { From 7f5bb9409479eb39dd3fcc6fc2826a5c58911940 Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Fri, 1 Sep 2023 13:34:04 +0800 Subject: [PATCH 07/51] feat: listingCartModal --- .../common/listingCart/ListingCartMini.vue | 10 +- .../common/listingCart/ListingCartModal.vue | 149 ++++++++++++++++++ components/items/ItemsGrid/ItemsGrid.vue | 1 + stores/preferences.ts | 2 + 4 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 components/common/listingCart/ListingCartModal.vue diff --git a/components/common/listingCart/ListingCartMini.vue b/components/common/listingCart/ListingCartMini.vue index 2df13854d5..6275bec736 100644 --- a/components/common/listingCart/ListingCartMini.vue +++ b/components/common/listingCart/ListingCartMini.vue @@ -16,7 +16,7 @@ Clear All
- + Select All
@@ -24,7 +24,7 @@ + @click.native="list"> List Items @@ -34,10 +34,12 @@ diff --git a/components/items/ItemsGrid/ItemsGrid.vue b/components/items/ItemsGrid/ItemsGrid.vue index 6abd13ed63..530e40fac3 100644 --- a/components/items/ItemsGrid/ItemsGrid.vue +++ b/components/items/ItemsGrid/ItemsGrid.vue @@ -39,6 +39,7 @@ + diff --git a/stores/preferences.ts b/stores/preferences.ts index 8c7838700c..bf4817758c 100644 --- a/stores/preferences.ts +++ b/stores/preferences.ts @@ -10,6 +10,7 @@ interface State { mobileFilterCollapseOpen: boolean notificationBoxCollapseOpen: boolean shoppingCartCollapseOpen: boolean + listingCartModalOpen: boolean completePurchaseModal: completePurchaseModalState triggerBuySuccess: boolean layoutClass: string @@ -40,6 +41,7 @@ export const usePreferencesStore = defineStore('preferences', { sidebarFilterCollapseOpen: true, mobileFilterCollapseOpen: false, notificationBoxCollapseOpen: false, + listingCartModalOpen: false, shoppingCartCollapseOpen: false, completePurchaseModal: { isOpen: false, From fe103bc723b1bf3fc2631cde417536e7d58d49c3 Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Fri, 1 Sep 2023 21:48:52 +0800 Subject: [PATCH 08/51] feat(listingCartModal): finalized ui --- .../common/listingCart/ListingCartItem.vue | 83 +++++++++++++++++++ .../common/listingCart/ListingCartModal.vue | 35 ++++++-- .../listingCart/ListingCartPriceInput.vue | 38 +++++++++ components/items/ItemsGrid/ItemsGrid.vue | 2 - pages/_prefix/u/_id.vue | 6 +- 5 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 components/common/listingCart/ListingCartItem.vue create mode 100644 components/common/listingCart/ListingCartPriceInput.vue diff --git a/components/common/listingCart/ListingCartItem.vue b/components/common/listingCart/ListingCartItem.vue new file mode 100644 index 0000000000..6f62a2042c --- /dev/null +++ b/components/common/listingCart/ListingCartItem.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/components/common/listingCart/ListingCartModal.vue b/components/common/listingCart/ListingCartModal.vue index 95fa4429be..31770cb548 100644 --- a/components/common/listingCart/ListingCartModal.vue +++ b/components/common/listingCart/ListingCartModal.vue @@ -31,13 +31,26 @@ class="identity-name-font-weight-regular" data-cy="item-creator" /> +
Set All To
+
Collection Floor Price
+
+
+ -5% +
+
+ Floor Price +
+
+5%
+
+
-Or-
+
Fixed Price
+
- + :nft="nft" />
@@ -60,12 +73,12 @@ + + diff --git a/components/items/ItemsGrid/ItemsGrid.vue b/components/items/ItemsGrid/ItemsGrid.vue index 530e40fac3..43c1c4b0f6 100644 --- a/components/items/ItemsGrid/ItemsGrid.vue +++ b/components/items/ItemsGrid/ItemsGrid.vue @@ -38,8 +38,6 @@ - -
diff --git a/pages/_prefix/u/_id.vue b/pages/_prefix/u/_id.vue index 564a25d16d..9155078068 100644 --- a/pages/_prefix/u/_id.vue +++ b/pages/_prefix/u/_id.vue @@ -1,5 +1,9 @@ - diff --git a/components/common/listingCart/ListingCartPriceInput.vue b/components/common/listingCart/ListingCartPriceInput.vue index 52d609a4c6..d6d6a2762f 100644 --- a/components/common/listingCart/ListingCartPriceInput.vue +++ b/components/common/listingCart/ListingCartPriceInput.vue @@ -31,6 +31,7 @@ const model = useVModel(props, 'value', emit, { eventName: 'input' }) border-right: none; outline: none; width: 5em; + text-indent: 10px; } .height-40 { diff --git a/stores/listingCart.ts b/stores/listingCart.ts index 9a1cb67b3a..a34bc4a634 100644 --- a/stores/listingCart.ts +++ b/stores/listingCart.ts @@ -23,6 +23,8 @@ export const useListingCartStore = defineStore('listingCart', { }), getters: { count: (state) => state.items.length, + incompleteListPrices: (state) => + state.items.filter((item) => !item.listPrice).length, }, actions: { getItemsByPrefix(prefix: string) { @@ -56,7 +58,7 @@ export const useListingCartStore = defineStore('listingCart', { localStorage.value = this.items } }, - setFixedPrice(price) { + setFixedPrice(price: number) { for (const item of this.items) { set(item, 'listPrice', price) } From b2e6d013cbf826de23928436e5da36b916dabcf6 Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Sat, 2 Sep 2023 02:52:16 +0800 Subject: [PATCH 15/51] feat: added loading indicator while saving on chain --- .../common/listingCart/ListingCartModal.vue | 171 +++++++++--------- components/common/shoppingCart/utils.ts | 3 +- stores/listingCart.ts | 2 +- 3 files changed, 90 insertions(+), 86 deletions(-) diff --git a/components/common/listingCart/ListingCartModal.vue b/components/common/listingCart/ListingCartModal.vue index f734d22228..3881824e01 100644 --- a/components/common/listingCart/ListingCartModal.vue +++ b/components/common/listingCart/ListingCartModal.vue @@ -1,91 +1,94 @@ diff --git a/queries/subsquid/general/nftListWithSearch.graphql b/queries/subsquid/general/nftListWithSearch.graphql index 7bf375a3b1..eb247a3619 100644 --- a/queries/subsquid/general/nftListWithSearch.graphql +++ b/queries/subsquid/general/nftListWithSearch.graphql @@ -27,7 +27,6 @@ query nftListWithSearch( collection { id name - floor } meta { ...baseMeta diff --git a/queries/subsquid/ksm/nftListWithSearch.graphql b/queries/subsquid/ksm/nftListWithSearch.graphql index 76f2e6da6f..dce09e27e6 100644 --- a/queries/subsquid/ksm/nftListWithSearch.graphql +++ b/queries/subsquid/ksm/nftListWithSearch.graphql @@ -27,7 +27,6 @@ query nftListWithSearch( collection { id name - floor } meta { ...baseMeta diff --git a/queries/subsquid/rmrk/nftListWithSearch.graphql b/queries/subsquid/rmrk/nftListWithSearch.graphql index 60cecdc814..deeb24c1b5 100644 --- a/queries/subsquid/rmrk/nftListWithSearch.graphql +++ b/queries/subsquid/rmrk/nftListWithSearch.graphql @@ -26,7 +26,6 @@ query nftListWithSearch( collection { id name - floor } meta { ...baseMeta From be7304610bade22be23ea07505a672bf52fbb369 Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Sat, 2 Sep 2023 12:06:37 +0800 Subject: [PATCH 19/51] feat: multichain segregation --- .../common/listingCart/ListingCartModal.vue | 8 +++--- stores/listingCart.ts | 26 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/components/common/listingCart/ListingCartModal.vue b/components/common/listingCart/ListingCartModal.vue index 6afcb585e2..cd233568a8 100644 --- a/components/common/listingCart/ListingCartModal.vue +++ b/components/common/listingCart/ListingCartModal.vue @@ -64,7 +64,7 @@
@@ -117,12 +117,12 @@ function setFixedPrice() { } const priceUSD = computed(() => { - const { nfts, royalties } = totalPriceUsd(listingCartStore.items) + const { nfts, royalties } = totalPriceUsd(listingCartStore.itemsInChain) return (nfts + royalties).toFixed(2) }) const totalNFTsPrice = computed(() => - sum(listingCartStore.items.map((nft) => Number(nft.price))) + sum(listingCartStore.itemsInChain.map((nft) => Number(nft.price))) ) const confirmListingLabel = computed(() => { @@ -137,7 +137,7 @@ const confirmListingLabel = computed(() => { }) async function confirm() { const updateItems = {} as { [urlPrefix: string]: TokenToList[] } - for (const item of listingCartStore.items) { + for (const item of listingCartStore.itemsInChain) { if (item.listPrice) { if (!updateItems[item.urlPrefix]) { updateItems[item.urlPrefix] = [] diff --git a/stores/listingCart.ts b/stores/listingCart.ts index 4e32864387..81784abc31 100644 --- a/stores/listingCart.ts +++ b/stores/listingCart.ts @@ -1,6 +1,8 @@ import { defineStore } from 'pinia' import { EntityWithId } from '~/components/rmrk/service/scheme' import { set } from 'vue' +import type { Prefix } from '@kodadot1/static' + export type ListCartItem = { id: string name: string @@ -15,6 +17,7 @@ type ID = string interface State { items: ListCartItem[] owned: ListCartItem[] + chain: ComputedRef } const localStorage = useLocalStorage('listingCart', []) @@ -22,16 +25,18 @@ export const useListingCartStore = defineStore('listingCart', { state: (): State => ({ items: localStorage.value, owned: [], + chain: usePrefix().urlPrefix, }), getters: { - count: (state) => state.items.length, + itemsInChain: (state): ListCartItem[] => + state.items.filter((item) => item.urlPrefix === state.chain), + count() { + return this.itemsInChain.length + }, incompleteListPrices: (state) => state.items.filter((item) => !item.listPrice).length, }, actions: { - getItemsByPrefix(prefix: string) { - this.items.filter((item) => item.urlPrefix === prefix) - }, getItem(id: ID) { return this.items.find((item) => item.id === id) }, @@ -66,12 +71,12 @@ export const useListingCartStore = defineStore('listingCart', { } }, setFixedPrice(price: number) { - for (const item of this.items) { + for (const item of this.itemsInChain) { set(item, 'listPrice', price) } }, setFloorPrice(adjust = 1) { - for (const item of this.items) { + for (const item of this.itemsInChain) { set( item, 'listPrice', @@ -90,12 +95,9 @@ export const useListingCartStore = defineStore('listingCart', { } }, clear() { - this.items = [] - localStorage.value = [] - }, - setItems(payload: ListCartItem[]) { - this.items = payload - localStorage.value = this.items + for (const item of this.itemsInChain) { + this.removeItem(item.id) + } }, }, }) From 32fbf99ddaaad97241d1ad8774b0984eec439443 Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Sat, 2 Sep 2023 12:11:55 +0800 Subject: [PATCH 20/51] refactor: transaction cleanup --- .../common/listingCart/ListingCartModal.vue | 23 ++++++++----------- stores/listingCart.ts | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/components/common/listingCart/ListingCartModal.vue b/components/common/listingCart/ListingCartModal.vue index cd233568a8..e605c485dc 100644 --- a/components/common/listingCart/ListingCartModal.vue +++ b/components/common/listingCart/ListingCartModal.vue @@ -136,28 +136,23 @@ const confirmListingLabel = computed(() => { } }) async function confirm() { - const updateItems = {} as { [urlPrefix: string]: TokenToList[] } + const token = {} as TokenToList[] for (const item of listingCartStore.itemsInChain) { if (item.listPrice) { - if (!updateItems[item.urlPrefix]) { - updateItems[item.urlPrefix] = [] - } - updateItems[item.urlPrefix].push({ + token.push({ price: String(calculateBalance(item.listPrice)), nftId: item.id, }) } } try { - for (const [urlPrefix, token] of Object.entries(updateItems)) { - await transaction({ - interaction: Interaction.LIST, - urlPrefix, - token, - successMessage: $i18n.t('transaction.price.success') as string, - errorMessage: $i18n.t('transaction.price.error') as string, - }) - } + await transaction({ + interaction: Interaction.LIST, + urlPrefix: urlPrefix.value, + token, + successMessage: $i18n.t('transaction.price.success') as string, + errorMessage: $i18n.t('transaction.price.error') as string, + }) listingCartStore.clear() preferencesStore.listingCartModalOpen = false } catch (error) { diff --git a/stores/listingCart.ts b/stores/listingCart.ts index 81784abc31..181e790ca1 100644 --- a/stores/listingCart.ts +++ b/stores/listingCart.ts @@ -1,6 +1,6 @@ import { defineStore } from 'pinia' import { EntityWithId } from '~/components/rmrk/service/scheme' -import { set } from 'vue' +import { ComputedRef, set } from 'vue' import type { Prefix } from '@kodadot1/static' export type ListCartItem = { From f9a4f5f6bb2968403dea1cbe75e694709de55397 Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Sat, 2 Sep 2023 12:13:01 +0800 Subject: [PATCH 21/51] fix: token object to array initializer --- components/common/listingCart/ListingCartModal.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/common/listingCart/ListingCartModal.vue b/components/common/listingCart/ListingCartModal.vue index e605c485dc..b827cf997c 100644 --- a/components/common/listingCart/ListingCartModal.vue +++ b/components/common/listingCart/ListingCartModal.vue @@ -136,7 +136,7 @@ const confirmListingLabel = computed(() => { } }) async function confirm() { - const token = {} as TokenToList[] + const token = [] as TokenToList[] for (const item of listingCartStore.itemsInChain) { if (item.listPrice) { token.push({ From 4136875c6c49c34ca3b0756ddc1bf8a37f817401 Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Sat, 2 Sep 2023 14:02:21 +0800 Subject: [PATCH 22/51] refactor: import alias from ~ to @ --- .../common/listingCart/ListingCartItem.vue | 6 +++--- .../common/listingCart/ListingCartMini.vue | 2 +- .../common/listingCart/ListingCartModal.vue | 18 +++++++++--------- components/common/shoppingCart/utils.ts | 2 +- components/items/ItemsGrid/ItemsGrid.vue | 4 ++-- components/items/ItemsGrid/ItemsGridImage.vue | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/components/common/listingCart/ListingCartItem.vue b/components/common/listingCart/ListingCartItem.vue index b5d6ed4da5..3c3be4b877 100644 --- a/components/common/listingCart/ListingCartItem.vue +++ b/components/common/listingCart/ListingCartItem.vue @@ -48,9 +48,9 @@ diff --git a/components/common/listingCart/ListingCartModal.vue b/components/common/listingCart/ListingCartModal.vue index fa93976e44..90484acc95 100644 --- a/components/common/listingCart/ListingCartModal.vue +++ b/components/common/listingCart/ListingCartModal.vue @@ -83,7 +83,7 @@ :label="confirmListingLabel" variant="k-accent" no-shadow - class="is-flex is-flex-grow-1 btn-height" + class="is-flex is-flex-grow-1 py-5" @click.native="confirm" /> @@ -96,7 +96,7 @@ import ListingCartPriceInput from '@/components/common/listingCart/ListingCartPr import { totalPriceUsd } from '@/components/common/shoppingCart/utils' import IdentityItem from '@/components/identity/IdentityItem.vue' import CommonTokenMoney from '@/components/shared/CommonTokenMoney.vue' -import { NeoButton, NeoModal } from '@/libs/ui' +import { NeoButton, NeoModal } from '@kodadot1/brick' import { usePreferencesStore } from '@/stores/preferences' import { TokenToList } from '@/composables/transaction/types' import { useListingCartStore } from '@/stores/listingCart' @@ -137,14 +137,14 @@ const confirmListingLabel = computed(() => { }) async function confirm() { const token = [] as TokenToList[] - for (const item of listingCartStore.itemsInChain) { + listingCartStore.itemsInChain.forEach((item) => { if (item.listPrice) { token.push({ price: String(calculateBalance(item.listPrice)), nftId: item.id, }) } - } + }) try { await transaction({ interaction: Interaction.LIST, @@ -163,10 +163,6 @@ async function confirm() { From 9e5fbbaf776c0f90d4502a7cc41ae62456d89133 Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Sun, 3 Sep 2023 14:36:12 +0800 Subject: [PATCH 27/51] fix: potential earnings not calculating correctly --- .../common/listingCart/ListingCartModal.vue | 25 +++++++++++++------ components/common/shoppingCart/utils.ts | 20 +++++++++++++++ components/items/ItemsGrid/ItemsGridImage.vue | 13 ++++------ stores/listingCart.ts | 10 +++----- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/components/common/listingCart/ListingCartModal.vue b/components/common/listingCart/ListingCartModal.vue index 92cc46b719..363704983b 100644 --- a/components/common/listingCart/ListingCartModal.vue +++ b/components/common/listingCart/ListingCartModal.vue @@ -72,7 +72,7 @@ class="is-flex border-top is-justify-content-space-between py-4 px-6"> Potential Earnings
- + {{ totalNFTsPrice }} KSM ${{ priceUSD }}
@@ -93,7 +93,10 @@ diff --git a/stores/listingCart.ts b/stores/listingCart.ts index 6d5a7f0216..d79a467f88 100644 --- a/stores/listingCart.ts +++ b/stores/listingCart.ts @@ -1,6 +1,6 @@ import { defineStore } from 'pinia' import { EntityWithId } from '~/components/rmrk/service/scheme' -import { ComputedRef, set } from 'vue' +import { ComputedRef } from 'vue' import type { Prefix } from '@kodadot1/static' export type ListCartItem = { @@ -72,15 +72,13 @@ export const useListingCartStore = defineStore('listingCart', { }, setFixedPrice(price: number) { this.itemsInChain.forEach((item) => { - set(item, 'listPrice', price) + item.listPrice = price }) }, setFloorPrice(adjust = 1) { this.itemsInChain.forEach((item) => { - set( - item, - 'listPrice', - this.inTrillions(Number(item.collection.floor ?? 0) * adjust) + item.listPrice = this.inTrillions( + Number(item.collection.floor ?? 0) * adjust ) }) }, From 875185bb3e1100ead81cef6af6f9323c2618aac8 Mon Sep 17 00:00:00 2001 From: Stephen Jason Wang Date: Sun, 3 Sep 2023 14:53:54 +0800 Subject: [PATCH 28/51] style: listing cart price input active state --- .../listingCart/ListingCartPriceInput.vue | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/components/common/listingCart/ListingCartPriceInput.vue b/components/common/listingCart/ListingCartPriceInput.vue index de7e4bc364..8e2b1d0f65 100644 --- a/components/common/listingCart/ListingCartPriceInput.vue +++ b/components/common/listingCart/ListingCartPriceInput.vue @@ -1,13 +1,12 @@