From 92e324487d647afa24a9dd0eb59a627de5a484ae Mon Sep 17 00:00:00 2001 From: Yuru Shao Date: Sat, 18 Jan 2025 12:32:43 -0800 Subject: [PATCH] gui: update access page & fix SOL transfer (#371) --- anchor/src/client/state.ts | 37 ++++++++++++++++++------ anchor/src/react/glam.tsx | 6 ++-- playground/src/components/PageAccess.tsx | 7 +---- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/anchor/src/client/state.ts b/anchor/src/client/state.ts index 99ef9337..037d1065 100644 --- a/anchor/src/client/state.ts +++ b/anchor/src/client/state.ts @@ -22,6 +22,7 @@ import { ShareClassModel, ShareClassOpenfundsModel, } from "../models"; +import { WSOL } from "../constants"; export class StateClient { public constructor(readonly base: BaseClient) {} @@ -440,6 +441,31 @@ export class StateClient { const { tokenProgram } = await this.base.fetchMintWithOwner(asset); const signerAta = this.base.getAta(asset, signer, tokenProgram); + const preInstructions = [ + createAssociatedTokenAccountIdempotentInstruction( + signer, + signerAta, + signer, + asset, + tokenProgram, + ), + ]; + const postInstructions = []; + + if (asset.equals(WSOL)) { + const wrapSolIx = await this.base.maybeWrapSol(statePda, amount, signer); + if (wrapSolIx) { + preInstructions.push(wrapSolIx); + // If we need to wrap SOL, it means the wSOL balance will be drained, + // and we close the wSOL token account for convenience + postInstructions.push( + await this.closeTokenAccountsIx(statePda, [ + this.base.getVaultAta(statePda, WSOL), + ]), + ); + } + } + const tx = await this.base.program.methods .withdraw(new BN(amount)) .accounts({ @@ -447,15 +473,8 @@ export class StateClient { asset, tokenProgram, }) - .preInstructions([ - createAssociatedTokenAccountIdempotentInstruction( - signer, - signerAta, - signer, - asset, - tokenProgram, - ), - ]) + .preInstructions(preInstructions) + .postInstructions(postInstructions) .transaction(); return await this.base.intoVersionedTransaction({ tx, ...txOptions }); diff --git a/anchor/src/react/glam.tsx b/anchor/src/react/glam.tsx index 1f0fc4eb..386dcdfd 100644 --- a/anchor/src/react/glam.tsx +++ b/anchor/src/react/glam.tsx @@ -284,12 +284,12 @@ export function GlamProvider({ const prices = Object.values(jupTokenPricesData.data).map( (p: any) => ({ - mint: p.id, - price: Number(p.price), + mint: p?.id, + price: Number(p?.price), }) as TokenPrice, ); - setTokenPrices(prices); + setTokenPrices(prices.filter((p) => !!p.mint)); } }, [jupTokenPricesData]); diff --git a/playground/src/components/PageAccess.tsx b/playground/src/components/PageAccess.tsx index 93a4558d..b5d72b9c 100644 --- a/playground/src/components/PageAccess.tsx +++ b/playground/src/components/PageAccess.tsx @@ -35,17 +35,12 @@ export default function PageAccess({ ).concat(mintTreeDataPermissions.children || []); } - const flatPermissions = - treeDataPermissions.children?.flatMap( - (lvl1: any) => lvl1.children?.map((node: any) => node.id) || [], - ) || []; - const owner = state.owner?.pubkey ? [ { pubkey: state.owner.pubkey.toBase58(), label: "Owner", - tags: flatPermissions, + tags: ["Full Access"], }, ] : [];