From bd75b9e6863af74a8e89333a18e71ebddc42bd19 Mon Sep 17 00:00:00 2001 From: Emanuele Cesena Date: Sun, 6 Oct 2024 11:01:44 -0700 Subject: [PATCH] playground refinements (#233) --- anchor/programs/glam/src/error.rs | 4 +-- .../glam/src/instructions/investor.rs | 2 +- .../glam/src/instructions/policy_hook.rs | 2 +- anchor/src/client/base.ts | 2 +- anchor/target/idl/glam.json | 13 ++++--- anchor/target/types/glam.ts | 13 ++++--- .../src/app/access/components/columns.tsx | 34 +++++++++++-------- playground/src/app/flows/page.tsx | 9 +++-- playground/src/components/AssetInput.tsx | 4 ++- playground/src/components/ExplorerLink.tsx | 4 ++- 10 files changed, 53 insertions(+), 34 deletions(-) diff --git a/anchor/programs/glam/src/error.rs b/anchor/programs/glam/src/error.rs index a46e28fa..aa44cfea 100644 --- a/anchor/programs/glam/src/error.rs +++ b/anchor/programs/glam/src/error.rs @@ -64,6 +64,6 @@ pub enum PolicyError { TransfersDisabled, #[msg("Policy violation: amount too big")] AmountTooBig, - #[msg("Policy violation: lock out period")] - LockOut, + #[msg("Policy violation: lock-up period")] + LockUp, } diff --git a/anchor/programs/glam/src/instructions/investor.rs b/anchor/programs/glam/src/instructions/investor.rs index 893d3f3f..3dd30355 100644 --- a/anchor/programs/glam/src/instructions/investor.rs +++ b/anchor/programs/glam/src/instructions/investor.rs @@ -362,7 +362,7 @@ pub fn redeem_handler<'c: 'info, 'info>( let cur_timestamp = Clock::get()?.unix_timestamp; if cur_timestamp < locked_until_ts { - return err!(PolicyError::LockOut); + return err!(PolicyError::LockUp); } // If the lock-up period has expired, we can delete the diff --git a/anchor/programs/glam/src/instructions/policy_hook.rs b/anchor/programs/glam/src/instructions/policy_hook.rs index 5ec4592c..415b5c7e 100644 --- a/anchor/programs/glam/src/instructions/policy_hook.rs +++ b/anchor/programs/glam/src/instructions/policy_hook.rs @@ -53,7 +53,7 @@ pub fn execute(ctx: Context, amount: u64) -> Result<()> { let cur_timestamp = Clock::get()?.unix_timestamp; if cur_timestamp < locked_until_ts { - return err!(PolicyError::LockOut); + return err!(PolicyError::LockUp); } Ok(()) diff --git a/anchor/src/client/base.ts b/anchor/src/client/base.ts index 5a0a33b5..b92f810a 100644 --- a/anchor/src/client/base.ts +++ b/anchor/src/client/base.ts @@ -777,7 +777,7 @@ export class BaseClient { openfundsMetadataId: fundAccount.openfunds.toBase58(), fundUri: `https://playground.glam.systems/products/${fundPDA}`, //@ts-ignore - imageKey: (fundModel.shareClasses[0]?.id || fundPDA).toBase58(), + imageKey: (fundAccount.shareClasses[0] || fundPDA).toBase58(), ...this.getOpenfundsFromAccounts(fundAccount, openfundsAccount, [ firstShareClass, ]), diff --git a/anchor/target/idl/glam.json b/anchor/target/idl/glam.json index 0b152e29..0802fd1c 100644 --- a/anchor/target/idl/glam.json +++ b/anchor/target/idl/glam.json @@ -3866,13 +3866,18 @@ "errors": [ { "code": 6000, - "name": "NotAuthorized", - "msg": "Signer is not authorized" + "name": "TransfersDisabled", + "msg": "Policy violation: transfers disabled" }, { "code": 6001, - "name": "IntegrationDisabled", - "msg": "Integration is disabled" + "name": "AmountTooBig", + "msg": "Policy violation: amount too big" + }, + { + "code": 6002, + "name": "LockUp", + "msg": "Policy violation: lock-up period" } ], "types": [ diff --git a/anchor/target/types/glam.ts b/anchor/target/types/glam.ts index 6a0f4da4..456247be 100644 --- a/anchor/target/types/glam.ts +++ b/anchor/target/types/glam.ts @@ -3872,13 +3872,18 @@ export type Glam = { "errors": [ { "code": 6000, - "name": "notAuthorized", - "msg": "Signer is not authorized" + "name": "transfersDisabled", + "msg": "Policy violation: transfers disabled" }, { "code": 6001, - "name": "integrationDisabled", - "msg": "Integration is disabled" + "name": "amountTooBig", + "msg": "Policy violation: amount too big" + }, + { + "code": 6002, + "name": "lockUp", + "msg": "Policy violation: lock-up period" } ], "types": [ diff --git a/playground/src/app/access/components/columns.tsx b/playground/src/app/access/components/columns.tsx index 03c3807c..468277e0 100644 --- a/playground/src/app/access/components/columns.tsx +++ b/playground/src/app/access/components/columns.tsx @@ -7,6 +7,7 @@ import { DataTableColumnHeader } from "./data-table-column-header"; import { DataTableRowActions } from "./data-table-row-actions"; import Sparkle from "../../../utils/Sparkle"; import TruncateAddress from "@/utils/TruncateAddress"; +import { ExplorerLink } from "@/components/ExplorerLink"; const tagColors: Record = { stake: @@ -28,24 +29,29 @@ interface KeyData { // Use the defined type in ColumnDef export const columns: ColumnDef[] = [ - { - accessorKey: "label", - header: ({ column }) => ( - - ), - cell: ({ row }) => ( -
{row.getValue("label")}
- ), - enableSorting: true, - enableHiding: false, - }, + // { + // accessorKey: "label", + // header: ({ column }) => ( + // + // ), + // cell: ({ row }) => ( + //
{row.getValue("label")}
+ // ), + // enableSorting: true, + // enableHiding: false, + // }, { accessorKey: "pubkey", header: ({ column }) => ( ), cell: ({ row }) => ( -
{row.getValue("pubkey")}
+
+ +
), enableSorting: false, enableHiding: false, @@ -58,12 +64,12 @@ export const columns: ColumnDef[] = [ cell: ({ row }) => { const tags = row.getValue("tags") as KeyData["tags"]; return ( -
+
{tags.map((tag) => ( {tag} diff --git a/playground/src/app/flows/page.tsx b/playground/src/app/flows/page.tsx index 7474604b..b10cc661 100644 --- a/playground/src/app/flows/page.tsx +++ b/playground/src/app/flows/page.tsx @@ -79,7 +79,6 @@ function InvestorDisclaimers({ const share = fund?.shareClasses[0]; if (!fund || !share) return null; - console.log(fund); const lockUp = Number(share?.lockUpPeriodInSeconds || 0); let lockUpStr; if (lockUp < 120) { @@ -427,8 +426,8 @@ function InvestorWidget({ fundId }: { fundId: string }) { Number(walletBalances?.balanceLamports || 0) / LAMPORTS_PER_SOL ); } else { - const tokenAccount = (walletBalances.tokenAccounts || []).find( - (a: any) => a.mint === mint + const tokenAccount = (walletBalances?.tokenAccounts || []).find( + (a: any) => a.mint === mint.toBase58() ); if (tokenAccount) { setBalance(Number(tokenAccount.amount) / 10 ** tokenAccount.decimals); @@ -495,7 +494,7 @@ function InvestorWidget({ fundId }: { fundId: string }) { let txId; if (direction === "redeem") { const asset = fund.shareClasses[0].id; - const decimals = getDecimals(asset, walletBalances.tokenAccounts); + const decimals = getDecimals(asset, walletBalances?.tokenAccounts); const amount = new BN(values.amountIn * 10 ** decimals); txId = await glamClient.investor.redeem( fund.id, @@ -504,7 +503,7 @@ function InvestorWidget({ fundId }: { fundId: string }) { ); } else { const asset = fund.assets[0]; - const decimals = getDecimals(asset, walletBalances.tokenAccounts); + const decimals = getDecimals(asset, walletBalances?.tokenAccounts); const amount = new BN(values.amountIn * 10 ** decimals); txId = await glamClient.investor.subscribe(fund.id, asset, amount); } diff --git a/playground/src/components/AssetInput.tsx b/playground/src/components/AssetInput.tsx index f05eac7e..57a7764c 100644 --- a/playground/src/components/AssetInput.tsx +++ b/playground/src/components/AssetInput.tsx @@ -105,7 +105,9 @@ export const AssetInput: React.FC = ({ }, [selectedAsset, setValue, name, useMaxAmount]); const formattedBalance = new Intl.NumberFormat("en-US").format( - assets.find((asset) => asset.symbol === selectedAsset)?.balance || 0 + assets.find((asset) => asset.symbol === selectedAsset)?.balance || + balance || + 0 ); const handleInputChange = (value: string) => { diff --git a/playground/src/components/ExplorerLink.tsx b/playground/src/components/ExplorerLink.tsx index 9d7ab867..b8f7dc5c 100644 --- a/playground/src/components/ExplorerLink.tsx +++ b/playground/src/components/ExplorerLink.tsx @@ -23,7 +23,6 @@ export function ExplorerLink({ explorer?: string; }) { const cluster = useCluster(); - console.log(cluster); let href = cluster.getExplorerUrl(path); if (explorer == "solana.fm") { href = href @@ -35,6 +34,9 @@ export function ExplorerLink({ href={href} target="_blank" rel="noopener noreferrer" + onClick={(e) => { + e.stopPropagation(); + }} className={className ? className : `link font-mono`} > {ellipsify(label)}