From 5cd0ceee1ed68671d9476fd2959af539aeaab21b Mon Sep 17 00:00:00 2001 From: Emanuele Cesena Date: Sat, 1 Feb 2025 15:13:56 -0800 Subject: [PATCH] dev: log state.updateState call --- anchor/src/client/state.ts | 17 +++++++++++++++-- anchor/src/react/glam.tsx | 8 ++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/anchor/src/client/state.ts b/anchor/src/client/state.ts index e0f7dee6..06554670 100644 --- a/anchor/src/client/state.ts +++ b/anchor/src/client/state.ts @@ -26,6 +26,12 @@ import { } from "../models"; import { WSOL } from "../constants"; +type PublicKeyOrString = PublicKey | string; + +function getPublicKey(input: PublicKeyOrString) { + return typeof input === "string" ? new PublicKey(input) : input; +} + export class StateClient { public constructor(readonly base: BaseClient) {} @@ -119,11 +125,18 @@ export class StateClient { } public async updateState( - statePda: PublicKey, + statePda: PublicKeyOrString, updated: Partial, txOptions: TxOptions = {}, ): Promise { - const tx = await this.updateStateTx(statePda, updated, txOptions); + console.log( + `await glam.state.updateState("${statePda.toString()}", ${JSON.stringify(updated)}, ${JSON.stringify(txOptions)});`, + ); + const tx = await this.updateStateTx( + getPublicKey(statePda), + updated, + txOptions, + ); return await this.base.sendAndConfirm(tx); } diff --git a/anchor/src/react/glam.tsx b/anchor/src/react/glam.tsx index b42e584b..a0082703 100644 --- a/anchor/src/react/glam.tsx +++ b/anchor/src/react/glam.tsx @@ -22,7 +22,9 @@ import { useCluster } from "./cluster-provider"; declare global { interface Window { - glamClient: GlamClient; + glam: GlamClient; + PublicKey: any; + BN: any; } } @@ -148,7 +150,9 @@ export function GlamProvider({ }), cluster: cluster.network, }); - window.glamClient = glamClient; + window.glam = glamClient; + window.PublicKey = PublicKey; + window.BN = BN; return glamClient; }, [connection, wallet, cluster]);