-
Notifications
You must be signed in to change notification settings - Fork 42
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
1,294 additions
and
75 deletions.
There are no files selected for viewing
Binary file not shown.
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,56 @@ | ||
import { TREASURY_ADDRESS, ETH_ADDRESS, STRK_ADDRESS } from '../constants/config.json'; | ||
import React, { useMemo } from "react"; | ||
import { useContractRead } from "@starknet-react/core"; | ||
import { abi, formatBalance } from "../lib/erc20"; | ||
|
||
export default function TreasuryStatus() { | ||
const tokens = [ | ||
{ name: "ETH", address: ETH_ADDRESS }, | ||
{ name: "STRK", address: STRK_ADDRESS }, | ||
]; | ||
|
||
const balanceReads = tokens.map(token => | ||
useContractRead({ | ||
functionName: "balanceOf", | ||
args: [TREASURY_ADDRESS], | ||
abi, | ||
address: token.address, | ||
watch: true, | ||
}) | ||
); | ||
|
||
const balances = useMemo(() => | ||
tokens.map((token, index) => ({ | ||
name: token.name, | ||
balance: balanceReads[index].data, | ||
isLoading: balanceReads[index].isLoading, | ||
})), | ||
[balanceReads.map(read => read.data)] | ||
); | ||
|
||
const isLoading = balances.some(b => b.isLoading); | ||
|
||
return ( | ||
<div className="p-6 mb-6"> | ||
<div className="flex w-full flex-grow pb-4 text-2xl font-bold">Treasury status</div> | ||
{isLoading ? ( | ||
<div>Loading...</div> | ||
) : ( | ||
<div className="w-[50rem] max-w-[50rem] grid grid-cols-2 items-center p-2 pl-0 rounded-lg bg-slate-200"> | ||
{balances.map((token, index) => ( | ||
<div key={index} className="flex items-center"> | ||
<div className="self-stretch pl-5 pr-4 mr-4 font-mono border-r grid text-slate-400 place-content-center border-slate-400"> | ||
{token.name} | ||
</div> | ||
<div className="flex justify-between items-center gap-20"> | ||
<div className="flex-grow font-bold"> | ||
{formatBalance(BigInt(token.balance.toString()))} | ||
</div> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useState } from "react"; | ||
import { ETH_ADDRESS, STRK_ADDRESS } from '../../constants/config.json'; | ||
import { toast } from 'react-hot-toast'; | ||
|
||
interface DistributionProps { | ||
onSubmit: (calldata: string[]) => void; | ||
} | ||
|
||
export const Distribution: React.FC<DistributionProps> = ({ onSubmit }) => { | ||
const [recipient, setRecipient] = useState(""); | ||
const [token, setToken] = useState("ETH"); | ||
const [amount, setAmount] = useState(""); | ||
|
||
const handleSubmit = (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
let tok; | ||
if(token == "ETH") { | ||
tok = ETH_ADDRESS; | ||
} else if (token == "STRK") { | ||
tok = STRK_ADDRESS; | ||
} | ||
|
||
if(!recipient.startsWith("0x")) { | ||
toast.error('Address must start with 0x'); | ||
return; | ||
} | ||
const amountWei = parseFloat(amount).toString(); | ||
const calldata = [recipient, tok, amountWei]; | ||
onSubmit(calldata); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit} className="space-y-4"> | ||
<div> | ||
<label htmlFor="recipient" className="block mb-2">Recipient</label> | ||
<input | ||
id="recipient" | ||
className='border border-gray-300 rounded-lg p-2 w-full' | ||
type="text" | ||
value={recipient} | ||
onChange={(e) => setRecipient(e.target.value)} | ||
/> | ||
</div> | ||
<div> | ||
<label htmlFor="token" className="block mb-2">Token to distribute</label> | ||
<select | ||
id="token" | ||
className='border border-gray-300 rounded-lg p-2 w-full' | ||
value={token} | ||
onChange={(e) => setToken(e.target.value)} | ||
> | ||
<option value="ETH">ETH</option> | ||
</select> | ||
</div> | ||
<div> | ||
<label htmlFor="amount" className="block mb-2">Amount</label> | ||
<input | ||
id="amount" | ||
type="number" | ||
className='border border-gray-300 rounded-lg p-2 w-full' | ||
value={amount} | ||
onChange={(e) => setAmount(e.target.value)} | ||
/> | ||
</div> | ||
<button | ||
type="submit" | ||
className="w-full p-2 mt-4 text-white bg-blue-500 rounded-lg" | ||
> | ||
Submit | ||
</button> | ||
</form> | ||
); | ||
}; |
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,74 @@ | ||
import React, { useState } from "react"; | ||
import { Distribution } from "./Distribution"; | ||
import { useAccount, useContractWrite } from '@starknet-react/core'; | ||
import { toast } from 'react-hot-toast'; | ||
import { CONTRACT_ADDR } from "../../lib/config"; | ||
|
||
const treasuryProposalTypes = ["distribution", "zklend", "nostra", "carmine"]; | ||
|
||
|
||
export default function Treasury({ | ||
setIsModalOpen, | ||
}: { | ||
setIsModalOpen: React.Dispatch<React.SetStateAction<boolean>>; | ||
}) { | ||
const [selectedType, setSelectedType] = useState<string | null>(null); | ||
const { isConnected } = useAccount(); | ||
const [calldata, setCalldata] = useState<string[]>([]); | ||
|
||
const { writeAsync } = useContractWrite({ calls: [] }); | ||
|
||
const handleSubmit = async (newCalldata: string[]) => { | ||
if (!isConnected) { | ||
toast.error('Please connect your wallet'); | ||
return; | ||
} | ||
|
||
if (!selectedType || newCalldata.length === 0) { | ||
toast.error('Please fill out all fields'); | ||
return; | ||
} | ||
|
||
setCalldata(newCalldata); | ||
if (!selectedType || calldata.length === 0) return []; | ||
const calls = [{ | ||
contractAddress: CONTRACT_ADDR, | ||
entrypoint: 'submit_custom_proposal', | ||
calldata: [ | ||
selectedType, | ||
...calldata.map(data => data.toString()), | ||
], | ||
}]; | ||
try { | ||
await writeAsync({ calls: calls }); | ||
toast.success('Custom proposal submitted'); | ||
} catch (e) { | ||
toast.error('Something went wrong'); | ||
console.error(e); | ||
} finally { | ||
setIsModalOpen(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="flex justify-between space-x-2"> | ||
{treasuryProposalTypes.map((type) => ( | ||
<button | ||
key={type} | ||
type="button" | ||
onClick={() => setSelectedType(type)} | ||
className={`px-4 py-2 rounded flex-1 ${ | ||
selectedType === type ? "bg-blue-500 text-white" : "bg-gray-200" | ||
}`} | ||
> | ||
{type} | ||
</button> | ||
))} | ||
</div> | ||
{selectedType === "distribution" && ( | ||
<Distribution onSubmit={handleSubmit} /> | ||
)} | ||
</> | ||
); | ||
} |
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 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
Oops, something went wrong.