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

✨ swap page landing #11163

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dca9973
✨ swap page landing
roiLeo Oct 23, 2024
2d4c882
✨ wip: swap page Step 2
roiLeo Oct 23, 2024
ca66655
✨ wip: swap page Step 2
roiLeo Oct 24, 2024
0fe2f3d
✨ wip: swap page Step 2 list
roiLeo Oct 24, 2024
6bff9f9
✨ wip: steps flow final
roiLeo Oct 24, 2024
1f9219c
Merge branch 'main' into feature/init/swapLanding
roiLeo Oct 30, 2024
1938f80
ref(swap): move simialr logic into smaller components
hassnian Nov 6, 2024
5d08758
add(swaps): store add item logic
hassnian Nov 6, 2024
5071fdb
add(offers): store multichain support
hassnian Nov 6, 2024
bc35ebd
ref(useAtomicSwapAction.ts): cleaner and null check
hassnian Nov 6, 2024
75041cd
add(swaps): add connect wallet button if wallet is not disconnected
hassnian Nov 7, 2024
1923237
add(swaps): swap middleware & review step
hassnian Nov 7, 2024
6e0c279
add(swaps): pesist store and step
hassnian Nov 7, 2024
d0d6ad3
add(swaps): init `createSwap` transaction
hassnian Nov 9, 2024
4db3059
ref(swaps): preview and fix surcharge per step
hassnian Nov 10, 2024
21b362c
fix(swap/Preview.vue): step based `surchargeDirection`
hassnian Nov 10, 2024
e843fea
fix(swaps): `getSwapStepRouteName` util
hassnian Nov 10, 2024
e568190
add(swaps): `swapId` in route
hassnian Nov 11, 2024
55c153f
fix(swaps): `surcharge` amount
hassnian Nov 11, 2024
57ca110
add(swaps): grid list filters
hassnian Nov 11, 2024
82846e9
fix(swaps): collection grid filter owner prop
hassnian Nov 12, 2024
5768199
ref(CollectionFilter.vue): query overfetching collection details
hassnian Nov 12, 2024
40f6996
add(swaps): selection cart sticky when scrolling
hassnian Nov 12, 2024
d40dbc3
🔧 ts warning swapgridlistfilter
roiLeo Nov 12, 2024
386a3f3
fix(swaps): network dropdown filter by vm & correct route redirect
hassnian Nov 12, 2024
8fe626a
fix(swaps): chain redirect pass swapId query
hassnian Nov 12, 2024
3a2193d
ref(swaos): transaction force 1:1 nft swaps
hassnian Nov 13, 2024
a124524
ref(swaps): selection disable next button if is over 1:1 swap
hassnian Nov 13, 2024
5018234
Merge branch 'feature/init/swapLanding' of https://github.com/roiLeo/…
hassnian Nov 13, 2024
4323ab1
ref(swaps): move `SwapStep` to `components/swap/types`
hassnian Nov 13, 2024
36dd75e
ref(swaps): layout and code duplication
hassnian Nov 13, 2024
e82f84a
ref(swaps): preview cart item
hassnian Nov 13, 2024
9442a8a
ref(swaps): pass `step` as prop to `Preview.vue`
hassnian Nov 14, 2024
618d5d2
ref(swaps): singular `swap` store name
hassnian Nov 14, 2024
bbf5219
add(swaps): allow logged out swap first steps
hassnian Nov 14, 2024
e09b5a5
fix(swaps): `isItemSelected` computed
hassnian Nov 14, 2024
e5fe925
ref(swaps): review step use `updateSwap` to update swap store
hassnian Nov 14, 2024
1da4f5c
fix(swap): `review.vue` redirect on success
hassnian Nov 14, 2024
a08d281
🔧 improve responsive
roiLeo Nov 14, 2024
dacbace
🔧 missing swap review hr
roiLeo Nov 14, 2024
f90a84a
🔧 swap selection to tailwind
roiLeo Nov 14, 2024
8b80fdb
🔧 swap review to tailwind
roiLeo Nov 14, 2024
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
19 changes: 19 additions & 0 deletions assets/svg/swap/arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions assets/svg/swap/arrow-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions assets/svg/swap/arrows.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions components/collection/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export type CollectionEntityMinimal = {
name: string
currentOwner: string
type: string
ownerCount?: number
}
7 changes: 5 additions & 2 deletions components/common/ChainDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
<template #trigger="{ active }">
<NeoButton
class="chain-dropdown-text"
:variant
:label="
isMobile || !showNetworkLabel
? selected?.text
? label || selected?.text
: `Network: ${selected?.text}`
"
:icon="active ? 'chevron-up' : 'chevron-down'"
Expand All @@ -27,7 +28,7 @@
</template>

<script setup lang="ts">
import { NeoButton, NeoDropdown, NeoDropdownItem } from '@kodadot1/brick'
import { NeoButton, NeoDropdown, NeoDropdownItem, type NeoButtonVariant } from '@kodadot1/brick'
import { type Prefix } from '@kodadot1/static'

const props = withDefaults(
Expand All @@ -36,6 +37,8 @@ const props = withDefaults(
position?: 'bottom-auto'
redirect?: boolean
exclude: Prefix[]
variant?: NeoButtonVariant
label?: string
}>(),
{
showNetworkLabel: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
>
<input
v-model="model"
:disabled="disabled"
type="number"
step="0.01"
min="0.001"
pattern="[0-9]+([\.,][0-9]+)?"
class="indent-2.5 border-none outline-none w-20 bg-background-color text-text-color"
:placeholder="$t('price')"
:placeholder="placeholder || $t('price')"
>
<div class="px-3 flex items-center">
{{ chainSymbol }}
Expand All @@ -35,6 +36,8 @@ const props = defineProps<{
modelValue?: number | string
check?: boolean
fullWidth?: boolean
disabled?: boolean
placeholder?: string
}>()
const emit = defineEmits(['confirm', 'update:modelValue'])

Expand Down
48 changes: 39 additions & 9 deletions components/items/ItemsGrid/ItemsGridImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
:class="{
'in-cart-border':
shoppingCartStore.isItemInCart(nft.id)
|| listingCartStore.isItemInCart(nft.id),
|| listingCartStore.isItemInCart(nft.id)
|| isAtomicSwapItemSelected
,
}"
:show-action-on-hover="!showActionSection"
:link="NuxtLink"
Expand All @@ -26,7 +28,7 @@
#action
>
<div
v-if="!isOwner && Number(nft?.price)"
v-if="!isOwner && Number(nft?.price) && !showAtomicSwapAction"
class="flex"
>
<NeoButton
Expand Down Expand Up @@ -56,15 +58,15 @@
</NeoButton>
</div>
<div
v-else-if="isOwner && !hideListing"
v-else-if="showSelect"
class="flex"
>
<NeoButton
:label="listLabel"
:label="selectLabel"
data-testid="item-buy"
no-shadow
class="flex-grow"
@click.prevent="onClickListingCart"
@click.prevent="onSelect"
/>
</div>
</template>
Expand All @@ -80,6 +82,7 @@
// PLEASE FIX bind-key href => to
import { resolveComponent } from 'vue'
import { NeoButton, NeoIcon } from '@kodadot1/brick'
import useAtomicSwapAction from './useAtomicSwapAction'
import type { NftCardVariant } from '@/components/shared/nftCard/types'
import type { NFTWithMetadata } from '@/composables/useNft'
import { useShoppingCartStore } from '@/stores/shoppingCart'
Expand Down Expand Up @@ -111,6 +114,12 @@ const props = defineProps<{
skeletonVariant: string
}>()

const {
onAtomicSwapSelect,
showAtomicSwapAction,
isItemSelected: isAtomicSwapItemSelected,
} = useAtomicSwapAction(props.nft)

const showActionSection = computed(() => {
return !isLogIn.value && shoppingCartStore.getItemToBuy?.id === props.nft.id
})
Expand All @@ -125,8 +134,6 @@ const buyLabel = computed(function () {
)
})

const listLabel = computed(() => listingCartStore.isItemInCart(props.nft.id) ? $i18n.t('remove') : $i18n.t('select'))

const isOwner = computed(() => isCurrentOwner(props.nft?.currentOwner))

const openCompletePurcahseModal = () => {
Expand Down Expand Up @@ -155,8 +162,31 @@ const onClickShoppingCart = () => {
shoppingCartStore.setItem(nftToShoppingCartItem(props.nft))
}
}
const onClickListingCart = () => {
listNftByNftWithMetadata(props.nft, { toggle: true })

const onClickListingCart = () => listNftByNftWithMetadata(props.nft, { toggle: true })

// select

const selectLabel = computed(() => {
const selected = showAtomicSwapAction.value ? isAtomicSwapItemSelected.value : listingCartStore.isItemInCart(props.nft.id)
return selected ? $i18n.t('remove') : $i18n.t('select')
})

const showSelect = computed(() => {
if (showAtomicSwapAction.value) {
return true
}

return isOwner.value && !props.hideListing
})

const onSelect = () => {
if (showAtomicSwapAction.value) {
onAtomicSwapSelect()
}
else {
onClickListingCart()
}
}
</script>

Expand Down
45 changes: 45 additions & 0 deletions components/items/ItemsGrid/useAtomicSwapAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { NFTWithMetadata } from '@/composables/useNft'

export const ATOMIC_SWAP_PAGES = [
'prefix-swap-id',
'prefix-swap-id-offer',
'prefix-swap-id-review',
]

export default (nft: NFTWithMetadata) => {
const route = useRoute()
const atomicSwapStore = useAtomicSwapsStore()
const { step, stepItems } = storeToRefs(atomicSwapStore)

const routeName = computed(() => route.name?.toString() as string)

const showAtomicSwapAction = computed(() => ATOMIC_SWAP_PAGES.includes(routeName.value))

const isItemSelected = computed(() => {
return step.value === SwapStep.REVIEW ? false : stepItems.value?.some(item => item.id === nft.id)
})

const onAtomicSwapSelect = () => {
if (isItemSelected.value) {
atomicSwapStore.removeStepItem(nft.id)
}
else {
atomicSwapStore.updateStepItems([
...stepItems.value,
{
id: nft.id,
collectionId: nft.collection.id,
sn: nft.sn,
name: nft.name,
meta: nft.meta,
},
])
}
}

return {
onAtomicSwapSelect,
showAtomicSwapAction,
isItemSelected,
}
}
2 changes: 2 additions & 0 deletions components/items/ItemsGrid/useItemsGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useItemsGridQueryParams,
useSearchParams,
} from './utils/useSearchParams'
import { ATOMIC_SWAP_PAGES } from './useAtomicSwapAction'
import resolveQueryPath from '@/utils/queryPathResolver'
import { getDenyList } from '@/utils/prefix'
import type { NFTWithMetadata, TokenEntity } from '@/composables/useNft'
Expand All @@ -25,6 +26,7 @@ const EXCLUDED_TOKEN_USE_PAGES = [
'prefix-collection-id',
'prefix-drops-id',
'prefix-u-id',
...ATOMIC_SWAP_PAGES,
]

export function useFetchSearch({
Expand Down
17 changes: 6 additions & 11 deletions components/items/ItemsGrid/useNftActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import nftById from '@/queries/subsquid/general/nftById.graphql'
import listCount from '@/queries/subsquid/general/countOfTokenNftsToList.graphql'
import nftListWithSearch from '@/queries/subsquid/ahk/nftListWithSearch.graphql'
import type { TokenId } from '@/types'

Expand Down Expand Up @@ -130,19 +129,15 @@ export const getTokensNfts = async (
}

export const checkIfAnythingToList = async (entities: TokenEntity[]) => {
const { client, urlPrefix } = usePrefix()
const { accountId } = useAuth()
const { data } = await useAsyncQuery<{ count: { totalCount: number } }>({
query: listCount,
variables: {
token: entities.map(({ id }) => id),
owner: accountId.value,
denyList: getDenyList(urlPrefix.value),
},
clientId: client.value,

const count = await getNftCount({
token: { id_in: entities.map(n => n.id) },
currentOwner_eq: accountId.value,
price_eq: 0,
})

return data.value.count.totalCount > 0
return count > 0
}

export function useNftActions(entity: TokenEntity) {
Expand Down
13 changes: 9 additions & 4 deletions components/offer/OfferExpirationSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
v-model="selected"
aria-role="list"
:triggers="['click']"
position="bottom-left"
:position="position"
append-to-body
close-menu-on-move
class="w-full"
Expand Down Expand Up @@ -54,9 +54,14 @@ const options = EXPIRATION_DAYS_LIST.map(value => ({

const selectedItem = computed(() => options.find(option => option.value === selected.value))

const props = defineProps<{
modelValue?: number
}>()
const props = withDefaults(
defineProps<{
modelValue?: number
position?: string
}>(), {
position: 'bottom-left',
},
)

const emit = defineEmits(['update:modelValue'])

Expand Down
Loading
Loading