Skip to content

Commit

Permalink
#3463 global offers
Browse files Browse the repository at this point in the history
  • Loading branch information
prachi00 committed Aug 7, 2022
1 parent fa58901 commit 51bafa5
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 5 deletions.
168 changes: 168 additions & 0 deletions components/bsx/Offer/MasterOfferTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<template>
<div>
<div class="is-flex is-align-items-center is-justify-content-center mb-5">
<AddressInput
class="address-input mr-3"
v-model="destinationAddress"
:strict="false" />
<b-button
type="is-primary"
icon-left="paper-plane"
@click="checkOfferForAddress"
:disabled="!correctAddress"
outlined>
{{ $t('offer.checkOffers') }}
</b-button>
</div>
<Loader v-model="isLoading" :status="status" />
<section>
<b-tabs class="tabs-container-mobile" v-model="activeTab" expanded>
<b-tab-item
:label="`${$t('offer.offersCreated')} ${
offers.length ? ' - ' + offers.length : ''
}`"
value="created">
<OffersUserTable :offers="offers" :ownerId="''" hideToggle />
</b-tab-item>
<b-tab-item
:label="`${$t('offer.incomingOffers')} ${
incomingOffersCount ? ' - ' + incomingOffersCount : ''
}`"
value="incoming">
<MyOffer
:address="accountIdChanged"
hideHeading
@offersIncoming="offersIncomingUpdate" />
</b-tab-item>
</b-tabs>
</section>
</div>
</template>

<script lang="ts">
import { Component, mixins, Watch } from 'nuxt-property-decorator'
import AuthMixin from '~/utils/mixins/authMixin'
import MetaTransactionMixin from '~/utils/mixins/metaMixin'
import { Offer, OfferResponse } from './types'
import PrefixMixin from '~/utils/mixins/prefixMixin'
import SubscribeMixin from '~/utils/mixins/subscribeMixin'
import offerListUser from '@/queries/subsquid/bsx/offerListUser.graphql'
import { notificationTypes, showNotification } from '~/utils/notification'
import correctFormat from '@/utils/ss58Format'
import { encodeAddress, isAddress } from '@polkadot/util-crypto'
import ChainMixin from '~/utils/mixins/chainMixin'
const components = {
Loader: () => import('@/components/shared/Loader.vue'),
CollapseCardWrapper: () =>
import('@/components/shared/collapse/CollapseCardWrapper.vue'),
OfferTable: () => import('@/components/bsx/Offer/OfferTable.vue'),
StatsOverview: () => import('~/components/bsx/Offer/StatsOverview.vue'),
AddressInput: () => import('@/components/shared/AddressInput.vue'),
OffersUserTable: () => import('@/components/bsx/Offer/OffersUserTable.vue'),
MyOffer: () => import('@/components/bsx/Offer/MyOffer.vue'),
}
@Component({ components })
export default class MasterOfferTable extends mixins(
AuthMixin,
MetaTransactionMixin,
PrefixMixin,
SubscribeMixin,
ChainMixin
) {
protected offers: Offer[] = []
protected total = 0
protected destinationAddress = ''
protected accountIdChanged = ''
protected incomingOffersCount = 0
public async created() {
this.checkQueryParams()
}
fetch() {
this.fetchOffers()
}
get ss58Format(): number {
return this.chainProperties?.ss58Format
}
get activeTab(): string {
return (this.$route.query.tab as string) || 'created'
}
set activeTab(val) {
const { target } = this.$route.query
this.$router.replace({
query: { target, tab: val },
})
}
get correctAddress(): string {
return this.destinationAddress
? encodeAddress(this.destinationAddress, correctFormat(this.ss58Format))
: ''
}
public offersIncomingUpdate(data) {
this.incomingOffersCount = data.offers.length
}
protected checkQueryParams() {
const { query } = this.$route
if (query.target) {
const hasAddress = isAddress(query.target as string)
if (hasAddress) {
this.destinationAddress = query.target as string
this.accountIdChanged = query.target as string
} else {
showNotification('Unable to use target address', notificationTypes.warn)
}
} else {
this.destinationAddress = this.accountId
}
}
public checkOfferForAddress() {
this.fetchOffers()
this.accountIdChanged = this.destinationAddress
}
protected setResponse(response: OfferResponse) {
this.offers = response.offers
}
protected async fetchOffers() {
try {
const { data } = await this.$apollo.query<OfferResponse>({
query: offerListUser,
client: this.client,
variables: {
id: this.destinationAddress || this.accountId,
burned: false,
},
})
if (data?.offers?.length) {
this.offers = data.offers
} else {
this.offers = []
}
} catch (e) {
showNotification(`${e}`, notificationTypes.warn)
}
}
@Watch('destinationAddress')
destinationChanged(target: string): void {
const { tab } = this.$route.query
this.$router.replace({ query: { target, tab } }).catch(() => null) // null to further not throw navigation errors
}
}
</script>
<style scoped>
.address-input {
width: 500px;
}
</style>
26 changes: 22 additions & 4 deletions components/bsx/Offer/MyOffer.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<template>
<div>
<div class="column is-8 is-offset-2">
<div class="column is-8 is-offset-2" v-if="!hideHeading">
<h1 class="title is-2 has-text-centered">
{{ $t('myOffer.bsxTitle') }}
</h1>
</div>
<b-select v-model="selectedStatus">
<option
v-for="option in getUniqType(offers)"
:value="option.type"
:key="option.type">
{{ option.value }}
</option>
</b-select>
<Loader v-model="isLoading" :status="status" />
<b-table :data="displayOffers(offers)">
<b-table-column
Expand Down Expand Up @@ -88,7 +96,7 @@
</template>

<script lang="ts">
import { Component, mixins, Watch } from 'nuxt-property-decorator'
import { Component, Emit, mixins, Prop, Watch } from 'nuxt-property-decorator'
import { Offer, OfferResponse } from './types'
import PrefixMixin from '~/utils/mixins/prefixMixin'
import acceptableOfferByCurrentOwner from '@/queries/subsquid/bsx/acceptableOfferByCurrentOwner.graphql'
Expand All @@ -107,13 +115,16 @@ const components = {
})
export default class MyOffer extends mixins(PrefixMixin, OfferMixin) {
protected offers: Offer[] = []
public destinationAddress = ''
@Prop({ type: String, default: '' }) public address!: string
@Prop({ type: Boolean, default: false }) public hideHeading!: boolean
mounted() {
if (this.accountId) {
this.$apollo.addSmartQuery<OfferResponse>('offers', {
client: this.urlPrefix,
query: acceptableOfferByCurrentOwner,
variables: { id: this.accountId },
variables: { id: this.destinationAddress || this.accountId },
manual: true,
result: ({ data }) => this.setResponse(data),
pollInterval: 10000,
Expand All @@ -128,6 +139,7 @@ export default class MyOffer extends mixins(PrefixMixin, OfferMixin) {
await this.submit(caller, item, collectionId, this.fetchMyOffers)
}
@Emit('offersIncoming')
protected setResponse(response: OfferResponse) {
this.offers = response.offers
}
Expand All @@ -138,7 +150,7 @@ export default class MyOffer extends mixins(PrefixMixin, OfferMixin) {
client: this.urlPrefix,
query: acceptableOfferByCurrentOwner,
variables: {
id: this.accountId,
id: this.destinationAddress || this.accountId,
},
})
this.setResponse(data)
Expand All @@ -151,6 +163,12 @@ export default class MyOffer extends mixins(PrefixMixin, OfferMixin) {
onAccountChange() {
this.fetchMyOffers()
}
@Watch('address', { immediate: true })
onAddressChange(value) {
this.destinationAddress = value
this.fetchMyOffers()
}
}
</script>
<style scoped>
Expand Down
2 changes: 2 additions & 0 deletions components/bsx/Offer/OffersUserTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</option>
</b-select>
<BasicSwitch
v-if="!hideToggle"
class="mt-4"
v-model="offersListed"
@input="updateList"
Expand Down Expand Up @@ -114,6 +115,7 @@ export default class OffersUserTable extends mixins(
protected offersListed = false
@Prop({ type: String, default: '' }) public ownerId!: string
@Prop({ type: Boolean, default: false }) public hideToggle!: boolean
@Emit('offersListUpdate')
public updateList(data) {
Expand Down
5 changes: 4 additions & 1 deletion langDir/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,10 @@
"nftName": "Name",
"accept": "NFT has new a owner",
"withdraw": "your offer has been withdrawn",
"burnedToggle": "Show Burned Nfts"
"burnedToggle": "Show Burned Nfts",
"checkOffers": "Check Offers",
"offersCreated": "Offers Created",
"incomingOffers": "Incoming Offers"
},
"statsOverview": {
"buys": "Buys",
Expand Down
15 changes: 15 additions & 0 deletions pages/bsx/offers.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<MasterOfferTable />
</template>

<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator'
@Component({
components: {
MasterOfferTable: () =>
import('@/components/bsx/Offer/MasterOfferTable.vue'),
},
})
export default class Offers extends Vue {}
</script>

0 comments on commit 51bafa5

Please sign in to comment.