Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Jul 2, 2024
1 parent bc76060 commit 43e88fe
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 187 deletions.
146 changes: 73 additions & 73 deletions src/components/Modules/CreateDanSession.tsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
import {
DEFAULT_SESSION_KEY_MANAGER_MODULE,
type DanModuleInfo,
PaymasterMode,
type Session,
SessionLocalStorage,
type Transaction,
createDANSessionKeyManagerModule,
createERC20SessionDatum,
getDANSessionKey,
type DanModuleInfo,
} from "@biconomy/account";
import { bigIntReplacer, useSmartAccount } from "@biconomy/use-aa";
import { makeStyles } from "@mui/styles";
import type React from "react";
import { useState } from "react";
import { ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import { type Hex, encodeAbiParameters, parseUnits } from "viem";
import { useAccount } from "wagmi";
import Button from "../Button";
import UseDanSession from "./UseDanSession";

import { configInfo } from "../../utils";
getDANSessionKey
} from "@biconomy/account"
import { bigIntReplacer, useSmartAccount } from "@biconomy/use-aa"
import { makeStyles } from "@mui/styles"
import type React from "react"
import { useState } from "react"
import { ToastContainer } from "react-toastify"
import "react-toastify/dist/ReactToastify.css"
import { type Hex, encodeAbiParameters, parseUnits } from "viem"
import { useAccount } from "wagmi"
import Button from "../Button"
import UseDanSession from "./UseDanSession"

import { configInfo } from "../../utils"

const CreateDanSession: React.FC = () => {
const classes = useStyles();
const token = configInfo.usdc.address as Hex;
const amount = parseUnits("50".toString(), 6);
const classes = useStyles()
const token = configInfo.usdc.address as Hex
const amount = parseUnits("50".toString(), 6)

const { address: eoa } = useAccount();
const { smartAccountAddress, smartAccountClient } = useSmartAccount();
const [session, setSession] = useState<Session | null>(null);
const { address: eoa } = useAccount()
const { smartAccountAddress, smartAccountClient } = useSmartAccount()
const [session, setSession] = useState<Session | null>(null)
const [danModuleInfo, setDanModuleInfo] = useState<
undefined | DanModuleInfo
>();
>()

const policy: any[] = [
{ interval: { validAfter: 0, validUntil: 0 } },
"{SESSION_KEY}",
token,
eoa!,
parseUnits("50".toString(), 6),
];
parseUnits("50".toString(), 6)
]

const createDanSessionHandler = async () => {
try {
if (!smartAccountClient || !smartAccountAddress) {
throw new Error("Smart Account not found");
throw new Error("Smart Account not found")
}
console.log(
"use",
smartAccountClient,
"address: ",
smartAccountAddress,
"to create the session"
);
)

const {
sessionKeyEOA,
mpcKeyId,
ephSK,
partiesNumber,
threshold,
eoaAddress,
} = await getDANSessionKey(smartAccountClient);
eoaAddress
} = await getDANSessionKey(smartAccountClient)

setDanModuleInfo({
mpcKeyId,
ephSK,
partiesNumber,
threshold,
eoaAddress,
chainId: 80002,
});
chainId: 80002
})

const sessionStorageClient = new SessionLocalStorage(smartAccountAddress);
const sessionStorageClient = new SessionLocalStorage(smartAccountAddress)

const sessionsModule = await createDANSessionKeyManagerModule({
smartAccountAddress,
sessionStorageClient,
});
sessionStorageClient
})

console.log("session module");
console.log(sessionsModule);
console.log("session module")
console.log(sessionsModule)

const createSessionDataParams = createERC20SessionDatum({
interval: { validAfter: 0, validUntil: 0 },
Expand All @@ -91,73 +91,73 @@ const CreateDanSession: React.FC = () => {
{ type: "address" },
{ type: "address" },
{ type: "address" },
{ type: "uint256" },
{ type: "uint256" }
],
[sessionKeyEOA, token, eoa!, amount]
),
});
)
})

const { data: policyData, sessionIDInfo } =
await sessionsModule.createSessionData([createSessionDataParams]);
await sessionsModule.createSessionData([createSessionDataParams])

console.log("sessionKeyEOA a", sessionKeyEOA, {
matchedLeaf: await sessionStorageClient.getSessionData({
sessionID: sessionIDInfo[0],
}),
});
sessionID: sessionIDInfo[0]
})
})

const permitTx = {
to: DEFAULT_SESSION_KEY_MANAGER_MODULE,
data: policyData,
};
data: policyData
}

const txs: Transaction[] = [];
const txs: Transaction[] = []

const isDeployed = await smartAccountClient.isAccountDeployed();
const isDeployed = await smartAccountClient.isAccountDeployed()
const enableSessionTx = await smartAccountClient.getEnableModuleData(
DEFAULT_SESSION_KEY_MANAGER_MODULE
);
)

if (isDeployed) {
const enabled = await smartAccountClient.isModuleEnabled(
DEFAULT_SESSION_KEY_MANAGER_MODULE
);
)
if (!enabled) {
txs.push(enableSessionTx);
txs.push(enableSessionTx)
}
} else {
txs.push(enableSessionTx);
txs.push(enableSessionTx)
}

txs.push(permitTx);
txs.push(permitTx)

const userOpResponse = await smartAccountClient.sendTransaction(txs, {
paymasterServiceData: { mode: PaymasterMode.SPONSORED },
nonceOptions: {
nonceKey: Date.now(),
},
});
nonceKey: Date.now()
}
})

console.log("userOpResponse", userOpResponse);
console.log("userOpResponse", userOpResponse)

const {
receipt: { transactionHash },
success,
} = await userOpResponse.wait();
success
} = await userOpResponse.wait()

console.log("transactionHash", transactionHash);
console.log("transactionHash", transactionHash)

const resultingSession = {
sessionStorageClient,
sessionIDInfo,
};
sessionIDInfo
}

// Handle Success. Keep the "Session" (StorageClient and sessionIDs) and set it to the session
success && setSession(resultingSession);
success && setSession(resultingSession)
} catch (error) {
console.error("Error creating session:", error);
console.error("Error creating session:", error)
}
};
}

return (
<main className={classes.main}>
Expand Down Expand Up @@ -191,28 +191,28 @@ const CreateDanSession: React.FC = () => {
<Button title="Create Session" onClickFunc={createDanSessionHandler} />
)}
</main>
);
};
)
}

const useStyles = makeStyles(() => ({
main: {
margin: "auto",
padding: "10px 40px",
color: "#EEEEEE",
color: "#EEEEEE"
},
subTitle: {
color: "#FFB999",
fontSize: 36,
margin: 0,
margin: 0
},
h3Title: {
color: "#e6e6e6",
color: "#e6e6e6"
},
listHover: {
"&:hover": {
color: "#FF9551",
},
},
}));
color: "#FF9551"
}
}
}))

export default CreateDanSession;
export default CreateDanSession
Loading

0 comments on commit 43e88fe

Please sign in to comment.