mint WORKING

This commit is contained in:
dr-frmr 2024-08-09 17:57:55 +03:00
parent 8f81279535
commit 6b47043ffd
No known key found for this signature in database
4 changed files with 11 additions and 28 deletions

View File

@ -10,9 +10,6 @@ import KinodeHome from "./pages/KinodeHome"
import ImportKeyfile from "./pages/ImportKeyfile";
import { UnencryptedIdentity } from "./lib/types";
import Header from "./components/Header";
import { bytesToHex } from "viem";
function App() {
const params = useParams()
@ -38,8 +35,6 @@ function App() {
const openConnect = () => setConnectOpen(true)
const closeConnect = () => setConnectOpen(false)
const commitSecret = bytesToHex(crypto.getRandomValues(new Uint8Array(32)))
useEffect(() => setAppSizeOnLoad(
(window.performance.getEntriesByType('navigation') as any)[0].transferSize
), []);
@ -100,7 +95,6 @@ function App() {
tcp_port, setTcpPort,
routers, setRouters,
nodeChainId,
commitSecret,
}
return (

View File

@ -23,7 +23,6 @@ export interface PageProps {
setPw: React.Dispatch<React.SetStateAction<string>>,
appSizeOnLoad: number,
nodeChainId: string,
commitSecret: `0x${string}`,
}
export type NetworkingInfo = {

View File

@ -23,7 +23,6 @@ function CommitDotOsName({
setWsPort,
setTcpPort,
setRouters,
commitSecret,
}: RegisterOsNameProps) {
let { address } = useAccount();
let navigate = useNavigate();
@ -62,18 +61,18 @@ function CommitDotOsName({
return
}
console.log("committing to .os name: ", name)
const commitSecret = keccak256(stringToHex(name))
const commit = keccak256(
encodeAbiParameters(
parseAbiParameters('bytes32, bytes32'),
[keccak256(stringToHex(name)), commitSecret]
)
)
writeContract({
abi: dotOsAbi,
address: DOTOS,
functionName: 'commit',
args: [
keccak256(
encodeAbiParameters(
parseAbiParameters('bytes memory, bytes32'),
[keccak256(stringToHex(name)), commitSecret]
)
)
],
args: [commit],
gas: 1000000n,
})

View File

@ -6,7 +6,7 @@ import { PageProps } from "../lib/types";
import { useAccount, useWaitForTransactionReceipt, useSendTransaction } from "wagmi";
import { useConnectModal, useAddRecentTransaction } from "@rainbow-me/rainbowkit"
import { dotOsAbi, generateNetworkingKeys, KINO_ACCOUNT_IMPL, DOTOS } from "../abis";
import { encodePacked, parseAbi, encodeFunctionData, stringToHex } from "viem";
import { encodePacked, encodeFunctionData, stringToHex, keccak256 } from "viem";
interface RegisterOsNameProps extends PageProps { }
@ -18,7 +18,6 @@ function MintDotOsName({
setWsPort,
setTcpPort,
setRouters,
commitSecret,
}: RegisterOsNameProps) {
let { address } = useAccount();
let navigate = useNavigate();
@ -70,13 +69,10 @@ function MintDotOsName({
// strip .os suffix
const name = knsName.replace(/\.os$/, '');
const abi = parseAbi([
'function mint(address,bytes,bytes,bytes,address,bytes32)',
])
const commitSecret = keccak256(stringToHex(name))
const data = encodeFunctionData({
abi,
abi: dotOsAbi,
functionName: 'mint',
args: [
address,
@ -88,8 +84,6 @@ function MintDotOsName({
],
})
console.log("data: ", data)
// use data to write to contract -- do NOT use writeContract
// writeContract will NOT generate the correct selector for some reason
// probably THEIR bug.. no abi works
@ -99,11 +93,8 @@ function MintDotOsName({
data: data,
gas: 1000000n,
})
console.log('Transaction sent?')
// You might want to add some state management here to track the transaction
} catch (error) {
console.error('Failed to send transaction:', error)
// Handle the error appropriately, maybe set an error state
}
}, [direct, address, sendTransaction, setNetworkingKey, setIpAddress, setWsPort, setTcpPort, setRouters, openConnectModal])