generated from theodorusclarence/ts-nextjs-tailwind-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34f9acc
commit 5aa7b40
Showing
15 changed files
with
296 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/GlobalRedux/Features/kernalClient/kernalClientSlice.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use client'; | ||
|
||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
export const kernalClientSlice = createSlice({ | ||
name: 'kernalClient', | ||
initialState: { | ||
value: {}, | ||
}, | ||
reducers: { | ||
kernalClient: (state, action) => { | ||
state.value = action.payload; | ||
}, | ||
}, | ||
}); | ||
export const { kernalClient } = kernalClientSlice.actions; | ||
export default kernalClientSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
'use client' | ||
'use client'; | ||
|
||
import { createSlice } from "@reduxjs/toolkit" | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
export const loginSlice = createSlice({ | ||
name: "login", | ||
initialState: { | ||
value: false, | ||
name: 'login', | ||
initialState: { | ||
value: false, | ||
}, | ||
reducers: { | ||
login: (state) => { | ||
state.value = true; | ||
}, | ||
reducers: { | ||
login: (state) => { | ||
state.value = true | ||
}, | ||
logout: (state) => { | ||
state.value = false | ||
}, | ||
logout: (state) => { | ||
state.value = false; | ||
}, | ||
}, | ||
}); | ||
export const { login, logout } = loginSlice.actions; | ||
export default loginSlice.reducer; | ||
export default loginSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Wagmi | ||
import { erc20ABI, useWaitForTransaction } from "wagmi"; | ||
|
||
// ZeroDev | ||
import { usePrepareSendUserOperation, useSendUserOperation } from "@zerodev/wagmi"; | ||
|
||
// Viem | ||
import { encodeFunctionData, parseUnits } from "viem"; | ||
import { useRouter } from "next/router"; | ||
|
||
export default function SendUsdc() { | ||
|
||
const router = useRouter(); | ||
|
||
const { payee } = router.query; | ||
|
||
// USDC contract address | ||
const usdc = "0x9999f7Fea5938fD3b1E26A12c3f2fb024e194f97"; | ||
|
||
// Encode the data with Viem Function | ||
// Requires the abi of the contract, the function name, and the arguments address and amount | ||
const encoded = encodeFunctionData({ | ||
abi: erc20ABI, | ||
functionName: "transfer", | ||
args: [payee as `0x${string}`, parseUnits("1", 6)], | ||
}); | ||
|
||
// Prepare the transaction with Wagmi | ||
const { config } = usePrepareSendUserOperation({ | ||
to: usdc, | ||
data: encoded, | ||
}); | ||
// Send the transaction with Wagmi | ||
const { sendUserOperation, data } = useSendUserOperation(config); | ||
|
||
// Wait for the transaction executed | ||
useWaitForTransaction({ | ||
hash: data?.hash, | ||
enabled: !!data, | ||
onSuccess(data) { | ||
console.log("Transaction was successful."); | ||
}, | ||
}); | ||
|
||
// Send transaction function | ||
const sendTx = async () => { | ||
try { | ||
// check if the operation exists | ||
sendUserOperation && sendUserOperation(); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
return ( | ||
<button | ||
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" | ||
onClick={() => sendTx()} | ||
> | ||
Send USDC to { payee } | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,61 @@ | ||
// Wagmi | ||
import { erc20ABI, useWaitForTransaction } from "wagmi"; | ||
import { erc20ABI, useWaitForTransaction } from 'wagmi'; | ||
|
||
// ZeroDev | ||
import { usePrepareSendUserOperation, useSendUserOperation } from "@zerodev/wagmi"; | ||
import { | ||
usePrepareSendUserOperation, | ||
useSendUserOperation, | ||
} from '@zerodev/wagmi'; | ||
|
||
// Viem | ||
import { encodeFunctionData, parseUnits } from "viem"; | ||
import { useRouter } from "next/router"; | ||
|
||
export default function SendUsdc() { | ||
|
||
const router = useRouter(); | ||
|
||
const { payee } = router.query; | ||
|
||
// USDC contract address | ||
const usdc = "0x9999f7Fea5938fD3b1E26A12c3f2fb024e194f97"; | ||
|
||
// Encode the data with Viem Function | ||
// Requires the abi of the contract, the function name, and the arguments address and amount | ||
const encoded = encodeFunctionData({ | ||
abi: erc20ABI, | ||
functionName: "transfer", | ||
args: [payee as `0x${string}`, parseUnits("1", 6)], | ||
}); | ||
|
||
// Prepare the transaction with Wagmi | ||
const { config } = usePrepareSendUserOperation({ | ||
to: usdc, | ||
data: encoded, | ||
}); | ||
// Send the transaction with Wagmi | ||
const { sendUserOperation, data } = useSendUserOperation(config); | ||
|
||
// Wait for the transaction executed | ||
useWaitForTransaction({ | ||
hash: data?.hash, | ||
enabled: !!data, | ||
onSuccess(data) { | ||
console.log("Transaction was successful."); | ||
}, | ||
}); | ||
|
||
// Send transaction function | ||
const sendTx = async () => { | ||
try { | ||
// check if the operation exists | ||
sendUserOperation && sendUserOperation(); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
return ( | ||
<button | ||
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" | ||
onClick={() => sendTx()} | ||
> | ||
Send USDC to { payee } | ||
</button> | ||
); | ||
} | ||
import { encodeFunctionData, parseUnits } from 'viem'; | ||
import { useRouter } from 'next/router'; | ||
|
||
export default async async function SendUsdc() { | ||
const router = useRouter(); | ||
|
||
const { payee } = router.query; | ||
|
||
// USDC contract address | ||
const usdc = '0x9999f7Fea5938fD3b1E26A12c3f2fb024e194f97'; | ||
|
||
// Encode the data with Viem Function | ||
// Requires the abi of the contract, the function name, and the arguments address and amount | ||
const encoded = encodeFunctionData({ | ||
abi: erc20ABI, | ||
functionName: 'transfer', | ||
args: [payee as `0x${string}`, parseUnits('1', 6)], | ||
}); | ||
|
||
const userOpHash = kernelClient.sendUserOperation({ | ||
userOperation: { | ||
callData: await kernelClient.account.encodeCallData({ | ||
to: contractAddress, | ||
value: BigInt(0), | ||
data: encodeFunctionData({ | ||
abi: contractABI, | ||
functionName: 'mint', | ||
args: [accountAddress], | ||
}), | ||
}), | ||
}, | ||
}); | ||
|
||
// Send transaction function | ||
const sendTx = async () => { | ||
try { | ||
// check if the operation exists | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
return ( | ||
<button | ||
className='rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700' | ||
onClick={() => sendTx()} | ||
> | ||
Send USDC to {payee} | ||
</button> | ||
); | ||
} |
Oops, something went wrong.