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

feat: Create offer modal & signing design #10909

Merged
merged 18 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
3 changes: 2 additions & 1 deletion components/common/shoppingCart/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ export const nftToListingCartItem = (
}
}

export const nftToOfferItem = (nft: NFT & TokenId): MakingOfferItem => {
export const nftToOfferItem = (nft: NFT & TokenId, highestOffer?: string): MakingOfferItem => {
const { urlPrefix } = usePrefix()

return {
id: nft.id,
name: nameWithIndex(nft.name, nft.sn),
price: nft.price ?? '0',
highestOffer,
urlPrefix: urlPrefix.value,
collection: nft.collection,
metadata: nft.metadata,
Expand Down
6 changes: 5 additions & 1 deletion components/gallery/GalleryItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@
v-if="nft && isAssetHub"
:nft="nft"
/>
<GalleryItemAction :nft="nft" />
<GalleryItemAction
:nft="nft"
:highest-offer="nftHighestOffer"
preschian marked this conversation as resolved.
Show resolved Hide resolved
/>
<UnlockableTag
v-if="isUnlockable && !isMobile"
:link="unlockLink"
Expand Down Expand Up @@ -258,6 +261,7 @@ const {
nftAnimationMimeType,
nftMimeType,
nftResources,
nftHighestOffer,
} = galleryItem
const collection = computed(() => nft.value?.collection)

Expand Down
3 changes: 3 additions & 0 deletions components/gallery/GalleryItemAction/GalleryItemAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<GalleryItemOffer
v-if="offerVisible(urlPrefix) && !isOwner && nft"
:nft="nft"
:highest-offer="highestOffer"
class="mt-2"
/>

Expand All @@ -34,11 +35,13 @@ import GalleryItemOffer from './GalleryItemActionType/GalleryItemOffer.vue'
import GalleryItemPriceRelist from './GalleryItemActionType/GalleryItemRelist.vue'
import GalleryItemPriceTransfer from './GalleryItemActionType/GalleryItemTransfer.vue'
import { listVisible, offerVisible } from '@/utils/config/permission.config'
import type { NFTOffer } from '@/composables/useNft'

import type { NFT } from '@/components/rmrk/service/scheme'

const props = defineProps<{
nft: NFT | undefined
highestOffer: NFTOffer
}>()

const { urlPrefix } = usePrefix()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<template>
<div class="flex justify-end gallery-item-offer">
<NeoButton
:label="$t('transaction.offer')"
variant="k-blue"
size="large"
class="w-[calc(10rem+55px)]"
@click="openOfferModal"
/>
<MakeOffer />
</div>
<GalleryItemPriceSection
:title="$t('offer.highestOffer')"
:price="highestOfferPrice"
class="mt-4"
>
<div class="flex justify-end gallery-item-offer">
<NeoButton
:label="$t('transaction.offer')"
variant="k-blue"
size="large"
class="w-[calc(10rem+55px)]"
@click="onMakeOfferClick"
/>
<MakeOffer />
</div>
</GalleryItemPriceSection>
</template>

<script setup lang="ts">
Expand All @@ -18,22 +24,39 @@ import { nftToOfferItem } from '@/components/common/shoppingCart/utils'
import { usePreferencesStore } from '@/stores/preferences'
import { useMakingOfferStore } from '@/stores/makeOffer'
import MakeOffer from '@/components/offer/MakeOffer.vue'
import GalleryItemPriceSection from '@/components/gallery/GalleryItemAction/GalleryItemActionSection.vue'
import type { NFTOffer } from '@/components/useNft'
Jarsen136 marked this conversation as resolved.
Show resolved Hide resolved

const props = defineProps<{
nft: NFT
highestOffer?: NFTOffer
}>()

const preferencesStore = usePreferencesStore()
const makeOfferStore = useMakingOfferStore()
const { doAfterLogin } = useDoAfterlogin()
const { isCurrentOwner } = useAuth()
const isOwner = computed(() => isCurrentOwner(props.nft?.currentOwner))

const highestOfferPrice = computed(() => props.highestOffer?.price || '')

const openOfferModal = () => {
makeOfferStore.clear()
const item = nftToOfferItem(props.nft)
const item = nftToOfferItem(props.nft, highestOfferPrice.value)
makeOfferStore.setItem(item)

preferencesStore.setMakeOfferModalOpen(true)
}

const onMakeOfferClick = () => {
doAfterLogin({
onLoginSuccess: () => {
if (!isOwner.value) {
openOfferModal()
}
hassnian marked this conversation as resolved.
Show resolved Hide resolved
},
})
}

useModalIsOpenTracker({
isOpen: computed(() => preferencesStore.makeOfferModalOpen),
onChange: () => makeOfferStore.clear(),
Expand Down
28 changes: 27 additions & 1 deletion components/gallery/useGalleryItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getNftMetadata } from '@/composables/useNft'
import useSubscriptionGraphql from '@/composables/useSubscriptionGraphql'
import { getCloudflareMp4 } from '@/services/imageWorker'
import type { NFT } from '@/components/rmrk/service/scheme'
import type { NFTWithMetadata, NftResources } from '@/composables/useNft'
import type { NFTWithMetadata, NftResources, NFTOffer } from '@/composables/useNft'
import { getMimeType } from '@/utils/gallery/media'

interface NFTData {
Expand All @@ -20,6 +20,7 @@ export interface GalleryItem {
nftAnimationMimeType: Ref<string>
nftImage: Ref<string>
nftResources: Ref<NftResources[] | undefined>
nftHighestOffer: Ref<NFTOffer | undefined>
}

export const useGalleryItem = (nftId?: string): GalleryItem => {
Expand All @@ -32,6 +33,8 @@ export const useGalleryItem = (nftId?: string): GalleryItem => {
const nftMimeType = ref('')
const nftMetadata = ref<NFTWithMetadata>()
const nftResources = ref<NftResources[]>()
const nftHighestOffer = ref<NFTOffer>()
const isOfferIndexerDisabled = computed(() => urlPrefix.value !== 'ahp')

const { params } = useRoute()
const id = nftId || params.id
Expand All @@ -53,6 +56,14 @@ export const useGalleryItem = (nftId?: string): GalleryItem => {
},
})

const { data: nftOfferData, refetch: refetchHighestOffer } = useGraphql({
queryName: 'highestOfferByNftId',
disabled: isOfferIndexerDisabled,
variables: {
id,
},
})

useSubscriptionGraphql({
query: ` nft: nftEntityById(id: "${id}") {
id
Expand All @@ -66,6 +77,14 @@ export const useGalleryItem = (nftId?: string): GalleryItem => {
onChange: refetch,
})

useSubscriptionGraphql({
query: `offers(where: {status_eq: ACTIVE, desired: {id_eq: "${id}"}}, orderBy: price_DESC, limit: 1) {
id
}`,
disabled: isOfferIndexerDisabled,
onChange: refetchHighestOffer,
})

watch(data as unknown as NFTData, async (newData) => {
const nftEntity = newData?.nftEntity
if (!nftEntity) {
Expand Down Expand Up @@ -152,6 +171,12 @@ export const useGalleryItem = (nftId?: string): GalleryItem => {
})
})

watch(nftOfferData as unknown as { offers: NFTOffer[] }, (newData) => {
if (newData && newData.offers && newData.offers[0]) {
nftHighestOffer.value = newData.offers[0]
}
})

return {
nft,
nftImage,
Expand All @@ -160,5 +185,6 @@ export const useGalleryItem = (nftId?: string): GalleryItem => {
nftMimeType,
nftMetadata,
nftResources,
nftHighestOffer,
}
}
Loading
Loading