diff --git a/utils/mixins/createdAtMixin.ts b/utils/mixins/createdAtMixin.ts deleted file mode 100644 index 12f7fbe3e7..0000000000 --- a/utils/mixins/createdAtMixin.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Component, Vue } from 'nuxt-property-decorator' -import { formatDistanceToNow } from 'date-fns' -/* - * refer to https://stackoverflow.com/questions/51873087/unable-to-use-mixins-in-vue-with-typescript - * usage import Component, { mixins } from 'vue-class-component'; - * class ExtendedClass extends mixins(SubscribeMixin) { - */ -@Component -export default class CreatedAtMixin extends Vue { - protected firstMintDate = new Date() - protected lastBoughtDate = new Date() - - get formattedTimeToNow() { - return this.firstMintDate - ? formatDistanceToNow(new Date(this.firstMintDate), { addSuffix: true }) - : '' - } - - get formattedLastBoughtToNow() { - return this.lastBoughtDate - ? formatDistanceToNow(new Date(this.lastBoughtDate), { addSuffix: true }) - : '' - } -} diff --git a/utils/mixins/extrinsicsMixin.ts b/utils/mixins/extrinsicsMixin.ts deleted file mode 100644 index 321478cd60..0000000000 --- a/utils/mixins/extrinsicsMixin.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { Component, Vue } from 'nuxt-property-decorator' - -/* - * refer to https://stackoverflow.com/questions/51873087/unable-to-use-mixins-in-vue-with-typescript - * import { Component, Mixins } from 'nuxt-property-decorator'; - * class ExtendedClass extends Mixins(ActualMixin) { - */ -@Component -export default class ExtrinsicMixin extends Vue { - private fnSection = '' - private fnMethod = '' - private args: any[] = [] - private selectedArguments = {} - private section = {} - - get sections() { - return Object.keys(this.section).sort() - } - - protected setSection(section: any): void { - this.section = section - } - - get methods() { - return this.fnSection - ? Object.keys(this.section[this.fnSection]).sort() - : [] - } - - get params() { - console.log(this.args) - return this.args - } - - protected handleSectionSelection(value: string): void { - this.fnSection = value - } - - protected handleMethodSelection(value: string): void { - this.fnMethod = value - } - - protected setArgs(args: any): void { - this.args = args - } - - protected handleSelectedArguments(value: any): void { - this.selectedArguments = { - ...this.selectedArguments, - ...value, - } - } - - protected hasArgs(): boolean { - return this.args && this.args.length > 0 - } - - protected getSection(): any { - return this.section[this.fnSection][this.fnMethod] - } - - protected getFnSection(): any { - return this.section[this.fnSection] - } - - protected argMapper(arg: any): any { - const accessor: string = arg.name.toString() - return this.selectedArguments[accessor] - } - - protected mapArgs(): any[] { - return this.args.map((arg) => this.argMapper(arg)) - } - - protected getFnMethodAndSection(): { fnMethod: string; fnSection: string } { - const { fnMethod, fnSection } = this - return { fnMethod, fnSection } - } -} diff --git a/utils/mixins/passionListMixin.ts b/utils/mixins/passionListMixin.ts deleted file mode 100644 index 6682d3cbe9..0000000000 --- a/utils/mixins/passionListMixin.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Component, mixins } from 'nuxt-property-decorator' -import AuthMixin from './authMixin' -import PrefixMixin from './prefixMixin' - -import passionQuery from '@/queries/rmrk/subsquid/passionFeed.graphql' - -type PassionList = string[] - -@Component -export default class PassionListMixin extends mixins(AuthMixin, PrefixMixin) { - public passionList: string[] = [''] - - async created() { - if (this.isLogIn) { - this.passionList = this.passionList.concat(await this.fetchPassionList()) - } - } - - public async fetchPassionList(): PassionList { - const { - data: { passionFeed }, - } = await this.$apollo.query({ - query: passionQuery, - client: this.client, - variables: { - account: this.accountId, - }, - fetchPolicy: 'cache-first', - }) - - return passionFeed?.map((x) => x.id) || [] - } -} diff --git a/utils/mixins/queryMixin.ts b/utils/mixins/queryMixin.ts deleted file mode 100644 index 2a8dfade9a..0000000000 --- a/utils/mixins/queryMixin.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { Component, Vue } from 'nuxt-property-decorator' -import isFunction from '@/utils/isFunction' -// declare type UnsubscribePromise = Promise; - -/* - * refer to https://stackoverflow.com/questions/51873087/unable-to-use-mixins-in-vue-with-typescript - * usage import Component, { mixins } from 'vue-class-component'; - * class ExtendedClass extends mixins(SubscribeMixin) { - */ -@Component -export default class QueryMixin extends Vue { - protected keys: any = {} - protected random: any[] = [] - protected defaultValues: any[] = [] - protected subs: any = {} - - protected magic(key: any, length: number, unwrap: any) { - return (value: any): void => { - const val = unwrap ? unwrap(value) : value - console.log(key, value) - this.$set(this.defaultValues, length, val) - } - } - - protected async extractValue({ - method, - args, - isConst, - unwrap, - valueMethod, - }: any) { - if (isConst) { - return method - } - - if (valueMethod) { - if (unwrap) { - return await valueMethod(...args).then(unwrap) - } - - return await valueMethod(...args) - } - - if (unwrap) { - return await method(...args).then(unwrap) - } - - return await method(...args) - } - - protected async handleWatch({ - key, - method, - args, - isConst, - unwrap, - valueMethod, - }: any) { - try { - if (key.name in this.keys) { - /** - * skipcq - * We already know that `key.name` is a string, because it's a property of the object, - * and already been subscribed. - */ - throw EvalError(`${key.name} already subscribed`) - } - const value = await this.extractValue({ - key, - method, - args, - isConst, - unwrap, - valueMethod, - }) - this.defaultValues = [...this.defaultValues, value] - this.random = [...this.random, key] - this.keys[key.name] = this.defaultValues.length - 1 - await this.subscribe( - method, - key.name, - args, - this.magic(key.name, this.keys[key.name], unwrap), - isConst - ) - } catch (e: any) { - console.warn(e.message) - } - } - - public async subscribe( - fn: any, - key: any, - args: any, - callback: any, - isConst?: boolean - ) { - if (isConst) { - this.subs[key] = fn - } else { - this.subs[key] = await fn(...args, callback) - } - } - - public beforeDestroy(): void { - Object.values(this.subs).forEach((sub: any) => sub()) - } - - public handleDeleteKey(key: any): void { - const index = this.keys[key] - this.$delete(this.random, index) - this.$delete(this.defaultValues, index) - - if (this.subs[key] && isFunction(this.subs[key])) { - this.subs[key]() - } - this.$delete(this.subs, key) - this.$delete(this.keys, key) - this.keys = Object.fromEntries( - Object.entries(this.keys).map(([keyIndex, value]: [string, any]) => [ - keyIndex, - value > index ? value - 1 : value, - ]) - ) - } -} diff --git a/utils/mixins/singleSubscribeMixin.ts b/utils/mixins/singleSubscribeMixin.ts deleted file mode 100644 index 5ab954fb54..0000000000 --- a/utils/mixins/singleSubscribeMixin.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Component, Vue } from 'nuxt-property-decorator' -import consola from 'consola' -// declare type UnsubscribePromise = Promise; -declare type Unsubscribe = () => void - -/* - * refer to https://stackoverflow.com/questions/51873087/unable-to-use-mixins-in-vue-with-typescript - * usage import Component, { mixins } from 'vue-class-component'; - * class ExtendedClass extends mixins(SubscribeMixin) { - */ -@Component -export default class SingleSubscribeMixin extends Vue { - private sub: Unsubscribe = () => void 0 - - public async singleSubscribe(fn: any, args: any[], callback: any) { - this.unsubscribe() // unsubscribe previous subscription - fn(...args, callback) - .then((sub: Unsubscribe) => (this.sub = sub)) - .catch(consola.error) - } - - private unsubscribe(): void { - this.sub() - } - - public beforeDestroy(): void { - this.unsubscribe() - } -}