diff --git a/src/renderer/components/CreateTask.tsx b/src/renderer/components/CreateTask.tsx index ac3815d..b952a7c 100644 --- a/src/renderer/components/CreateTask.tsx +++ b/src/renderer/components/CreateTask.tsx @@ -16,16 +16,13 @@ import { } from 'grommet'; import { DocumentText, SettingsOption, Table } from 'grommet-icons'; import { useEffect, useState } from 'react'; -import { create as ipfsHttpClient } from 'ipfs-http-client'; import { createSchema } from 'genson-js/dist'; -import { FLOCK_ABI, FLOCK_ADDRESS } from 'renderer/contracts/flock'; +import { FLOCK_V2_ABI, FLOCK_V2_ADDRESS } from 'renderer/contracts/flockV2'; import { FLOCK_TASK_MANAGER_ABI, FLOCK_TASK_MANAGER_ADDRESS, } from 'renderer/contracts/flockTaskManager'; -const ipfsClient = ipfsHttpClient({ url: 'https://ipfs.flock.io/api/v0' }); - type FormValues = { name: string; description: string; @@ -406,8 +403,8 @@ export function CreateTask({ isError: isErrorApprove, error: errorApprove, } = useContractWrite({ - address: FLOCK_ADDRESS as `0x${string}`, - abi: FLOCK_ABI, + address: FLOCK_V2_ADDRESS as `0x${string}`, + abi: FLOCK_V2_ABI, functionName: 'approve', }); diff --git a/src/renderer/components/Task.tsx b/src/renderer/components/Task.tsx index 6335a9f..6521579 100644 --- a/src/renderer/components/Task.tsx +++ b/src/renderer/components/Task.tsx @@ -37,7 +37,7 @@ import { LogViewer } from '@patternfly/react-log-viewer'; import { RunnerContext } from 'renderer/context/runnerContext'; import { useAccount, useContractWrite, useWaitForTransaction } from 'wagmi'; import { FLOCK_TASK_ABI } from 'renderer/contracts/flockTask'; -import { FLOCK_ABI, FLOCK_ADDRESS } from 'renderer/contracts/flock'; +import { FLOCK_V2_ABI, FLOCK_V2_ADDRESS } from 'renderer/contracts/flockV2'; import { WalletContext } from 'renderer/context/walletContext'; import { useNavigate } from 'react-router-dom'; import { formatUnits } from 'viem'; @@ -100,7 +100,8 @@ function Task({ task, goBack }: TaskProps) { const navigate = useNavigate(); const { address } = useAccount(); - const { nativeTokenBalance, flockTokenBalance } = useContext(WalletContext); + const { nativeTokenBalance, FLCTokenBalance, FLOTokenBalance } = + useContext(WalletContext); const { runningTasks, runTask, logs } = useContext(RunnerContext); const [file, setFile] = useState({} as File); const [step, setStep] = useState('DETAIL'); @@ -165,8 +166,8 @@ function Task({ task, goBack }: TaskProps) { const { data: dataApprove, writeAsync: writeAsyncApprove } = useContractWrite( { - address: FLOCK_ADDRESS as `0x${string}`, - abi: FLOCK_ABI, + address: FLOCK_V2_ADDRESS as `0x${string}`, + abi: FLOCK_V2_ABI, functionName: 'approve', } ); @@ -471,7 +472,7 @@ function Task({ task, goBack }: TaskProps) { )} {Number(nativeTokenBalance?.value) !== 0 && - Number(flockTokenBalance?.value) === 0 && ( + Number(FLCTokenBalance?.value) === 0 && ( diff --git a/src/renderer/components/Wallet.tsx b/src/renderer/components/Wallet.tsx index 8b2640e..1c69348 100644 --- a/src/renderer/components/Wallet.tsx +++ b/src/renderer/components/Wallet.tsx @@ -17,7 +17,7 @@ import { useContractWrite, useWaitForTransaction, } from 'wagmi'; -import { FLOCK_ABI, FLOCK_ADDRESS } from 'renderer/contracts/flock'; +import { FLOCK_V2_ABI, FLOCK_V2_ADDRESS } from 'renderer/contracts/flockV2'; import { ToastContainer, toast } from 'react-toastify'; import { web3AuthInstance } from '../Web3AuthInstance'; import 'react-toastify/dist/ReactToastify.css'; @@ -33,7 +33,8 @@ function Wallet() { const { connectAsync, connectors, pendingConnector, isSuccess } = useConnect(); const { disconnect: wagmiDisconnect } = useDisconnect(); - const { nativeTokenBalance, flockTokenBalance } = useContext(WalletContext); + const { nativeTokenBalance, FLCTokenBalance, FLOTokenBalance } = + useContext(WalletContext); const [privateKey, setPrivateKey] = useState(''); const [userEmail, setUserEmail] = useState(''); const [showEmailImport, setShowEmailImport] = useState(false); @@ -162,8 +163,8 @@ function Wallet() { const { data: dataTransfer, writeAsync: writeAsyncApprove } = useContractWrite({ - address: FLOCK_ADDRESS as `0x${string}`, - abi: FLOCK_ABI, + address: FLOCK_V2_ADDRESS as `0x${string}`, + abi: FLOCK_V2_ABI, functionName: 'transfer', }); @@ -178,8 +179,12 @@ function Wallet() { }); }; - const roundedFLCBalance = flockTokenBalance - ? Math.round(Number(flockTokenBalance.formatted) * 100) / 100 + const roundedFLCBalance = FLCTokenBalance + ? Math.round(Number(FLCTokenBalance.formatted) * 100) / 100 + : 0; + + const roundedFLOBalance = FLOTokenBalance + ? Math.round(Number(FLOTokenBalance.formatted) * 100) / 100 : 0; const roundedMaticBalance = nativeTokenBalance @@ -215,6 +220,10 @@ function Wallet() { Wallet Address: {address} + + FLock(FLO) Balance: + {roundedFLOBalance} $F + FLock(FLC) Balance: {roundedFLCBalance} $F @@ -225,7 +234,7 @@ function Wallet() { - Transfer FLC tokens + Transfer FLO tokens ({ nativeTokenBalance, - flockTokenBalance, + FLCTokenBalance, + FLOTokenBalance, }), - [nativeTokenBalance, flockTokenBalance] + [nativeTokenBalance, FLCTokenBalance, FLOTokenBalance] ); return ( diff --git a/src/renderer/contracts/flockV2.ts b/src/renderer/contracts/flockV2.ts new file mode 100644 index 0000000..84b0338 --- /dev/null +++ b/src/renderer/contracts/flockV2.ts @@ -0,0 +1,366 @@ +export const FLOCK_V2_ADDRESS = '0x45Ef45b77199a48416330d1e461b89a64b4a3CA4'; +export const FLOCK_V2_ABI = [ + { + inputs: [], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + ], + name: 'allowance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_account', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'burn', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'decimals', + outputs: [ + { + internalType: 'uint8', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'subtractedValue', + type: 'uint256', + }, + ], + name: 'decreaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'addedValue', + type: 'uint256', + }, + ], + name: 'increaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_account', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'mint', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'symbol', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transfer', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +]; diff --git a/src/renderer/contracts/migrateTokens.ts b/src/renderer/contracts/migrateTokens.ts new file mode 100644 index 0000000..2b61edf --- /dev/null +++ b/src/renderer/contracts/migrateTokens.ts @@ -0,0 +1,87 @@ +export const MIGRATE_TOKENS_ADDRESS = + '0x1f808c9d65D992f822Ab1Fc33cc76Cda7334687c'; + +export const MIGRATE_TOKENS_ABI = [ + { + inputs: [ + { + internalType: 'address', + name: '_oldTokenAddress', + type: 'address', + }, + { + internalType: 'address', + name: '_newTokenAddress', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + inputs: [], + name: 'migrate', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'withdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +]; diff --git a/src/renderer/pages/Faucet.tsx b/src/renderer/pages/Faucet.tsx index 82e7313..535e2e8 100644 --- a/src/renderer/pages/Faucet.tsx +++ b/src/renderer/pages/Faucet.tsx @@ -1,78 +1,87 @@ -import { - Box, - Button, - Form, - FormField, - Heading, - Paragraph, - TextInput, -} from 'grommet'; +import { Box, Button, Heading, Paragraph } from 'grommet'; +import { useEffect, useState, useContext } from 'react'; import { useAccount, useContractWrite, useWaitForTransaction } from 'wagmi'; -import { useEffect, useState } from 'react'; import Layout from 'renderer/components/Layout'; -import { ToastContainer, toast } from 'react-toastify'; -import 'react-toastify/dist/ReactToastify.css'; import { FLOCK_ABI, FLOCK_ADDRESS } from '../contracts/flock'; +import { + MIGRATE_TOKENS_ABI, + MIGRATE_TOKENS_ADDRESS, +} from '../contracts/migrateTokens'; +import { WalletContext } from '../context/walletContext'; -export default function Faucet() { +export default function FaucetPage() { const { address } = useAccount(); - const [amount, setAmount] = useState(0); const [errors, setErrors] = useState({}); + const [disabled, setDisabled] = useState(true); + const [isLoading, setIsLoading] = useState(false); + const { FLCTokenBalance } = useContext(WalletContext); + + const { data: dataMigrate, write: writeMigrate } = useContractWrite({ + address: MIGRATE_TOKENS_ADDRESS as `0x${string}`, + abi: MIGRATE_TOKENS_ABI, + functionName: 'migrate', + }); - const { data, write } = useContractWrite({ + const { data: dataApprove, write: writeApprove } = useContractWrite({ address: FLOCK_ADDRESS as `0x${string}`, abi: FLOCK_ABI, - functionName: 'mint', + functionName: 'approve', }); - const { isSuccess, isLoading } = useWaitForTransaction({ - hash: data?.hash, + const { isSuccess: isSuccessMigrate } = useWaitForTransaction({ + hash: dataMigrate?.hash, }); - const handleMint = async () => { - write?.({ args: [address, amount * 10 ** 18] }); + const { isSuccess: isSuccessApprove } = useWaitForTransaction({ + hash: dataApprove?.hash, + }); + + const handleApprove = async () => { + setIsLoading(true); + writeApprove?.({ + args: [MIGRATE_TOKENS_ADDRESS as `0x${string}`, FLCTokenBalance.value], + }); }; useEffect(() => { - if (isSuccess) { - toast.success(`Minted ${amount} FLC successfully`); + if (isSuccessApprove) { + writeMigrate?.(); } - setAmount(0); - }, [isSuccess]); + if (isSuccessMigrate) { + setIsLoading(false); + } + }, [isSuccessApprove, isSuccessMigrate]); const hasErrors = Object.keys(errors).length > 0; + useEffect(() => { + setDisabled(!address || hasErrors || isLoading); + }, [address, isLoading]); + + const roundedFLCBalance = FLCTokenBalance + ? Math.round(Number(FLCTokenBalance.formatted) * 100) / 100 + : 0; + return ( - + - - FLock (FLC) tokens faucet + + FLock (FLO) tokens faucet - Mint your FLC tokens for participating in the FLock network. + Migrate your FLC to FLO tokens for participating in the FLock network. - Contract Address: {FLOCK_ADDRESS} - - - {`To get testnet MATIC on Polygon Mumbai network visit this `} - - link - + {roundedFLCBalance} FLC tokens available to migrate. @@ -84,49 +93,16 @@ export default function Faucet() { justify="center" round="small" > -
{ - setErrors(validationResults.errors); - }} - > - - setAmount(e.target.value)} - /> - - -