-
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.
Withdraw fund implemented and add multicall for deposit and update
- Loading branch information
1 parent
ba5c614
commit f6e15ef
Showing
6 changed files
with
81 additions
and
18 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
50 changes: 50 additions & 0 deletions
50
frontend/gostarkme-web/components/modules/Fund/FundWithdraw.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { calculatePorcentage } from "@/app/utils"; | ||
import { Button } from "@/components/ui/Button"; | ||
import ProgressBar from "@/components/ui/ProgressBar"; | ||
import { fundAbi } from "@/contracts/abis/fund"; | ||
import { walletStarknetkitLatestAtom } from "@/state/connectedWallet"; | ||
import { latestTxAtom } from "@/state/latestTx"; | ||
import { useAtomValue, useSetAtom } from "jotai"; | ||
import { Contract, InvokeFunctionResponse } from "starknet"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
interface FundWithdrawProps { | ||
addr: string, | ||
setLoading: (load: boolean) => void, | ||
getDetails: () => void, | ||
currentBalance: number; | ||
goal: number; | ||
} | ||
|
||
export const FundWithdraw = ({ currentBalance, goal, addr, setLoading, getDetails }: FundWithdrawProps) => { | ||
|
||
const wallet = useAtomValue(walletStarknetkitLatestAtom); | ||
|
||
const progress = calculatePorcentage(currentBalance, goal); | ||
|
||
const setLatestTx = useSetAtom(latestTxAtom); | ||
|
||
const router = useRouter(); | ||
|
||
async function withdraw() { | ||
setLoading(true); | ||
const fundContract = new Contract(fundAbi, addr, wallet?.account); | ||
fundContract.withdraw() | ||
.then(async (resp: InvokeFunctionResponse) => { | ||
setLatestTx({ txHash: resp.transaction_hash, type: "vote" }); | ||
router.push("/app/confirmation"); | ||
}) | ||
.catch((e: any) => { getDetails() }); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<ProgressBar progress={progress} /> | ||
<div className="flex justify-center my-2"> | ||
<p className="text-center mx-2">{currentBalance.toString()} / {goal.toString()} </p> | ||
<p>🌟</p> | ||
</div> | ||
<Button label="Withdraw" onClick={withdraw}></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
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