Skip to content

Commit

Permalink
Monkeys strong together: temporary patch
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoistP committed Aug 26, 2024
1 parent 4df4582 commit 65fb43e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
34 changes: 33 additions & 1 deletion app/helpers/mplx.helper.dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,43 @@ import { I_ExpectedCandyMachineState, mplhelp_T_AirdropResult, mplhelp_T_CreateC
} from "types";
import { checkBalance, setIdentityPayer_APP, setIdentityPayer_WalletAdapter } from "./mplx.helper.common.dynamic";

// Monkey patch the Connection prototype until UMI library is updated
import { Connection } from "@solana/web3.js";

const filePath = "app/helpers/mplx.helpers.ts"

// ------------------------------------------------------------

const mplx_umi: MPL_T_Umi = MPL_F_createUmi(RPC_URL).use(mplCoreCandyMachine());
// Monkey patch the Connection prototype until UMI library is updated
Connection.prototype.getRecentBlockhash = async function (commitment) {
try {
const { blockhash, lastValidBlockHeight } =
await this.getLatestBlockhash(commitment);
const recentPrioritizationFees = await this.getRecentPrioritizationFees();
const averageFee =
recentPrioritizationFees.length > 0
? recentPrioritizationFees.reduce(
(sum, fee) => sum + fee.prioritizationFee,
0
) / recentPrioritizationFees.length
: 5000;

return {
blockhash,
feeCalculator: {
lamportsPerSignature: averageFee
}
};
} catch (e) {
throw new Error('failed to get recent blockhash: ' + e);
}
};
// Monkey patch the Connection prototype until UMI library is updated
const mplxHelperDynamicConnection = new Connection(RPC_URL || "", "confirmed");

// const mplx_umi: MPL_T_Umi = MPL_F_createUmi(RPC_URL).use(mplCoreCandyMachine());
const mplx_umi: MPL_T_Umi = MPL_F_createUmi(mplxHelperDynamicConnection).use(mplCoreCandyMachine());

if (!mplx_umi) {
throw new Error('mplx_umi not found')
}
Expand Down
45 changes: 42 additions & 3 deletions app/helpers/mplx.storage.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
import { irysUploader } from '@metaplex-foundation/umi-uploader-irys'
import { MPL_F_createGenericFileFromBrowserFile } from '@imports/mtplx.storage.imports';

const filePath = "app/helpers/mplx.storage.helpers.ts"
// Monkey patch the Connection prototype until UMI library is updated
import { Connection } from "@solana/web3.js";

// const filePath = "app/helpers/mplx.storage.helpers.ts"

// --------------------------------------------------

Expand All @@ -17,9 +20,45 @@ if (!token) {
throw new Error('NFT_STORAGE_API_KEY not found')
}

// const mplx_umi_storage: MPL_T_Umi =
// createUmi(PUBLIC_STORAGE_RPC_URL).use(nftStorageUploader({
// token: process.env.NEXT_PUBLIC_NFT_STORAGE_KEY||"", }))

// Monkey patch the Connection prototype until UMI library is updated
Connection.prototype.getRecentBlockhash = async function (commitment) {
try {
const { blockhash, lastValidBlockHeight } =
await this.getLatestBlockhash(commitment);
const recentPrioritizationFees = await this.getRecentPrioritizationFees();
const averageFee =
recentPrioritizationFees.length > 0
? recentPrioritizationFees.reduce(
(sum, fee) => sum + fee.prioritizationFee,
0
) / recentPrioritizationFees.length
: 5000;

return {
blockhash,
feeCalculator: {
lamportsPerSignature: averageFee
}
};
} catch (e) {
throw new Error('failed to get recent blockhash: ' + e);
}
};

// Monkey patch the Connection prototype until UMI library is updated
const mplxStorageHelperConnection = new Connection(PUBLIC_STORAGE_RPC_URL || "", "confirmed");

const mplx_umi_storage: MPL_T_Umi =
createUmi(PUBLIC_STORAGE_RPC_URL).use(nftStorageUploader({
token: process.env.NEXT_PUBLIC_NFT_STORAGE_KEY||"", }))
// Monkey patch the Connection prototype until UMI library is updated
// createUmi(PUBLIC_STORAGE_RPC_URL)
createUmi(mplxStorageHelperConnection)
.use(nftStorageUploader({
token: process.env.NEXT_PUBLIC_NFT_STORAGE_KEY||"", }))

if (!mplx_umi_storage) {
throw new Error('mplx_umi_storage not found')
}
Expand Down

0 comments on commit 65fb43e

Please sign in to comment.