-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create / Update Token Metadata (#866)
* Create and Update token metadata proposal * add MetadataCreationModal * Metadata is deprecated on mpl-token-metadata v2 * Metadata is deprecated on mpl-token-metadata v2 * Civic Plugin: Simplify gateway provider config (#870) * Metadata is deprecated on mpl-token-metadata v2 * fix * fixed logic about making sol treasury and selecting correct governance * yarn * connected bundlr in devnet. made bundlr.fund stable * bundlr getPrice should be called as close with uploading as possible * calculate with buffer Co-authored-by: Daniel Kelleher <[email protected]> Co-authored-by: Sebastian Bor <[email protected]>
- Loading branch information
1 parent
5e77d7e
commit 76f6835
Showing
17 changed files
with
3,283 additions
and
79 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,156 @@ | ||
import Select from '@components/inputs/Select' | ||
import { Governance, GovernanceAccountType } from '@solana/spl-governance' | ||
import { ProgramAccount } from '@solana/spl-governance' | ||
import { | ||
getMintAccountLabelInfo, | ||
getSolAccountLabel, | ||
getTokenAccountLabelInfo, | ||
} from '@utils/tokens' | ||
import React, { useEffect } from 'react' | ||
import { getProgramName } from '@components/instructions/programs/names' | ||
import { AssetAccount } from '@utils/uiTypes/assets' | ||
|
||
const GovernedAccountSelect = ({ | ||
onChange, | ||
value, | ||
error, | ||
governedAccounts = [], | ||
shouldBeGoverned, | ||
governance, | ||
label, | ||
noMaxWidth, | ||
autoselectFirst = true, | ||
}: { | ||
onChange | ||
value | ||
error? | ||
governedAccounts: AssetAccount[] | ||
shouldBeGoverned? | ||
governance?: ProgramAccount<Governance> | null | undefined | ||
label? | ||
noMaxWidth?: boolean | ||
autoselectFirst?: boolean | ||
}) => { | ||
function getLabel(value: AssetAccount) { | ||
if (value) { | ||
const accountType = value.governance.account.accountType | ||
if (value.isSol || value.isToken) { | ||
return getTokenAccountLabelComponent( | ||
value.isSol | ||
? getSolAccountLabel(value) | ||
: getTokenAccountLabelInfo(value) | ||
) | ||
} else { | ||
switch (accountType) { | ||
case GovernanceAccountType.MintGovernanceV1: | ||
case GovernanceAccountType.MintGovernanceV2: | ||
return getMintAccountLabelComponent(getMintAccountLabelInfo(value)) | ||
case GovernanceAccountType.ProgramGovernanceV1: | ||
case GovernanceAccountType.ProgramGovernanceV2: | ||
return getProgramAccountLabel(value.governance) | ||
default: | ||
return value.governance.account.governedAccount.toBase58() | ||
} | ||
} | ||
} else { | ||
return null | ||
} | ||
} | ||
//TODO refactor both methods (getMintAccountLabelComponent, getTokenAccountLabelComponent) make it more common | ||
function getMintAccountLabelComponent({ | ||
account, | ||
tokenName, | ||
mintAccountName, | ||
amount, | ||
imgUrl, | ||
}) { | ||
return ( | ||
<div className="break-all text-fgd-1"> | ||
{account && <div className="mb-0.5">{account}</div>} | ||
<div className="mb-2">{mintAccountName}</div> | ||
<div className="space-y-0.5 text-xs text-fgd-3"> | ||
{tokenName && ( | ||
<div className="flex items-center"> | ||
Token: <img className="flex-shrink-0 h-4 mx-1 w-4" src={imgUrl} /> | ||
{tokenName} | ||
</div> | ||
)} | ||
<div>Supply: {amount}</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
function getTokenAccountLabelComponent({ | ||
tokenAccount, | ||
tokenAccountName, | ||
tokenName, | ||
amount, | ||
}) { | ||
return ( | ||
<div className="break-all text-fgd-1 "> | ||
{tokenAccountName && <div className="mb-0.5">{tokenAccountName}</div>} | ||
<div className="mb-2 text-fgd-3 text-xs">{tokenAccount}</div> | ||
<div className="flex space-x-3 text-xs text-fgd-3"> | ||
{tokenName && ( | ||
<div className="flex items-center"> | ||
Token: | ||
<span className="ml-1 text-fgd-1">{tokenName}</span> | ||
</div> | ||
)} | ||
<div> | ||
Bal:<span className="ml-1 text-fgd-1">{amount}</span> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
function getProgramAccountLabel(val: ProgramAccount<Governance>) { | ||
const name = val ? getProgramName(val.account.governedAccount) : '' | ||
return ( | ||
<div className="flex flex-col"> | ||
{name && <div>{name}</div>} | ||
<div>{val?.account?.governedAccount?.toBase58()}</div> | ||
</div> | ||
) | ||
} | ||
useEffect(() => { | ||
if (governedAccounts.length == 1 && autoselectFirst) { | ||
//wait for microtask queue to be empty | ||
setTimeout(() => { | ||
onChange(governedAccounts[0]) | ||
}) | ||
} | ||
}, [JSON.stringify(governedAccounts)]) | ||
return ( | ||
<Select | ||
label={label} | ||
onChange={onChange} | ||
componentLabel={getLabel(value)} | ||
placeholder="Please select..." | ||
value={value?.governance?.account.governedAccount.toBase58()} | ||
error={error} | ||
noMaxWidth={noMaxWidth} | ||
> | ||
{governedAccounts | ||
.filter((x) => | ||
!shouldBeGoverned | ||
? !shouldBeGoverned | ||
: x?.governance?.pubkey.toBase58() === | ||
governance?.pubkey?.toBase58() | ||
) | ||
.map((acc) => { | ||
return ( | ||
<Select.Option | ||
className="border-red" | ||
key={acc.pubkey.toBase58()} | ||
value={acc} | ||
> | ||
{getLabel(acc)} | ||
</Select.Option> | ||
) | ||
})} | ||
</Select> | ||
) | ||
} | ||
|
||
export default GovernedAccountSelect |
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
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.
76f6835
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
governance-ui – ./
governance-ui-solana-labs.vercel.app
governance-ui-git-main-solana-labs.vercel.app
realms.today
daoverse.today
app.realms.today