Skip to content

Commit

Permalink
playground refinements (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece authored Oct 6, 2024
1 parent 0392215 commit bd75b9e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 34 deletions.
4 changes: 2 additions & 2 deletions anchor/programs/glam/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion anchor/programs/glam/src/instructions/investor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion anchor/programs/glam/src/instructions/policy_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn execute(ctx: Context<TransferHook>, 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(())
Expand Down
2 changes: 1 addition & 1 deletion anchor/src/client/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]),
Expand Down
13 changes: 9 additions & 4 deletions anchor/target/idl/glam.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
13 changes: 9 additions & 4 deletions anchor/target/types/glam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
34 changes: 20 additions & 14 deletions playground/src/app/access/components/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
stake:
Expand All @@ -28,24 +29,29 @@ interface KeyData {

// Use the defined type in ColumnDef
export const columns: ColumnDef<KeyData>[] = [
{
accessorKey: "label",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Label" />
),
cell: ({ row }) => (
<div className="w-[100px] truncate">{row.getValue("label")}</div>
),
enableSorting: true,
enableHiding: false,
},
// {
// accessorKey: "label",
// header: ({ column }) => (
// <DataTableColumnHeader column={column} title="Label" />
// ),
// cell: ({ row }) => (
// <div className="w-[100px] truncate">{row.getValue("label")}</div>
// ),
// enableSorting: true,
// enableHiding: false,
// },
{
accessorKey: "pubkey",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Key" />
),
cell: ({ row }) => (
<div className="w-[100px] truncate">{row.getValue("pubkey")}</div>
<div className="w-[100px]">
<ExplorerLink
path={`/account/${row.getValue("pubkey")}`}
label={row.getValue("pubkey")}
/>
</div>
),
enableSorting: false,
enableHiding: false,
Expand All @@ -58,12 +64,12 @@ export const columns: ColumnDef<KeyData>[] = [
cell: ({ row }) => {
const tags = row.getValue("tags") as KeyData["tags"];
return (
<div className="flex space-x-2">
<div className="space-x-2">
{tags.map((tag) => (
<Badge
key={tag}
variant="default"
className={`pointer-events-none capitalize font-normal rounded-none dark:bg-opacity-25 ${tagColors[tag]}`}
className={`my-1 pointer-events-none capitalize font-normal rounded-none dark:bg-opacity-25 ${tagColors[tag]}`}
>
{tag}
</Badge>
Expand Down
9 changes: 4 additions & 5 deletions playground/src/app/flows/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion playground/src/components/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export const AssetInput: React.FC<AssetInputProps> = ({
}, [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) => {
Expand Down
4 changes: 3 additions & 1 deletion playground/src/components/ExplorerLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)}
Expand Down

0 comments on commit bd75b9e

Please sign in to comment.