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 on AssetHub #10842

Merged
merged 7 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions components/common/autoTeleport/AutoTeleportActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<NeoButton
:label="autoTeleportLabel"
variant="primary"
:variant="buttonVariant"
no-shadow
:shiny="shiny"
:disabled="isDisabled"
Expand Down Expand Up @@ -96,7 +96,7 @@
</template>

<script setup lang="ts">
import { NeoButton, NeoSwitch } from '@kodadot1/brick'
import { NeoButton, NeoSwitch, type NeoButtonVariant } from '@kodadot1/brick'
import AutoTeleportWelcomeModal from './AutoTeleportWelcomeModal.vue'
import type { ActionlessInteraction } from './utils'
import { getActionDetails } from './utils'
Expand Down Expand Up @@ -133,6 +133,7 @@ const props = withDefaults(
loading?: boolean
shiny?: boolean
earlySuccess?: boolean
buttonVariant?: NeoButtonVariant
}>(),
{
autoCloseModalDelayModal: undefined,
Expand All @@ -146,6 +147,7 @@ const props = withDefaults(
loading: false,
shiny: false,
earlySuccess: true,
buttonVariant: 'primary',
},
)

Expand Down
17 changes: 17 additions & 0 deletions components/common/shoppingCart/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { sum } from '@/utils/math'
import type { NFT, TokenId } from '@/components/rmrk/service/scheme'
import { chainPropListOf } from '@/utils/config/chain.config'
import { nameWithIndex } from '@/utils/nft'
import type { MakingOfferItem } from '@/components/offer/types'

export const prefixToToken = {
ksm: 'KSM',
Expand Down Expand Up @@ -90,6 +91,22 @@ export const nftToListingCartItem = (
}
}

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

return {
id: nft.id,
name: nameWithIndex(nft.name, nft.sn),
price: nft.price ?? '0',
urlPrefix: urlPrefix.value,
collection: nft.collection,
metadata: nft.metadata,
meta: nft.meta,
sn: nft.sn,
currentOwner: nft.currentOwner,
}
}

export const shoppingCartItemToListingCartItem = (
item: ShoppingCartItem,
floor = '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
v-if="!isOwner && nft"
:nft="nft"
/>
<!-- make offer -->
<GalleryItemOffer
v-if="offerVisible(urlPrefix) && !isOwner && nft"
:nft="nft"
class="mt-2"
/>

<!-- change price as an owner -->
<GalleryItemPriceRelist
Expand All @@ -24,9 +30,10 @@

<script lang="ts" setup>
import GalleryItemPriceBuy from './GalleryItemActionType/GalleryItemBuy.vue'
import GalleryItemOffer from './GalleryItemActionType/GalleryItemOffer.vue'
import GalleryItemPriceRelist from './GalleryItemActionType/GalleryItemRelist.vue'
import GalleryItemPriceTransfer from './GalleryItemActionType/GalleryItemTransfer.vue'
import { listVisible } from '@/utils/config/permission.config'
import { listVisible, offerVisible } from '@/utils/config/permission.config'

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<template>
<div class="flex justify-end gallery-item-offer mr-[55px]">
<NeoButton
:label="$t('transaction.offer')"
variant="k-blue"
size="large"
fixed-width
@click="openOfferModal"
/>
hassnian marked this conversation as resolved.
Show resolved Hide resolved
<MakeOffer />
</div>
</template>

<script setup lang="ts">
import { NeoButton } from '@kodadot1/brick'
import type { NFT } from '@/components/rmrk/service/scheme'
import { nftToOfferItem } from '@/components/common/shoppingCart/utils'
import { usePreferencesStore } from '@/stores/preferences'
import { useMakingOfferStore } from '@/stores/makeOffer'
import MakeOffer from '@/components/offer/MakeOffer.vue'

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

const preferencesStore = usePreferencesStore()
const makeOfferStore = useMakingOfferStore()

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

preferencesStore.setMakeOfferModalOpen(true)
}

watch(
() => preferencesStore.makeOfferModalOpen,
(isOpen) => {
if (!isOpen) {
onOfferModalClose()
}
},
)

const onOfferModalClose = () => {
setTimeout(() => {
makeOfferStore.clear()
}, 500) // wait for modal animation
}
hassnian marked this conversation as resolved.
Show resolved Hide resolved
</script>

<style lang="scss" scoped>
@import '@/assets/styles/abstracts/variables';

.gallery-item-offer {
button {
font-size: 1rem;
height: 3.375rem;
}
}

@include until-widescreen {
.gallery-item-offer {
width: 100%;
margin-top: 1rem !important;
button {
width: 100%;
height: 100%;
}
}
}
</style>
Loading
Loading