From a7da1d8b08ad19832525a842eff57acc346dbfcc Mon Sep 17 00:00:00 2001 From: roiLeo Date: Wed, 19 Jul 2023 17:07:21 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9E=96=20unused=20utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/urlTransform.spec.ts | 42 ----------- utils/chainProperties.ts | 8 -- utils/countOf.ts | 8 -- utils/format/string.ts | 0 utils/gpt.ts | 22 ------ utils/groupBy.ts | 8 -- utils/history.ts | 13 ---- utils/isFunction.ts | 3 - utils/pinata.ts | 47 ------------ utils/pinning.ts | 87 ---------------------- utils/proxy.ts | 149 ------------------------------------- utils/rpc.ts | 27 ------- utils/urlTransformer.ts | 48 ------------ utils/vueNotification.ts | 64 ---------------- 14 files changed, 526 deletions(-) delete mode 100644 tests/urlTransform.spec.ts delete mode 100644 utils/chainProperties.ts delete mode 100644 utils/countOf.ts delete mode 100644 utils/format/string.ts delete mode 100644 utils/gpt.ts delete mode 100644 utils/groupBy.ts delete mode 100644 utils/history.ts delete mode 100644 utils/isFunction.ts delete mode 100644 utils/pinata.ts delete mode 100644 utils/pinning.ts delete mode 100644 utils/proxy.ts delete mode 100644 utils/rpc.ts delete mode 100644 utils/urlTransformer.ts delete mode 100644 utils/vueNotification.ts diff --git a/tests/urlTransform.spec.ts b/tests/urlTransform.spec.ts deleted file mode 100644 index f5979468d7..0000000000 --- a/tests/urlTransform.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import transform from '@/utils/urlTransformer' - -describe('URL TRANSFORMER TEST', (): void => { - describe('For Singular', (): void => { - it('can correctly transform profile', () => { - const profile = - 'https://singular.rmrk.app/space/JHMAL5CyvxWc3Ud42QxRUTpSnUa4m56mRSzPK69d1TU8NG7' - const transformed = transform(profile) - expect(transformed).toBe( - '/rmrk/u/JHMAL5CyvxWc3Ud42QxRUTpSnUa4m56mRSzPK69d1TU8NG7' - ) - }) - - it('can correctly transform nft', () => { - const nft = - 'https://singular.rmrk.app/collectibles/10249854-FC77C33AB229A2056A-BTFLSUZANN-BEAUTIFUL_SUZANNE_13-0000000000000013' - const transformed = transform(nft) - expect(transformed).toBe( - '/rmrk/gallery/10249854-FC77C33AB229A2056A-BTFLSUZANN-BEAUTIFUL_SUZANNE_13-0000000000000013' - ) - }) - - it('can correctly transform collection', () => { - const collection = - 'https://singular.rmrk.app/collections/FC77C33AB229A2056A-BTFLSUZANN' - const transformed = transform(collection) - expect(transformed).toBe('/rmrk/collection/FC77C33AB229A2056A-BTFLSUZANN') - }) - - it('can correctly handle empty URL', () => { - const collection = '' - const transformed = transform(collection) - expect(transformed).toBe('') - }) - - it('should return empty string when the value is not correct', () => { - const collection = 'kkdot' - const transformed = transform(collection) - expect(transformed).toBe('') - }) - }) -}) diff --git a/utils/chainProperties.ts b/utils/chainProperties.ts deleted file mode 100644 index f0fe6fe7e0..0000000000 --- a/utils/chainProperties.ts +++ /dev/null @@ -1,8 +0,0 @@ -const shortAddress = (address: string): string => { - if (address) { - return `${address.slice(0, 6)}...${address.slice(-6)}` - } - return '' -} - -export default shortAddress diff --git a/utils/countOf.ts b/utils/countOf.ts deleted file mode 100644 index c8ff8c84e4..0000000000 --- a/utils/countOf.ts +++ /dev/null @@ -1,8 +0,0 @@ -export function countOf(value: DataWithCount) { - return value.count || value.totalCount -} - -export type DataWithCount = { - totalCount?: number - count?: number -} diff --git a/utils/format/string.ts b/utils/format/string.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/utils/gpt.ts b/utils/gpt.ts deleted file mode 100644 index 6f98e7f749..0000000000 --- a/utils/gpt.ts +++ /dev/null @@ -1,22 +0,0 @@ -import Axios from 'axios' - -export const BASE_URL = - 'https://petersopko.api.stdlib.com/imagedescription@dev/' // TODO: @petersopko - -const api = Axios.create({ - baseURL: BASE_URL, -}) - -export type GptResponse = { - title: string - description: string -} - -export const askGpt = async (url: string) => { - const { status, data } = await api.post( - 'titleDescriptionGenerator', - { url } - ) - console.log('[GPT::askGpt]', status) - return data -} diff --git a/utils/groupBy.ts b/utils/groupBy.ts deleted file mode 100644 index 23c586fc9d..0000000000 --- a/utils/groupBy.ts +++ /dev/null @@ -1,8 +0,0 @@ -const groupBy = (xs: any[], key: string) => { - return xs.reduce((rv, x) => { - (rv[x[key]] = rv[x[key]] || []).push(x) - return rv - }, {}) -} - -export default groupBy diff --git a/utils/history.ts b/utils/history.ts deleted file mode 100644 index 8f8dc6ea22..0000000000 --- a/utils/history.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { HistoryItem } from '~/store/history' - -export const filterHistoryItemByPrefix = ( - historyItems: HistoryItem[], - prefix: string -): HistoryItem[] => { - return historyItems.filter((item) => { - if (prefix === 'rmrk' && !item.prefix) { - return true - } - return item.prefix === prefix - }) -} diff --git a/utils/isFunction.ts b/utils/isFunction.ts deleted file mode 100644 index dcfc3c242a..0000000000 --- a/utils/isFunction.ts +++ /dev/null @@ -1,3 +0,0 @@ -const isFunction = (fn: any): boolean => typeof fn === 'function' - -export default isFunction diff --git a/utils/pinata.ts b/utils/pinata.ts deleted file mode 100644 index 05c96d5dc2..0000000000 --- a/utils/pinata.ts +++ /dev/null @@ -1,47 +0,0 @@ -import Axios from 'axios' -import { URLS } from './constants' - -export const BASE_URL = `${URLS.providers.pinata}pinning/` - -export type APIKeys = { - pinata_api_key: string - pinata_api_secret: string -} - -const api = Axios.create({ - baseURL: BASE_URL, - headers: { - 'Content-Type': 'application/json', - }, - withCredentials: false, -}) - -export const pinFileToIPFS = async ( - file: Blob, - keys: APIKeys -): Promise => { - const formData = new FormData() - formData.append('file', file) - - try { - const { status, data } = await api.post('pinFileToIPFS', formData, { - headers: { - 'Content-Type': 'multipart/form-data;', - pinata_api_key: keys.pinata_api_key, - pinata_secret_api_key: keys.pinata_api_secret, - }, - }) - console.log('[PINATA] Pin Image', status, data) - if (status < 400) { - return data.IpfsHash - } else { - throw new Error('Unable to PIN for reasons') - } - } catch (e) { - console.warn(e) - throw e - } -} - -export default api -// QmYt2FydonvVMsEqe2q3hvm38WDq21xM8Z5ZSHZw19PwjF; diff --git a/utils/pinning.ts b/utils/pinning.ts deleted file mode 100644 index 146c27f41e..0000000000 --- a/utils/pinning.ts +++ /dev/null @@ -1,87 +0,0 @@ -import Axios from 'axios' -import { URLS } from './constants' - -export const BASE_URL = URLS.koda.estuary - -const api = Axios.create({ - baseURL: BASE_URL, -}) - -export type PinningKey = { - expiry: string - token: string -} - -type EstuaryApiResponse = { - cid: string - estuaryId: number - providers: string[] -} - -export const pinJson = async (object: Record, name: string) => { - try { - const { status, data } = await api.post( - `pinJson/${name}`, - object - ) - console.log('[PINNING] Pin JSON', status) - if (status < 400) { - return data.cid - } else { - throw new Error( - `[PINNING] Unable to PIN JSON for reasons ${status} ${data}` - ) - } - } catch (e) { - console.warn(e) - throw e - } -} - -export const getKey = async (address: string): Promise => { - try { - const { status, data } = await api.get(`getKey/${address}`) - console.log('[PINNING] Obtain', status) - return data - } catch (e) { - console.warn(e) - throw e - } -} - -// TODO: implement revokeKey - -export const pinFileToIPFS = async ( - file: Blob, - token: string -): Promise => { - const formData = new FormData() - formData.append('data', file) - - try { - const { status, data } = await Axios.post( - 'https://shuttle-4.estuary.tech/content/add', - formData, - { - headers: { - 'Content-Type': 'multipart/form-data;', - Authorization: `Bearer ${token}`, - }, - } - ) - console.log('[ESTUARY] Pin Image', status) - if (status < 400) { - return data.cid - } else { - throw new Error( - `[PINNING] Unable to PIN Image for reasons ${status} ${data}` - ) - } - } catch (e) { - console.warn(e) - throw e - } -} - -export default api -// QmYt2FydonvVMsEqe2q3hvm38WDq21xM8Z5ZSHZw19PwjF; diff --git a/utils/proxy.ts b/utils/proxy.ts deleted file mode 100644 index a577bd84fc..0000000000 --- a/utils/proxy.ts +++ /dev/null @@ -1,149 +0,0 @@ -import Axios from 'axios' -import { NFTMetadata } from '@/components/rmrk/service/scheme' -import { APIKeys, pinFileToIPFS } from '@/utils/pinata' -import { justHash } from '@kodadot1/minimark/utils' -import { extractCid } from './ipfs' -import { URLS } from './constants' - -export const BASE_URL = URLS.koda.netlify - -const api = Axios.create({ - baseURL: BASE_URL, -}) - -export const pinJson = async (object: any) => { - try { - const { status, data } = await api.post('pinJson', object) - console.log('[PROXY] Pin JSON', status, data) - if (status < 400) { - return data.IpfsHash - } - } catch (e) { - console.warn(e) - throw e - } -} - -export const getKey = async (address: string) => { - try { - const { status, data } = await api.get('getKey', { params: { address } }) - console.log('[PROXY] Obtain', status) - if (status < 400) { - return data - } - } catch (e) { - console.warn(e) - throw e - } -} - -export const revokeKey = async (key: string) => { - try { - const { status, data } = await api.get('revokeKey', { params: { key } }) - console.log('[PROXY] Revoke', status) - if (status < 400) { - return data as APIKeys - } - } catch (e) { - console.warn(e) - throw e - } - - throw new Error('Key not found') -} - -export const pinFileDirect = async (file: Blob): Promise => { - try { - const keys: APIKeys = await getKey(`${file.type}::${file.size}`) - const cid = await pinFileToIPFS(file, keys) - revokeKey(keys.pinata_api_key).then(console.log, console.warn) - return cid - } catch (e) { - console.warn(e) - throw e - } -} - -export const pinFile = async (file: Blob): Promise => { - const formData = new FormData() - formData.append('data', file) - - try { - const { status, data } = await api.post('pinFile', formData, { - headers: { - 'Content-Type': 'multipart/form-data;', - }, - }) - console.log('[PROXY] Pin Image', status, data) - if (status < 400) { - return data.IpfsHash - } else { - throw new Error('Unable to PIN for reasons') - } - } catch (e) { - console.warn(e) - throw e - } -} - -const PERMAFROST_URL = process.env.VUE_APP_PERMAFROST_URL -export const permaStore = async ( - nftMeta: NFTMetadata, - file: Blob, - collection: string -): Promise => { - if (!PERMAFROST_URL) { - throw new Error('No Permafrost URL set') - } - - const formData = new FormData() - formData.append('avatar', file) - - Object.entries(nftMeta).forEach(([key, value]) => { - if (key === 'attributes') { - formData.append('attributes', JSON.stringify(value)) - } else { - formData.append(key, value) - } - }) - - formData.append('collection', collection) - - try { - const { status, data } = await Axios.post( - PERMAFROST_URL + '/store', - formData, - { - headers: { - 'Content-Type': 'multipart/form-data', - }, - } - ) - console.log('[PROXY] Permafrost', status, data) - if (status < 400) { - return data.arweaveId - } else { - throw new Error('Unable to store for reasons') - } - } catch (e) { - console.warn(e) - throw e - } -} - -export const unpin = async (ipfsLink: string) => { - const hash = justHash(ipfsLink) ? ipfsLink : extractCid(ipfsLink) - try { - const { status, data } = await api.delete(`unpin/?hash=${hash}`) - console.log('[PROXY] Unpin whatever', status, data) - if (status < 400) { - return data - } - } catch (e) { - console.warn(e) - throw e - } -} - -export default api -// QmYt2FydonvVMsEqe2q3hvm38WDq21xM8Z5ZSHZw19PwjF; diff --git a/utils/rpc.ts b/utils/rpc.ts deleted file mode 100644 index 2e6fea59dc..0000000000 --- a/utils/rpc.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { ApiPromise } from '@polkadot/api' - -export function getMetadata(api: ApiPromise) { - return api.query.nft.instances -} - -export function getMarketplaceData(api: ApiPromise) { - return api.query.nft.instances -} - -export function getPrice(api: ApiPromise) { - return api.query.marketplace.prices -} - -export function getOffers(api: ApiPromise) { - return api.query.marketplace.offers.keys -} - -export function getOwner(api: ApiPromise) { - return api.query.uniques.asset -} - -export function hasAllPallets(api: ApiPromise): boolean { - return [api.query.uniques, api.query.nft, api.query.marketplace].every( - (pallet) => pallet - ) -} diff --git a/utils/urlTransformer.ts b/utils/urlTransformer.ts deleted file mode 100644 index dce53718c9..0000000000 --- a/utils/urlTransformer.ts +++ /dev/null @@ -1,48 +0,0 @@ -type URLParams = string[] -type TransformFunction = (params: URLParams) => string -type Transformer = Record - -const getParams = (url: URL): string[] => - url.pathname.split('/').filter(Boolean) - -const lastParam = (params: URLParams): string => params[params.length - 1] - -const getTransformer = (url: URL): Transformer => availableTranformers[url.host] - -const isTransformer = (transformer?: Transformer): boolean => - transformer !== undefined - -function transform(url: string): string { - try { - const value = new URL(url) - - const transformer = getTransformer(value) - - if (!isTransformer(transformer)) { - return url - } - - const params = getParams(value) - const fn = transformer[params[0]] // TODO: only works for singular - - if (!fn) { - return url - } - - return fn(params) - } catch (e) { - return '' - } -} - -const singularTransformer: Transformer = { - space: (params: URLParams) => `/rmrk/u/${lastParam(params)}`, - collections: (params: URLParams) => `/rmrk/collection/${lastParam(params)}`, - collectibles: (params: URLParams) => `/rmrk/gallery/${lastParam(params)}`, -} - -const availableTranformers: Record = { - 'singular.rmrk.app': singularTransformer, -} - -export default transform diff --git a/utils/vueNotification.ts b/utils/vueNotification.ts deleted file mode 100644 index e5bfdbee97..0000000000 --- a/utils/vueNotification.ts +++ /dev/null @@ -1,64 +0,0 @@ -import Vue from 'vue' - -/** - * NotificationService for vue - * @example - * // Show success message - * NS.success('Success') - * @example - * // Show info message - * NS.info('This is info message'); - */ -class NotificationService extends Vue { - private snackbarTypes: any = { - success: { - type: 'is-success', - actionText: 'View', - }, - info: { - type: 'is-info', - actionText: 'OK', - }, - danger: { - type: 'is-danger', - actionText: 'Oh no!', - }, - } - - public success(message: string | null, params?: any) { - this.showNotification(message, { ...this.snackbarTypes.success, ...params }) - } - - public info(message: string | null, params?: any) { - this.showNotification(message, { ...this.snackbarTypes.info, ...params }) - } - - public danger(message: string | null, params?: any) { - this.showNotification(message, { ...this.snackbarTypes.danger, ...params }) - } - - /** - * Show error message - */ - public error(message: string | null, params?: any) { - this.danger(message, params) - } - - private showNotification( - message: string | null, - params = this.snackbarTypes.info - ) { - this.$buefy.snackbar.open({ - duration: 10000, - message, - type: 'is-success', - position: 'is-top-right', - actionText: 'OK', - queue: false, - ...params, - }) - } -} - -const bus = new NotificationService() -export default bus From d713bdfa148c3ed7763795a17c53b57032d5fbbf Mon Sep 17 00:00:00 2001 From: roiLeo Date: Thu, 20 Jul 2023 09:02:08 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A7=20StatsOverview=20countOf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/substack.json | 24 ++++++++++++------------ utils/countOf.ts | 8 ++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 utils/countOf.ts diff --git a/script/substack.json b/script/substack.json index c4c2fc92e6..71a8589dbf 100644 --- a/script/substack.json +++ b/script/substack.json @@ -1,5 +1,17 @@ { "post": [ + { + "title": "RIDE ON ART #19 - STARGAZER", + "description": "Im sure you already saw characters from this collection somewhere on your Twitter feed. Who are they, and what’s their story? And most importantly, who is behind this project?", + "image": "https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d997f5c-b869-49a6-a5d6-1023ea8d844d_1200x675.png", + "link": "https://kodadot.substack.com/p/ride-on-art-19-stargazer" + }, + { + "title": "RIDE ON ART #18 - ALIEN ANT PHARM", + "description": "Each art piece within this collection is a testament to boundless creativity, bringing together a diverse range of intriguing characters, each with its own distinctive personality.", + "image": "https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f03fc0e-83e3-4841-96d0-60fbeadde123_1200x675.png", + "link": "https://kodadot.substack.com/p/ride-on-art-18-alien-ant-pharm" + }, { "title": "RIDE ON ART #17 - CYBERPOPGIRL", "description": "Coming from far Indonesia, Cyberpopgirl NFTs are finally on KodaDot! Read on to learn more about this incredible artist.", @@ -11,18 +23,6 @@ "description": "I think we don't need to do a deep introduction. I believe everyone in our ecosystem knows the Kusama Kingdom project that was created in 2021. Read on to learn more about their successful journey.", "image": "https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fc0c58d-4016-4d4a-bc97-eb6bcc04bb1c_1200x675.png", "link": "https://kodadot.substack.com/p/ride-on-art-kusama-kingdom" - }, - { - "title": "RIDE ON ART #15 - GLAUBER", - "description": "Let's welcome Glauber, a talented artist with a unique style that will take you on a journey through his imagination. Read on to learn about his first collection on KodaDot ❤️.", - "image": "https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe19f804e-b44c-48b9-8dae-7f00efda82b2_1200x675.png", - "link": "https://kodadot.substack.com/p/ride-on-art-15-glauber" - }, - { - "title": "RIDE ON ART #14 - NEVER FAMOUS ARTISTS", - "description": "Our latest interview features not just one but a talented artistic duo - a husband and wife team. Their NFTs are incredibly beautiful and colorful and Im sure you will love them.", - "image": "https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfb87bff-377e-46dd-8866-319a6aa1bb8c_1200x675.png", - "link": "https://kodadot.substack.com/p/ride-on-art-14-never-famous-artists" } ] } \ No newline at end of file diff --git a/utils/countOf.ts b/utils/countOf.ts new file mode 100644 index 0000000000..c8ff8c84e4 --- /dev/null +++ b/utils/countOf.ts @@ -0,0 +1,8 @@ +export function countOf(value: DataWithCount) { + return value.count || value.totalCount +} + +export type DataWithCount = { + totalCount?: number + count?: number +}