Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load minter with v4 client #187

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 12 additions & 8 deletions src/lib/deploy-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
} from "./jetton-minter";
import { readJettonMetadata, changeAdminBody, JettonMetaDataKeys } from "./jetton-minter";
import { getClient } from "./get-ton-client";
import { cellToAddress, makeGetCall } from "./make-get-call";
import { cellToAddress, makeGetCall, makeGetCall4 } from "./make-get-call";
import { SendTransactionRequest, TonConnectUI } from "@tonconnect/ui-react";
import { getClient4 } from "./get-ton-client-4";

export const JETTON_DEPLOY_GAS = toNano(0.25);

Expand Down Expand Up @@ -211,16 +212,19 @@ class JettonDeployController {

async getJettonDetails(contractAddr: Address, owner: Address) {
const tc = await getClient();
const minter = await makeGetCall(
const tc4 = await getClient4();
const minter = await makeGetCall4(
contractAddr,
"get_jetton_data",
[],
async ([totalSupply, __, adminCell, contentCell]) => ({
...(await readJettonMetadata(contentCell as unknown as Cell)),
admin: cellToAddress(adminCell),
totalSupply: totalSupply as BN,
}),
tc,
async ([totalSupply, __, adminCell, contentCell]) => {
return {
...(await readJettonMetadata(contentCell as unknown as Cell)),
admin: cellToAddress(adminCell),
totalSupply: totalSupply as BN,
};
},
tc4,
);

const jWalletAddress = await makeGetCall(
Expand Down
23 changes: 23 additions & 0 deletions src/lib/get-ton-client-4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { TonClient4 } from "ton";
import { getHttpV4Endpoint } from "@orbs-network/ton-access";
import { getNetwork } from "./hooks/useNetwork";

const endpointP = getHttpV4Endpoint({
network: getNetwork(new URLSearchParams(window.location.search)),
});

async function _getClient() {
return new TonClient4({
endpoint: await endpointP,
});
}

const clientP = _getClient();

export async function getClient4() {
return clientP;
}

export async function getEndpoint4() {
return endpointP;
}
18 changes: 17 additions & 1 deletion src/lib/make-get-call.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Cell, TonClient } from "ton";
import { Address, Cell, TonClient, TonClient4 } from "ton";
import BN from "bn.js";

function _prepareParams(params: any[] = []) {
Expand Down Expand Up @@ -49,3 +49,19 @@ export async function makeGetCall<T>(

return parser(_parseGetMethodCall(stack as [["num" | "cell", any]]));
}

export async function makeGetCall4<T>(
address: Address | undefined,
name: string,
params: any[],
parser: (stack: GetResponseValue[]) => T,
tonClient: TonClient4,
) {
const {
last: { seqno },
} = await tonClient.getLastBlock();
const res = await tonClient.runMethod(seqno, address!, name, params);

// @ts-ignore
return parser(res.result.map(({ value, cell }) => value ?? cell));
}
1 change: 1 addition & 0 deletions src/pages/deployer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function DeployerPage() {
if (err instanceof Error) {
showNotification(<>{err.message}</>, "error");
}
console.error(err);
} finally {
setIsLoading(false);
}
Expand Down
1 change: 1 addition & 0 deletions src/store/jetton-store/useJettonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function useJettonStore() {
: error.message,
"error",
);
console.error(error);
}
} finally {
setState((prevState) => ({
Expand Down
Loading