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

Fix select sc address #19

Merged
merged 6 commits into from
Sep 5, 2024
Merged
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
4 changes: 2 additions & 2 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# buildnet config:
VITE_SC_ADDRESS=AS14oUcMujECzburUs8iMZZGsJQQQ61MxPVUKyV8WUNrw3mHmSqF
VITE_MAINNET_SC_ADDRESS=AS1q5hUfxLXNXLKsYQVXZLK7MPUZcWaNZZsK7e9QzqhGdAgLpUGT
VITE_BUILDNET_SC_ADDRESS=AS12qKAVjU1nr66JSkQ6N4Lqu4iwuVc6rAbRTrxFoynPrPdP1sj3G
VITE_OP_FEES=10000000 # value in nMAS
7 changes: 4 additions & 3 deletions frontend/src/components/MNSManagement.tsx
Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@

export function MNSManagement(props: MNSManagementProps) {
const { customClass } = props;
const { massaClient, connectedAccount, currentProvider } = useAccountStore();
const { massaClient, connectedAccount, currentProvider, chainId } =
useAccountStore();
const {
list,
listSpinning,
@@ -25,9 +26,9 @@
const connected = !!connectedAccount && !!currentProvider;

useEffect(() => {
if (!connectedAccount || !massaClient || listSpinning) return;
if (!connectedAccount || !massaClient || listSpinning || !chainId) return;
getUserEntryList({ address: connectedAccount.address() });
}, [connectedAccount, massaClient]);
}, [connectedAccount, massaClient, chainId]);

Check warning on line 31 in frontend/src/components/MNSManagement.tsx

GitHub Actions / lint-frontend

React Hook useEffect has missing dependencies: 'getUserEntryList' and 'listSpinning'. Either include them or remove the dependency array
return (
<div className={customClass}>
{!connected ? (
4 changes: 3 additions & 1 deletion frontend/src/const/sc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { fromMAS } from '@massalabs/massa-web3';

export const SC_ADDRESS = import.meta.env.VITE_SC_ADDRESS;
export const MAINNET_SC_ADDRESS = import.meta.env.VITE_MAINNET_SC_ADDRESS;
export const BUILDNET_SC_ADDRESS = import.meta.env.VITE_BUILDNET_SC_ADDRESS;

export const VESTING_SESSION_STORAGE_COST = fromMAS(2);
let defaultOpFees: bigint;
try {
27 changes: 26 additions & 1 deletion frontend/src/utils/write-mns-sc.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Args,
CHAIN_ID,
Client,
EOperationStatus,
ICallData,
@@ -10,10 +11,15 @@ import {
} from '@massalabs/massa-web3';
import { ToastContent, toast } from '@massalabs/react-ui-kit';
import { useState } from 'react';
import { DEFAULT_OP_FEES, SC_ADDRESS } from '../const/sc';
import {
DEFAULT_OP_FEES,
MAINNET_SC_ADDRESS,
BUILDNET_SC_ADDRESS,
} from '../const/sc';
import { OperationToast } from '../lib/connectMassaWallets/components/OperationToast';
import { logSmartContractEvents } from '../lib/connectMassaWallets/utils';
import { ExplorerApiClient } from '../ExplorerApiClient';
import { useAccountStore } from '../lib/connectMassaWallets/store';

interface ToasterMessage {
pending: string;
@@ -67,6 +73,18 @@ type callSmartContractOptions = {
function minBigInt(a: bigint, b: bigint) {
return a < b ? a : b;
}

function getScAddress(chainId: bigint | undefined) {
switch (chainId) {
case CHAIN_ID.BuildNet:
return BUILDNET_SC_ADDRESS;
case CHAIN_ID.MainNet:
return MAINNET_SC_ADDRESS;
default:
throw new Error('SC_ADDRESS not found for chainId : ' + chainId);
}
}

export function useWriteMNS(client?: Client) {
const [isPending, setIsPending] = useState(false);
const [isSuccess, setIsSuccess] = useState(false);
@@ -75,10 +93,13 @@ export function useWriteMNS(client?: Client) {
const [list, setList] = useState<DnsUserEntryListResult[]>([]);
const [listSpinning, setListSpinning] = useState(false);
const explorerApi = new ExplorerApiClient();
const { chainId } = useAccountStore();

async function getAllocCost(
params: DnsAllocParams,
): Promise<DnsGetAllocCostResponse> {
const SC_ADDRESS = getScAddress(chainId);

let price = 0n;
try {
let args = new Args();
@@ -182,6 +203,8 @@ export function useWriteMNS(client?: Client) {
let operationId: string | undefined;
let toastId: string | undefined;

const SC_ADDRESS = getScAddress(chainId);

const callData = {
targetAddress: SC_ADDRESS,
targetFunction,
@@ -314,6 +337,8 @@ export function useWriteMNS(client?: Client) {
params: DnsUserEntryListParams,
): Promise<DnsUserEntryListResult[]> {
setListSpinning(true);
const SC_ADDRESS = getScAddress(chainId);

let resultBalance = await client?.smartContracts().readSmartContract({
targetAddress: SC_ADDRESS,
targetFunction: 'balanceOf',