-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from adrianvrj/feat-vote
[feat] added voting logic
- Loading branch information
Showing
10 changed files
with
183 additions
and
75 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
'use client'; | ||
|
||
import hex2ascii from "@/app/utils"; | ||
import Fund from "@/components/modules/Fund/Fund"; | ||
import Bounded from "@/components/ui/Bounded"; | ||
import Divider from "@/components/ui/Divider"; | ||
import { FUND_MANAGER_ADDR } from "@/constants"; | ||
import { fundAbi } from "@/contracts/abis/fund"; | ||
import { fundManager } from "@/contracts/abis/fundManager"; | ||
import { walletStarknetkitLatestAtom } from "@/state/connectedWallet"; | ||
import { useAtomValue } from "jotai"; | ||
import { useEffect, useState } from "react"; | ||
import { Contract } from "starknet"; | ||
|
||
const FundDetailsPage = () => { | ||
|
||
return ( | ||
<> | ||
<Bounded className="px-60 text-lg"> | ||
<Fund></Fund> | ||
</Bounded> | ||
</> | ||
); | ||
}; | ||
|
||
export default FundDetailsPage; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function hex2ascii(hexx: string) { | ||
var hex = hexx.toString();//force conversion | ||
var str = ''; | ||
for (var i = 0; i < hex.length; i += 2) | ||
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); | ||
return str; | ||
} | ||
|
||
export function calculatePorcentage(qty: number, goal: number): number { | ||
return (Number(qty) / Number(goal)) * 100; | ||
} |
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
36 changes: 29 additions & 7 deletions
36
frontend/gostarkme-web/components/modules/Fund/FundVote.tsx
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 |
---|---|---|
@@ -1,21 +1,43 @@ | ||
import { calculatePorcentage } from "@/app/utils"; | ||
import { Button } from "@/components/ui/Button"; | ||
import { LinkButton } from "@/components/ui/LinkButton"; | ||
import ProgressBar from "@/components/ui/ProgressBar"; | ||
import Image, { StaticImageData } from "next/image"; | ||
import { fundAbi } from "@/contracts/abis/fund"; | ||
import { walletStarknetkitLatestAtom } from "@/state/connectedWallet"; | ||
import { useAtomValue } from "jotai"; | ||
import { useState } from "react"; | ||
import { Contract, wallet, InvokeFunctionResponse } from "starknet"; | ||
|
||
interface FundVoteProps { | ||
icon?: StaticImageData; | ||
upVotes: number, | ||
upVotesNeeded: number, | ||
addr: string, | ||
} | ||
|
||
export const FundVote = ({ icon }: FundVoteProps) => { | ||
export const FundVote = ({ upVotes, upVotesNeeded, addr }: FundVoteProps) => { | ||
|
||
const wallet = useAtomValue(walletStarknetkitLatestAtom); | ||
|
||
const progress = calculatePorcentage(upVotes, upVotesNeeded); | ||
|
||
function vote() { | ||
const fundContract = new Contract(fundAbi, addr, wallet?.account); | ||
const myCall = fundContract.populate("receiveVote", []); | ||
wallet?.account?.execute(myCall) | ||
.then(async (resp: InvokeFunctionResponse) => { | ||
console.log("increaseBalance txH =", resp.transaction_hash); | ||
}) | ||
.catch((e: any) => { console.log("error increase balance =", e) }); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<ProgressBar progress={34} /> | ||
<ProgressBar progress={progress} /> | ||
<div className="flex justify-center my-2"> | ||
<p className="text-center mx-2">200 / 300 </p> | ||
{/* <Image src={icon || ""} alt="icon" width={24} height={24} /> */} | ||
<p className="text-center mx-2">{upVotes.toString()} / {upVotesNeeded.toString()} </p> | ||
<p>🌟</p> | ||
</div> | ||
<LinkButton label="Vote" href="/" /> | ||
<Button label="Vote" onClick={vote}></Button> | ||
</div> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const fund = [ | ||
export const fundAbi = [ | ||
{ | ||
"type": "impl", | ||
"name": "FundImpl", | ||
|
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,5 @@ | ||
import { atomWithReset } from "jotai/utils" | ||
|
||
export const clickedFundState = atomWithReset< | ||
Number | null | undefined | ||
>(undefined) |