Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions tokens/token-2022/nft-meta-data-pointer/app/.eslintrc.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button, HStack, VStack } from '@chakra-ui/react';
import { useSessionWallet } from '@magicblock-labs/gum-react-sdk';
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { PublicKey } from '@solana/web3.js';
import { PublicKey, SystemProgram } from '@solana/web3.js';
import Image from 'next/image';
import { useCallback, useState } from 'react';
import { useGameState } from '@/contexts/GameStateProvider';
Expand All @@ -21,11 +21,20 @@ const ChopTreeButton = () => {

const onChopClick = useCallback(async () => {
setIsLoadingSession(true);
if (!playerDataPDA || !sessionWallet?.publicKey) return;
if (!playerDataPDA || !sessionWallet?.publicKey || !sessionWallet.sessionToken) {
setIsLoadingSession(false);
return;
}
Comment thread
dev-jodee marked this conversation as resolved.
setTransactionCounter(transactionCounter + 1);

const nftAuthority = await PublicKey.findProgramAddress([Buffer.from('nft_authority')], program.programId);

if (nftState == null) {
window.alert('Load NFT state first');
setIsLoadingSession(false);
return;
}

let nft = null;

for (let i = 0; i < nftState.items.length; i++) {
Expand All @@ -43,7 +52,7 @@ const ChopTreeButton = () => {
console.log('NFT', nft);
if (nft == null) {
window.alert('Mint and NFT character first');
setIsLoadingMainWallet(false);
setIsLoadingSession(false);
return;
}

Expand All @@ -57,6 +66,8 @@ const ChopTreeButton = () => {
sessionToken: sessionWallet.sessionToken,
nftAuthority: nftAuthority[0],
mint: nft.id,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_2022_PROGRAM_ID,
})
.transaction();

Expand Down Expand Up @@ -91,9 +102,11 @@ const ChopTreeButton = () => {
for (let i = 0; i < nftState.items.length; i++) {
try {
const nftData = nftState.items[i];
console.log(`${nftData.authorities[0].address} == ${nftAuthority[0].toBase58()}`);
const authority = nftData.authorities[0];
const authorityAddress = typeof authority === 'string' ? authority : authority.address;
console.log(`${authorityAddress} == ${nftAuthority[0].toBase58()}`);

if (nftData.authorities[0].address === nftAuthority[0].toBase58()) {
if (authorityAddress === nftAuthority[0].toBase58()) {
nft = nftData;
}
console.log('NFT data', nftData);
Expand All @@ -109,7 +122,9 @@ const ChopTreeButton = () => {
return;
}
try {
console.log('NFTid', nft.id, 'NFT authority', nft.authorities[0].address);
const nftAuthorityAddress =
typeof nft.authorities[0] === 'string' ? nft.authorities[0] : nft.authorities[0].address;
console.log('NFTid', nft.id, 'NFT authority', nftAuthorityAddress);
const transaction = await program.methods
.chopTree(GAME_DATA_SEED, transactionCounter)
.accounts({
Expand All @@ -119,6 +134,7 @@ const ChopTreeButton = () => {
sessionToken: null,
nftAuthority: nftAuthority[0].toBase58(),
mint: nft.id,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_2022_PROGRAM_ID,
})
.transaction();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Button, HStack, VStack } from '@chakra-ui/react';
import { web3 } from '@coral-xyz/anchor';
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { Keypair, PublicKey, SystemProgram } from '@solana/web3.js';
import { Keypair, PublicKey, SYSVAR_RENT_PUBKEY, SystemProgram } from '@solana/web3.js';
import Image from 'next/image';
import { useCallback, useState } from 'react';
import { useGameState } from '@/contexts/GameStateProvider';
Expand Down Expand Up @@ -39,7 +38,7 @@ const MintNftButton = () => {
tokenProgram: TOKEN_2022_PROGRAM_ID,
tokenAccount: destinationTokenAccount,
mint: mint.publicKey,
rent: web3.SYSVAR_RENT_PUBKEY,
rent: SYSVAR_RENT_PUBKEY,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
nftAuthority: nftAuthority[0],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button } from '@chakra-ui/react';
import { useSessionWallet } from '@magicblock-labs/gum-react-sdk';
import { useWallet } from '@solana/wallet-adapter-react';
import { LAMPORTS_PER_SOL } from '@solana/web3.js';
Comment thread
dev-jodee marked this conversation as resolved.
import { useState } from 'react';
import { useGameState } from '@/contexts/GameStateProvider';
import { program } from '@/utils/anchor';
Expand All @@ -13,11 +14,11 @@ const SessionKeyButton = () => {

const handleCreateSession = async () => {
setIsLoading(true);
const topUp = true;
const topUpLamports = 0.01 * LAMPORTS_PER_SOL;
const expiryInMinutes = 600;

try {
const session = await sessionWallet.createSession(program.programId, topUp, expiryInMinutes);
const session = await sessionWallet.createSession(program.programId, topUpLamports, expiryInMinutes);
console.log('Session created:', session);
} catch (error) {
console.error('Failed to create session:', error);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BN } from '@coral-xyz/anchor';
import { BN } from '@anchor-lang/core';
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { PublicKey } from '@solana/web3.js';
import { createContext, useContext, useEffect, useState } from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom';
import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react';
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
import { PhantomWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets';
import { SolflareWalletAdapter } from '@solana/wallet-adapter-solflare';
import { clusterApiUrl } from '@solana/web3.js';
import { type FC, type ReactNode, useMemo } from 'react';

Expand Down
18 changes: 18 additions & 0 deletions tokens/token-2022/nft-meta-data-pointer/app/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig, globalIgnores } from 'eslint/config';
import nextVitals from 'eslint-config-next/core-web-vitals';

const eslintConfig = defineConfig([
...nextVitals,
{
rules: {
// Pre-existing pattern: these effects clear stale state before an
// async fetch keyed on a changing wallet/PDA dependency, which this
// rule flags but is not itself buggy. Left as-is by the Next.js
// upgrade rather than restructuring live wallet-data-fetching logic.
'react-hooks/set-state-in-effect': 'off',
},
},
globalIgnores(['node_modules/**', '.next/**', 'out/**', 'build/**', 'next-env.d.ts']),
]);

export default eslintConfig;
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
export type ExtensionNft = {
address: 'H31ofLpWqeAzF2Pg54HSPQGYifJad843tTJg8vCYVoh3';
metadata: {
name: 'extension_nft';
version: '0.1.0';
spec: '0.1.0';
};
version: '0.1.0';
name: 'extension_nft';
instructions: [
{
name: 'initPlayer';
discriminator: [218, 66, 97, 209, 99, 22, 158, 199];
accounts: [
{
name: 'player';
Expand Down Expand Up @@ -35,12 +42,13 @@ export type ExtensionNft = {
},
{
name: 'chopTree';
discriminator: [239, 143, 6, 72, 108, 119, 167, 156];
accounts: [
{
name: 'sessionToken';
isMut: false;
isSigner: false;
isOptional: true;
optional: true;
},
{
name: 'player';
Expand Down Expand Up @@ -91,6 +99,7 @@ export type ExtensionNft = {
},
{
name: 'mintNft';
discriminator: [245, 247, 58, 90, 129, 73, 62, 228];
accounts: [
{
name: 'signer';
Expand Down Expand Up @@ -137,6 +146,20 @@ export type ExtensionNft = {
},
];
accounts: [
{
name: 'nftAuthority';
discriminator: [3, 176, 246, 106, 104, 231, 175, 162];
},
{
name: 'gameData';
discriminator: [193, 17, 100, 157, 52, 32, 121, 71];
},
{
name: 'playerData';
discriminator: [13, 233, 221, 44, 139, 185, 62, 42];
},
];
types: [
{
name: 'nftAuthority';
type: {
Expand All @@ -163,7 +186,7 @@ export type ExtensionNft = {
fields: [
{
name: 'authority';
type: 'publicKey';
type: 'pubkey';
},
{
name: 'name';
Expand Down Expand Up @@ -212,11 +235,18 @@ export type ExtensionNft = {
};

export const IDL: ExtensionNft = {
address: 'H31ofLpWqeAzF2Pg54HSPQGYifJad843tTJg8vCYVoh3',
metadata: {
name: 'extension_nft',
version: '0.1.0',
spec: '0.1.0',
},
version: '0.1.0',
name: 'extension_nft',
instructions: [
{
name: 'initPlayer',
discriminator: [218, 66, 97, 209, 99, 22, 158, 199],
accounts: [
{
name: 'player',
Expand Down Expand Up @@ -248,12 +278,13 @@ export const IDL: ExtensionNft = {
},
{
name: 'chopTree',
discriminator: [239, 143, 6, 72, 108, 119, 167, 156],
accounts: [
{
name: 'sessionToken',
isMut: false,
isSigner: false,
isOptional: true,
optional: true,
},
{
name: 'player',
Expand Down Expand Up @@ -304,6 +335,7 @@ export const IDL: ExtensionNft = {
},
{
name: 'mintNft',
discriminator: [245, 247, 58, 90, 129, 73, 62, 228],
accounts: [
{
name: 'signer',
Expand Down Expand Up @@ -350,6 +382,20 @@ export const IDL: ExtensionNft = {
},
],
accounts: [
{
name: 'nftAuthority',
discriminator: [3, 176, 246, 106, 104, 231, 175, 162],
},
{
name: 'gameData',
discriminator: [193, 17, 100, 157, 52, 32, 121, 71],
},
{
name: 'playerData',
discriminator: [13, 233, 221, 44, 139, 185, 62, 42],
},
],
types: [
{
name: 'nftAuthority',
type: {
Expand All @@ -376,7 +422,7 @@ export const IDL: ExtensionNft = {
fields: [
{
name: 'authority',
type: 'publicKey',
type: 'pubkey',
},
{
name: 'name',
Expand Down
22 changes: 12 additions & 10 deletions tokens/token-2022/nft-meta-data-pointer/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "eslint ."
},
"dependencies": {
"@chakra-ui/next-js": "^2.1.3",
Expand All @@ -20,21 +20,23 @@
"@solana/spl-token": "^0.4.0",
"@solana/wallet-adapter-base": "^0.9.23",
"@solana/wallet-adapter-censo": "^0.1.4",
"@solana/wallet-adapter-phantom": "^0.9.29",
"@solana/wallet-adapter-react": "^0.15.35",
"@solana/wallet-adapter-react-ui": "^0.9.35",
"@solana/wallet-adapter-wallets": "^0.19.26",
"@solana/wallet-adapter-solflare": "^0.6.33",
"@solana/web3.js": "^1.98.4",
"axios": "^1.19.0",
"@types/node": "20.2.5",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"@types/react": "18.3.31",
"@types/react-dom": "18.3.7",
"browserify-sign": ">=4.2.2",
"crypto-js": ">=4.2.0",
"eslint": "8.41.0",
"eslint-config-next": "13.4.4",
"eslint": "^9.39.5",
"eslint-config-next": "16.2.12",
"framer-motion": "^10.12.16",
"next": "13.4.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.0.4"
"next": "16.2.12",
"react": "18.3.1",
"react-dom": "18.3.1",
"typescript": "^5.9.3"
}
}
Loading
Loading