Skip to content

Commit

Permalink
dev: log state.updateState call
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece committed Feb 1, 2025
1 parent 8591478 commit fda35d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
17 changes: 15 additions & 2 deletions anchor/src/client/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down Expand Up @@ -119,11 +125,18 @@ export class StateClient {
}

public async updateState(
statePda: PublicKey,
statePda: PublicKeyOrString,
updated: Partial<StateModel>,
txOptions: TxOptions = {},
): Promise<TransactionSignature> {
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);
}

Expand Down
10 changes: 7 additions & 3 deletions anchor/src/react/glam.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { AnchorProvider } from "@coral-xyz/anchor";
import { AnchorProvider, BN } from "@coral-xyz/anchor";

import { createContext, useContext, useEffect, useMemo, useState } from "react";
import {
Expand All @@ -22,7 +22,9 @@ import { useCluster } from "./cluster-provider";

declare global {
interface Window {
glamClient: GlamClient;
glam: GlamClient;
PublicKey: any;
BN: any;
}
}

Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit fda35d1

Please sign in to comment.