-
Notifications
You must be signed in to change notification settings - Fork 70
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
8 changed files
with
155 additions
and
56 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
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", | ||
|