Skip to content

Commit

Permalink
Merge pull request #686 from artizen-fund/updateData
Browse files Browse the repository at this point in the history
Update data
  • Loading branch information
rubelux authored Dec 15, 2023
2 parents 5975084 + 6a41282 commit 480efa0
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"eslint.validate": ["javascript"]
}
4 changes: 3 additions & 1 deletion src/components/ArtifactRaised.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ const ArtifactRaised = ({
totalSales,
matchFundPooled,
isWinner,
totalBase,
}: {
count: number
totalSales: number
matchFundPooled: number
isWinner: boolean
totalBase?: number
}) => {
// const BASE_ARTIFACT_PRICE = assertFloat(
// process.env.NEXT_PUBLIC_BASE_ARTIFACT_PRICE,
Expand Down Expand Up @@ -44,7 +46,7 @@ const ArtifactRaised = ({
// console.log('split ', split)
// console.log('matchFundMoney', matchFundMoney)

const { totalAward } = calculateSales(isWinner, matchFundPooled, count, totalSales)
const { totalAward } = calculateSales(isWinner, matchFundPooled, count, totalSales, totalBase || 0)

const showRaisedMoney: boolean = count > 0

Expand Down
4 changes: 3 additions & 1 deletion src/components/HomeParts/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ interface IProjectCard {
totalSales: number
matchFundPooled: number
seasonIsActive?: boolean
totalBase?: number
}

const ProjectCard = ({ seasonIsActive, project, index, totalSales, matchFundPooled }: IProjectCard) => {
const ProjectCard = ({ seasonIsActive, project, index, totalSales, matchFundPooled, totalBase }: IProjectCard) => {
const { setVisibleModalWithAttrs } = useContext(LayoutContext)
if (!project) return <></>
const latestArtifact = project.artifacts[0]
Expand All @@ -40,6 +41,7 @@ const ProjectCard = ({ seasonIsActive, project, index, totalSales, matchFundPool
seasonIsActive={seasonIsActive}
totalSales={totalSales ? totalSales : 0}
matchFundPooled={matchFundPooled}
totalBase={totalBase}
/>
<ArtifactNumber>{count} Minted</ArtifactNumber>
</Header>
Expand Down
9 changes: 6 additions & 3 deletions src/components/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ interface ILeaderboard {
count: number
totalSales: number
matchFundPooled: number
totalBase: number
}

const DEFAULT_LIMIT = 3
const FIXED_PRECISION = 2

const Leaderboard = ({ openEditions, isWinner, count, totalSales, matchFundPooled }: ILeaderboard) => {
const Leaderboard = ({ openEditions, isWinner, count, totalSales, matchFundPooled, totalBase }: ILeaderboard) => {
const [limit, setLimit] = useState(DEFAULT_LIMIT)

console.log('Leaderboard totalBase', totalBase)

if (!openEditions) return <Spinner minHeight="65px" />

const sideItem =
Expand All @@ -37,7 +40,7 @@ const Leaderboard = ({ openEditions, isWinner, count, totalSales, matchFundPoole
)

const { salesArtifacts, prize, totalAward, projectMatchFund, calculateMatchFundContribution, getSalesArtifacts } =
calculateSales(isWinner, matchFundPooled, count, totalSales)
calculateSales(isWinner, matchFundPooled, count, totalSales, totalBase)

const title = (
<div>
Expand All @@ -60,7 +63,7 @@ const Leaderboard = ({ openEditions, isWinner, count, totalSales, matchFundPoole
</div>
<div>
<Grey>Ξ&nbsp;{getSalesArtifacts(user.copies)}</Grey>
<Green>+&nbsp; Ξ&nbsp;{calculateMatchFundContribution(user.copies)}</Green>{' '}
{/* <Green>+&nbsp; Ξ&nbsp;{calculateMatchFundContribution(user.copies)}</Green>{' '} */}
<Amount>
| <span> minted</span> {user.copies}
</Amount>
Expand Down
18 changes: 16 additions & 2 deletions src/components/RankAndArtifactCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,28 @@ interface IRankAndArtifactCount {
seasonIsActive?: boolean
totalSales: number
matchFundPooled: number
totalBase?: number
}

const RankAndArtifactCount = ({ rank, count, seasonIsActive, totalSales, matchFundPooled }: IRankAndArtifactCount) => {
const RankAndArtifactCount = ({
rank,
count,
seasonIsActive,
totalSales,
matchFundPooled,
totalBase,
}: IRankAndArtifactCount) => {
console.log('seasonIsActive ::: ', seasonIsActive)
return (
<Wrapper>
<Rank value={rank + 1} />
<ArtifactRaised isWinner={rank === 0} count={count} totalSales={totalSales} matchFundPooled={matchFundPooled} />
<ArtifactRaised
isWinner={rank === 0}
count={count}
totalSales={totalSales}
matchFundPooled={matchFundPooled}
totalBase={totalBase}
/>
{!seasonIsActive && (
<SubmissionEnded>
<span>Season 2 ended</span>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/SeasonSubcriptionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ interface ISeasonSubcriptionContext {
seasonIsActive?: boolean
totalSales?: number
totalPrizePooled?: number
totalBase?: number
}

export const SeasonSubcriptionContext = createContext<ISeasonSubcriptionContext>({})

export const SeasonSubcriptionProvider = ({ children }: SimpleComponentProps) => {
const { season, loading, arrangedSeasonList, seasonIsActive, totalSales, totalPrizePooled } =
const { season, loading, arrangedSeasonList, seasonIsActive, totalSales, totalPrizePooled, totalBase } =
useSeasonSubscriptionData()

return (
Expand All @@ -26,6 +27,7 @@ export const SeasonSubcriptionProvider = ({ children }: SimpleComponentProps) =>
seasonIsActive,
totalSales,
totalPrizePooled,
totalBase,
}}
>
{children}
Expand Down
46 changes: 44 additions & 2 deletions src/lib/calculateSales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,56 @@ const getMatchFundMoney = (totalSales: number, countH: number, spli80: number):
return (spli80 * split) / 100
}

export const calculateSales = (isWinner: boolean, matchFundPooled: number, count: number, totalSales: number) => {
function getBaseLog(x: number, y: number) {
return Math.log(x) / Math.log(y)
}

const getMatchFundMoneyAlgor = (totalSales: number, countH: number, spli90: number, totalBase: number): number => {
// const split = totalSales > 0 ? (countH * 100) / totalSales : 0

// //split: 6*100/8 = 75%
// //spli80: 80*10/100 = 8
// return (spli80 * getBaseLog(2,split)) / 100

console.log('totalBase ', totalBase)

const BaseLog = 1.0001

console.log('countH ', countH)

const LogB2 = getBaseLog(countH + 1, BaseLog)

console.log('LogB2 ', LogB2)

const projectBasedPercent = (LogB2 * 100) / totalBase

console.log('getPercent ', projectBasedPercent)

const getCOntribution = (spli90 * projectBasedPercent) / 100

console.log('getCOntribution ', getCOntribution)

return getCOntribution
}

export const calculateSales = (
isWinner: boolean,
matchFundPooled: number,
count: number,
totalSales: number,
totalBase: number,
) => {
const getSalesArtifacts = (artifactCount: number) => BASE_ARTIFACT_PRICE * artifactCount

const totalProjectSales = getSalesArtifacts(count)

const spli90 = (90 * matchFundPooled) / 100
const split10 = (10 * matchFundPooled) / 100
const projectMatchFund = getMatchFundMoney(totalSales, count, spli90)
//const projectMatchFund = getMatchFundMoney(totalSales, count, spli90)

console.log('calculateSales totalBase ', totalBase)

const projectMatchFund = getMatchFundMoneyAlgor(totalSales, count, spli90, totalBase)

const totalAward = (totalProjectSales + projectMatchFund + (isWinner ? split10 : 0)).toFixed(2)

Expand Down
35 changes: 34 additions & 1 deletion src/lib/useSeasonSubscriptionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,40 @@ const countTotalSales = (submissions: ISubmissionFragment[]): number => {
return total
}

function getBaseLog(x: number, y: number) {
return Math.log(x) / Math.log(y)
}

const getBaseAllSales = (submissions: ISubmissionFragment[]): number => {
let baseTotal = 0
const BaseLog = 1.0001

submissions.forEach(submission => {
// total += submission.project!.artifacts[0].openEditionCopies_aggregate.aggregate!.sum!.copies!
const filteredOpenEditionCopiesTotal = filteredOpenEditionCopies(submission.project!.artifacts[0].openEditionCopies)

console.log('filteredOpenEditionCopiesTotal ', filteredOpenEditionCopiesTotal)

const submissionsCount = count(filteredOpenEditionCopiesTotal)
console.log('submissionsCount ', submissionsCount + 1)

const LogB2 = submissionsCount > 0 ? getBaseLog(submissionsCount + 1, BaseLog) : 0

console.log('LogB2 ', LogB2)
baseTotal += LogB2
})

console.log('getBaseAllSales baseTotal::: ', baseTotal)

return baseTotal
}

export function useSeasonSubscriptionData() {
const { seasonId, isSeasonActive: seasonIsActive } = useContext(SeasonContext)
const [arrangedSeasonList, setArrangedSeasonList] = useState<ISubmissionFragment[] | null>(null)
const [totalSales, setTotalSales] = useState<number>(0)
const [totalPrizePooled, setTotalPrizePooled] = useState<number>(0)
// const { isSeasonActive } = useDateHelpers()
const [totalBase, setTotalBase] = useState<number>(0)

const { data, loading, error } = useSubscription<ISubscribeSeasonsSubscription>(SUBSCRIBE_SEASONS, {
skip: !seasonId,
Expand All @@ -61,6 +89,10 @@ export function useSeasonSubscriptionData() {
const arrangedSeasonListHere = arrangeSubmissions(data?.Seasons[0].submissions)
const totalSales = countTotalSales(data?.Seasons[0].submissions)

//getBaseAllSales

setTotalBase(getBaseAllSales(data?.Seasons[0].submissions))

setArrangedSeasonList(arrangedSeasonListHere)
setTotalSales(totalSales)
const totalPrizePooledL = data?.Seasons[0].matchFundPooled + totalSales * BASE_ARTIFACT_PRICE
Expand All @@ -72,6 +104,7 @@ export function useSeasonSubscriptionData() {
return {
arrangedSeasonList,
totalSales,
totalBase,
season: data?.Seasons[0],
loading,
seasonIsActive,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const MAXIMUN_NUMBER_OF_LOADING = 9
const IndexPage = () => {
const { asPath } = useRouter()
const [numberOfLoading, setNumberOfLoading] = useState<number>(MAXIMUN_NUMBER_OF_LOADING)
const { season, loading, arrangedSeasonList, seasonIsActive, totalSales, totalPrizePooled } =
const { season, loading, arrangedSeasonList, seasonIsActive, totalSales, totalPrizePooled, totalBase } =
useContext(SeasonSubcriptionContext)

const arrangedSeasonListCapped = arrangedSeasonList?.slice(0, numberOfLoading)
Expand Down Expand Up @@ -66,6 +66,7 @@ const IndexPage = () => {
project={submission.project}
{...{ index }}
key={submission.id}
totalBase={totalBase}
seasonIsActive={seasonIsActive}
/>
))}
Expand Down
8 changes: 6 additions & 2 deletions src/pages/project/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ProjectPage = () => {
totalSales,
loading: loadingSeason,
arrangedSeasonList,
totalBase,
} = useContext(SeasonSubcriptionContext)
const { setVisibleModalWithAttrs } = useContext(LayoutContext)

Expand Down Expand Up @@ -89,12 +90,13 @@ const ProjectPage = () => {

const openEditions = openEditionsSub || openEditionsQuery

console.log('openEditions', openEditions)

const lead = project?.members?.find((m: any) => m.type === 'lead')?.user

const rank = arrangedSeasonList?.findIndex(submission => submission.project?.id === project.id) || 0

// I can take arrangedSeasonList and work out the tatio
console.log('arrangedSeasonList2', arrangedSeasonList)

const arrayOfOpenEdtionClean =
openEditions?.OpenEditionCopies.filter(({ status }: any) => {
return status === 'confirmed'
Expand All @@ -121,6 +123,7 @@ const ProjectPage = () => {
seasonIsActive={seasonIsActive}
totalSales={totalSales ? totalSales : 0}
matchFundPooled={seasonData?.matchFundPooled}
totalBase={totalBase}
/>
)}
</div>
Expand Down Expand Up @@ -159,6 +162,7 @@ const ProjectPage = () => {
count={count}
totalSales={totalSales ? totalSales : 0}
matchFundPooled={seasonData?.matchFundPooled}
totalBase={totalBase ? totalBase : 0}
/>
<ProjectSponsors projectId={project.id} />
</>
Expand Down

0 comments on commit 480efa0

Please sign in to comment.