Skip to content

Commit 0b9b15c

Browse files
Copilot0xrinegade
andcommitted
Fix critical SPL token imports and remove remaining fake data generation
Co-authored-by: 0xrinegade <[email protected]>
1 parent 4298a3c commit 0b9b15c

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

src/utils/rewardTransactions.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -278,20 +278,8 @@ export const claimRewards = async (wallet, connection, userPublicKey, options =
278278
}
279279

280280
if (!web3 || !PublicKey) {
281-
// Mock implementation for test environment with enhanced cooldown
282-
return new Promise((resolve, reject) => {
283-
setTimeout(() => {
284-
// Simulate 10% chance of failure for demonstration
285-
if (Math.random() < 0.1) {
286-
setFailedClaimCooldown(userPublicKey);
287-
reject(new Error('Simulated transaction failure: Network congestion'));
288-
} else {
289-
// Set cooldown for successful mock claim
290-
setClaimCooldown(userPublicKey);
291-
resolve('mock_transaction_signature_' + Date.now());
292-
}
293-
}, 2000);
294-
});
281+
// Real blockchain environment required - no mock data
282+
throw new Error('Web3 connection required for claiming rewards');
295283
}
296284

297285
const operation = async () => {
@@ -354,8 +342,8 @@ export const createUserRewardsAccount = async (wallet, connection, userPublicKey
354342
const { retryConfig = {} } = options;
355343

356344
if (!web3 || !PublicKey) {
357-
// Mock implementation
358-
return Promise.resolve('mock_create_account_signature_' + Date.now());
345+
// Real blockchain environment required - no mock data
346+
throw new Error('Web3 connection required for creating user rewards account');
359347
}
360348

361349
const operation = async () => {
@@ -409,8 +397,8 @@ export const hasUserRewardsAccount = async (
409397
const { retryConfig = {} } = options;
410398

411399
if (!web3 || !PublicKey) {
412-
// Mock implementation - randomly return true/false
413-
return Math.random() > 0.5;
400+
// Real blockchain environment required - no mock data
401+
throw new Error('Web3 connection required for checking user rewards account');
414402
}
415403

416404
const operation = async () => {

src/utils/transactionCPI.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { Transaction, SystemProgram, PublicKey } from '@solana/web3.js';
9-
import { getAssociatedTokenAddress, createAssociatedTokenAccountInstruction, TOKEN_PROGRAM_ID } from '@solana/spl-token';
9+
import { TOKEN_PROGRAM_ID, Token, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
1010
import { createLogger } from './logger';
1111

1212
const logger = createLogger('TransactionCPI');
@@ -68,7 +68,12 @@ const ACCOUNT_DERIVATION = {
6868
* @returns {Promise<PublicKey>} Associated token account address
6969
*/
7070
getAssociatedTokenAccount: async (mint, owner) => {
71-
return await getAssociatedTokenAddress(mint, owner);
71+
return await Token.getAssociatedTokenAddress(
72+
ASSOCIATED_TOKEN_PROGRAM_ID,
73+
TOKEN_PROGRAM_ID,
74+
mint,
75+
owner
76+
);
7277
}
7378
};
7479

@@ -251,11 +256,13 @@ export class TransactionBuilder {
251256
}
252257
}
253258

254-
const instruction = createAssociatedTokenAccountInstruction(
255-
payer, // payer
259+
const instruction = Token.createAssociatedTokenAccountInstruction(
260+
ASSOCIATED_TOKEN_PROGRAM_ID,
261+
TOKEN_PROGRAM_ID,
262+
mint, // mint
256263
tokenAccount, // ata
257-
owner, // owner
258-
mint // mint
264+
owner, // owner
265+
payer // payer
259266
);
260267

261268
this.transaction.add(instruction);

0 commit comments

Comments
 (0)