Skip to content

Commit

Permalink
gui: update access page & fix SOL transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
yurushao committed Jan 18, 2025
1 parent 549e310 commit 6d4e1f0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
37 changes: 28 additions & 9 deletions anchor/src/client/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ShareClassModel,
ShareClassOpenfundsModel,
} from "../models";
import { WSOL } from "../constants";

export class StateClient {
public constructor(readonly base: BaseClient) {}
Expand Down Expand Up @@ -440,22 +441,40 @@ 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({
state: statePda,
asset,
tokenProgram,
})
.preInstructions([
createAssociatedTokenAccountIdempotentInstruction(
signer,
signerAta,
signer,
asset,
tokenProgram,
),
])
.preInstructions(preInstructions)
.postInstructions(postInstructions)
.transaction();

return await this.base.intoVersionedTransaction({ tx, ...txOptions });
Expand Down
6 changes: 3 additions & 3 deletions anchor/src/react/glam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
7 changes: 1 addition & 6 deletions playground/src/components/PageAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
]
: [];
Expand Down

0 comments on commit 6d4e1f0

Please sign in to comment.