-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
backend/packages/backend/src/scripts/spaces/kusamaSociety.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { networks, strategies } = require("./consts"); | ||
|
||
const config = { | ||
id: "kusamasociety", | ||
name: "KusamaSociety", | ||
symbol: "KSM", | ||
decimals: 12, | ||
networks: [ | ||
{ | ||
network: networks.kusama, | ||
ss58Format: 2, | ||
assets: [ | ||
{ | ||
symbol: "KSM", | ||
decimals: 12, | ||
votingThreshold: "10000000000", | ||
}, | ||
], | ||
}, | ||
], | ||
proposeThreshold: "10000000000", | ||
weightStrategy: [strategies.onePersonOneVote], | ||
version: "4", | ||
spaceIcon: "kusama.svg", | ||
seoImage: "QmYB3YVU3Sa27EfqTk3cGZ9S3GhiH6Z2ANpQdHKETpRrEZ", | ||
admins: [], | ||
}; | ||
|
||
module.exports = { | ||
kusamaSocietyConfig: config, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
next/components/postDetail/strategyResult/common/onePersonOneVoteOptionList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Tooltip } from "@osn/common-ui"; | ||
import { | ||
Divider, | ||
FlexAround, | ||
OptionIndex, | ||
ProgressBackground, | ||
ProgressBar, | ||
ProgressItem, | ||
ResultHead, | ||
ResultName, | ||
} from "./styled"; | ||
import { toPrecision } from "@osn/common"; | ||
|
||
export default function OnePersonOneVoteOptionList({ | ||
optionList, | ||
strategy, | ||
space, | ||
}) { | ||
const symbol = space?.symbol; | ||
|
||
return ( | ||
<> | ||
<ResultHead> | ||
<ResultName>{strategy}</ResultName> | ||
</ResultHead> | ||
<Divider /> | ||
{optionList.map((vote, index) => { | ||
return ( | ||
<div key={index}> | ||
<ProgressItem> | ||
<Tooltip content={vote.choice}> | ||
<OptionIndex>{vote.choice}</OptionIndex> | ||
</Tooltip> | ||
<FlexAround> | ||
<Tooltip | ||
content={`${toPrecision( | ||
vote.voteBalance, | ||
space?.decimals, | ||
)} ${symbol} (${vote.percentage}%)`} | ||
> | ||
<div>{vote.voteBalance} VOTE</div> | ||
</Tooltip> | ||
{vote.icon && <> {vote.icon}</>} | ||
</FlexAround> | ||
</ProgressItem> | ||
<ProgressBackground> | ||
<ProgressBar percent={`${vote.percentage}%`} /> | ||
</ProgressBackground> | ||
</div> | ||
); | ||
})} | ||
</> | ||
); | ||
} |
83 changes: 83 additions & 0 deletions
83
next/components/postDetail/strategyResult/onePersonOneVoteResult.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import BigNumber from "bignumber.js"; | ||
import { Tooltip } from "@osn/common-ui"; | ||
import { SystemFail, SystemPass } from "@osn/icons/opensquare"; | ||
import OnePersonOneVoteOptionList from "./common/onePersonOneVoteOptionList"; | ||
|
||
export default function OnePersonOneVoteResult({ | ||
proposal, | ||
space, | ||
voteStatus, | ||
}) { | ||
let winnerChoice = null; | ||
for (let item of voteStatus) { | ||
if (new BigNumber(item.onePersonOneVote).isZero()) { | ||
continue; | ||
} | ||
if ( | ||
!winnerChoice || | ||
new BigNumber(item.onePersonOneVote).gte(winnerChoice.onePersonOneVote) | ||
) { | ||
winnerChoice = item; | ||
} | ||
} | ||
|
||
const isEnded = new Date().getTime() > proposal?.endDate; | ||
const passStatusText = isEnded ? "Passed" : "Passing"; | ||
const failStatusText = isEnded ? "Failed" : "Failing"; | ||
|
||
const total = proposal?.votedWeights?.onePersonOneVote || 0; | ||
|
||
const optionList = []; | ||
proposal?.choices?.forEach((choice, index) => { | ||
for (let voteStat of voteStatus) { | ||
if (voteStat.choice !== choice) { | ||
continue; | ||
} | ||
|
||
const voteBalance = new BigNumber(voteStat.onePersonOneVote || 0); | ||
const percentage = ( | ||
voteStat.onePersonOneVote > 0 ? voteBalance.dividedBy(total) * 100 : 0 | ||
).toFixed(2); | ||
|
||
const isWin = voteStat.choice === winnerChoice?.choice; | ||
|
||
optionList.push({ | ||
index: index + 1, | ||
choice, | ||
voteBalance: voteBalance.toString(), | ||
percentage, | ||
icon: ( | ||
<Tooltip content={isWin ? passStatusText : failStatusText}> | ||
<div className="inline-flex"> | ||
{isWin ? <SystemPass /> : <SystemFail />} | ||
</div> | ||
</Tooltip> | ||
), | ||
}); | ||
|
||
return; | ||
} | ||
|
||
optionList.push({ | ||
index: index + 1, | ||
choice, | ||
voteBalance: "0", | ||
percentage: "0", | ||
icon: ( | ||
<Tooltip content={failStatusText}> | ||
<div className="inline-flex"> | ||
<SystemFail /> | ||
</div> | ||
</Tooltip> | ||
), | ||
}); | ||
}); | ||
|
||
return ( | ||
<OnePersonOneVoteOptionList | ||
strategy="one-person-one-vote" | ||
optionList={optionList} | ||
space={space} | ||
/> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.