From 825aca40efc0c8a62680c7fe5fb59ec69c2af3fb Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 16 Apr 2021 15:22:58 -0500 Subject: [PATCH 01/11] Metaplex: Royalty sliders movement (#73) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MainAuctionCard * trending auctions * fix scroll, reduce padding * fixing errors/warnings and formatting * formatting & sold auctions * artists cards * initial presale banner. move sample data to own file * new home layout * presale banner image fix * countdown implementation * initial artwork implementation * getCountdown * presale card * fix presale banner image * fix width. show preview. load only 1 file * remove preview/keep filename. url id for steps * slider > input number * upload step for every category * fix file handling * hashrouter * waiting view * congrats buttons * conffeti 🎉 * randomize conffeti rotation and size * usd conversion * initial royalties splitter * sliders movement * sliders movement * prevent single creator error. shuffle array for impartial movement Co-authored-by: B <264380+bartosz-lipinski@users.noreply.github.com> --- .../metavinci/src/views/artCreate/index.tsx | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/packages/metavinci/src/views/artCreate/index.tsx b/packages/metavinci/src/views/artCreate/index.tsx index 2fc30ae..a83591f 100644 --- a/packages/metavinci/src/views/artCreate/index.tsx +++ b/packages/metavinci/src/views/artCreate/index.tsx @@ -357,13 +357,13 @@ const InfoStep = (props: { setAttributes: (attr: IMetadataExtension) => void; confirm: () => void; }) => { - const [creators, setCreators] = useState>([]); + const [creators, setCreators] = useState>([]) const [royalties, setRoyalties] = useState>([]) useEffect(() => { setRoyalties(creators.map(creator => ({ creator_key: creator.key, - amount: 100 / creators.length, + amount: Math.trunc(100 / creators.length), }))) }, [creators]) @@ -463,6 +463,10 @@ const InfoStep = (props: { ); }; +const shuffle = (array: Array) => { + array.sort(() => Math.random() - 0.5); +} + const RoyaltiesSplitter = (props: { creators: Array, royalties: Array, @@ -476,15 +480,31 @@ const RoyaltiesSplitter = (props: { const amt = royalty.amount const handleSlide = (newAmt: number) => { - const diff = newAmt - amt - let n = props.royalties.length - 1 + const othersRoyalties = props.royalties.filter(_royalty => _royalty.creator_key != royalty.creator_key) + if (othersRoyalties.length < 1) return + shuffle(othersRoyalties) + const others_n = props.royalties.length - 1 + const sign = Math.sign(newAmt - amt) + let remaining = Math.abs(newAmt - amt) + let count = 0 + while (remaining > 0 && count < 100) { + const idx = count % others_n + const _royalty = othersRoyalties[idx] + if ( + (0 < _royalty.amount && _royalty.amount < 100) // Normal + || (_royalty.amount == 0 && sign < 0) // Low limit + || (_royalty.amount == 100 && sign > 0) // High limit + ) { + _royalty.amount -= sign + remaining -= 1 + } + count += 1 + } props.setRoyalties(props.royalties.map(_royalty => { - let computed_amount = _royalty.amount - diff / n - if (computed_amount <= 0) { - computed_amount = 0 - // n -= 1 - } + const computed_amount = othersRoyalties.find(newRoyalty => + newRoyalty.creator_key == _royalty.creator_key + )?.amount return { ..._royalty, amount: _royalty.creator_key == royalty.creator_key ? newAmt : computed_amount, @@ -494,7 +514,7 @@ const RoyaltiesSplitter = (props: { return ( {creator.label} - {amt.toFixed(0)}% + {amt}% ) From 523f01a7193be1eabee5daeb3f90260e58ef27f3 Mon Sep 17 00:00:00 2001 From: bartosz-lipinski <264380+bartosz-lipinski@users.noreply.github.com> Date: Fri, 16 Apr 2021 22:57:29 -0500 Subject: [PATCH 02/11] feat: create auction --- .../src/components/ArtCard/index.tsx | 25 +- .../src/components/ArtContent/index.tsx | 20 +- packages/metavinci/src/hooks/index.ts | 1 + packages/metavinci/src/hooks/useUserArts.tsx | 16 + .../metavinci/src/views/artworks/index.tsx | 12 +- .../src/views/auctionCreate/index.tsx | 357 +++++++----------- packages/metavinci/src/views/styles.less | 21 ++ 7 files changed, 212 insertions(+), 240 deletions(-) create mode 100644 packages/metavinci/src/hooks/useUserArts.tsx diff --git a/packages/metavinci/src/components/ArtCard/index.tsx b/packages/metavinci/src/components/ArtCard/index.tsx index 817ab4e..e7bfe60 100644 --- a/packages/metavinci/src/components/ArtCard/index.tsx +++ b/packages/metavinci/src/components/ArtCard/index.tsx @@ -1,21 +1,12 @@ import React, { useLayoutEffect, useState } from 'react'; -import { Card, Avatar } from 'antd'; +import { Card, Avatar, CardProps } from 'antd'; import { MetadataCategory } from '@oyster/common'; import { ArtContent } from './../ArtContent'; import './index.less'; const { Meta } = Card; -export const ArtCard = ({ - image, - category, - name, - symbol, - description, - artist, - preview, - small, -}: { +export interface ArtCardProps extends CardProps { image?: string; category?: MetadataCategory name?: string; @@ -23,13 +14,17 @@ export const ArtCard = ({ description?: string; artist?: string; preview?: boolean; - small?: boolean -}) => { + small?: boolean; +} + +export const ArtCard = (props: ArtCardProps) => { + const { className, small, category, image, name, preview, artist, ...rest } = props; return ( } + className={`art-card ${small ? 'small' : ''} ${className}`} + cover={} + {...rest} > { +export const ArtContent = ({ + content, + category, + className, + preview + }: { + category?: MetadataCategory, + content?: string, + className?: string, + preview?: boolean, + }) => { return category === 'video' ? -