forked from solana-labs/governance-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Friktion - Claim Pending Deposit/Withdraw Instructions (solana-la…
…bs#514) * start adding friktion * fix friktion deposit * add claim pending ixs * remove unnecessary createATA check * bump friktion sdk * fix merge conflicts * bump friktion sdk * parent 8155368 author bigdefidev <[email protected]> 1651008195 -0500 committer bigdefidev <[email protected]> 1654563073 -0500 parent 8155368 author bigdefidev <[email protected]> 1651008195 -0500 committer bigdefidev <[email protected]> 1654563034 -0500 upgrade sdk, change how volt is loaded friktion related changes * upgrade friktion sdk to 1.1.114 * use upstream main yarn.lock * fix lint errors fmt fix withdrawHumanAmount params * update yarn.lock to friktion sdk 1.1.115 * revert back * new yarn.lock * Revert "new yarn.lock" This reverts commit 5582762. * update yarn lock * update lock file * bump sdk again * remove duplicate Co-authored-by: bigdefidev <[email protected]>
- Loading branch information
1 parent
a2e46d5
commit 3d75c1b
Showing
12 changed files
with
812 additions
and
341 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
144 changes: 144 additions & 0 deletions
144
pages/dao/[symbol]/proposal/components/instructions/Friktion/FriktionClaimPendingDeposit.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,144 @@ | ||
import React, { useContext, useEffect, useState } from 'react' | ||
import useRealm from '@hooks/useRealm' | ||
import { PublicKey } from '@solana/web3.js' | ||
import useWalletStore from 'stores/useWalletStore' | ||
import { | ||
FriktionClaimPendingDepositForm, | ||
UiInstruction, | ||
} from '@utils/uiTypes/proposalCreationTypes' | ||
import { NewProposalContext } from '../../../new' | ||
import { getFriktionClaimPendingDepositSchema } from '@utils/validations' | ||
import useGovernanceAssets from '@hooks/useGovernanceAssets' | ||
import { Governance } from '@solana/spl-governance' | ||
import { ProgramAccount } from '@solana/spl-governance' | ||
import GovernedAccountSelect from '../../GovernedAccountSelect' | ||
import { getFriktionClaimPendingDepositInstruction } from '@utils/instructions/Friktion' | ||
import Select from '@components/inputs/Select' | ||
import { FriktionSnapshot, VoltSnapshot } from '@friktion-labs/friktion-sdk' | ||
|
||
const FriktionClaimPendingDeposit = ({ | ||
index, | ||
governance, | ||
}: { | ||
index: number | ||
governance: ProgramAccount<Governance> | null | ||
}) => { | ||
const connection = useWalletStore((s) => s.connection) | ||
const wallet = useWalletStore((s) => s.current) | ||
const { realmInfo } = useRealm() | ||
const { governedTokenAccountsWithoutNfts } = useGovernanceAssets() | ||
const shouldBeGoverned = index !== 0 && governance | ||
const programId: PublicKey | undefined = realmInfo?.programId | ||
const [form, setForm] = useState<FriktionClaimPendingDepositForm>({ | ||
governedTokenAccount: undefined, | ||
voltVaultId: '', | ||
programId: programId?.toString(), | ||
mintInfo: undefined, | ||
}) | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
const [friktionVolts, setFriktionVolts] = useState<VoltSnapshot[] | null>( | ||
null | ||
) | ||
const [governedAccount, setGovernedAccount] = useState< | ||
ProgramAccount<Governance> | undefined | ||
>(undefined) | ||
const [formErrors, setFormErrors] = useState({}) | ||
const { handleSetInstructions } = useContext(NewProposalContext) | ||
const handleSetForm = ({ propertyName, value }) => { | ||
setFormErrors({}) | ||
setForm({ ...form, [propertyName]: value }) | ||
} | ||
const setMintInfo = (value) => { | ||
setForm({ ...form, mintInfo: value }) | ||
} | ||
|
||
async function getInstruction(): Promise<UiInstruction> { | ||
return getFriktionClaimPendingDepositInstruction({ | ||
schema, | ||
form, | ||
programId, | ||
connection, | ||
wallet, | ||
setFormErrors, | ||
}) | ||
} | ||
useEffect(() => { | ||
// call for the mainnet friktion volts | ||
const callfriktionRequest = async () => { | ||
const response = await fetch( | ||
'https://friktion-labs.github.io/mainnet-tvl-snapshots/friktionSnapshot.json' | ||
) | ||
const parsedResponse = (await response.json()) as FriktionSnapshot | ||
setFriktionVolts(parsedResponse.allMainnetVolts as VoltSnapshot[]) | ||
} | ||
|
||
callfriktionRequest() | ||
}, []) | ||
|
||
useEffect(() => { | ||
handleSetForm({ | ||
propertyName: 'programId', | ||
value: programId?.toString(), | ||
}) | ||
}, [realmInfo?.programId]) | ||
useEffect(() => { | ||
handleSetInstructions( | ||
{ governedAccount: governedAccount, getInstruction }, | ||
index | ||
) | ||
}, [form]) | ||
useEffect(() => { | ||
setGovernedAccount(form.governedTokenAccount?.governance) | ||
setMintInfo(form.governedTokenAccount?.extensions.mint?.account) | ||
}, [form.governedTokenAccount]) | ||
const schema = getFriktionClaimPendingDepositSchema() | ||
|
||
return ( | ||
<> | ||
<GovernedAccountSelect | ||
label="Source account" | ||
governedAccounts={governedTokenAccountsWithoutNfts} | ||
onChange={(value) => { | ||
handleSetForm({ value, propertyName: 'governedTokenAccount' }) | ||
}} | ||
value={form.governedTokenAccount} | ||
error={formErrors['governedTokenAccount']} | ||
shouldBeGoverned={shouldBeGoverned} | ||
governance={governance} | ||
></GovernedAccountSelect> | ||
<Select | ||
label="Friktion Volt" | ||
value={form.voltVaultId} | ||
placeholder="Please select..." | ||
onChange={(value) => | ||
handleSetForm({ value, propertyName: 'voltVaultId' }) | ||
} | ||
error={formErrors['voltVaultId']} | ||
> | ||
{friktionVolts | ||
?.filter((x) => !x.isInCircuits) | ||
.map((value) => ( | ||
<Select.Option key={value.voltVaultId} value={value.voltVaultId}> | ||
<div className="break-all text-fgd-1 "> | ||
<div className="mb-2">{`Volt #${value.voltType} - ${ | ||
value.voltType === 1 | ||
? 'Generate Income' | ||
: value.voltType === 2 | ||
? 'Sustainable Stables' | ||
: '' | ||
} - ${value.underlyingTokenSymbol} - APY: ${value.apy}%`}</div> | ||
<div className="space-y-0.5 text-xs text-fgd-3"> | ||
<div className="flex items-center"> | ||
Deposit Token: {value.depositTokenSymbol} | ||
</div> | ||
{/* <div>Capacity: {}</div> */} | ||
</div> | ||
</div> | ||
</Select.Option> | ||
))} | ||
</Select> | ||
</> | ||
) | ||
} | ||
|
||
export default FriktionClaimPendingDeposit |
Oops, something went wrong.