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

Remove faucet #58

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 3 additions & 6 deletions src/renderer/components/CreateTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
});

Expand Down
11 changes: 6 additions & 5 deletions src/renderer/components/Task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<File>({} as File);
const [step, setStep] = useState<STEP>('DETAIL');
Expand Down Expand Up @@ -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',
}
);
Expand Down Expand Up @@ -471,7 +472,7 @@ function Task({ task, goBack }: TaskProps) {
</Layer>
)}
{Number(nativeTokenBalance?.value) !== 0 &&
Number(flockTokenBalance?.value) === 0 && (
Number(FLCTokenBalance?.value) === 0 && (
<Layer modal onEsc={goBack} onClickOutside={goBack}>
<Box pad="large" align="center" gap="medium">
<Alert size="large" />
Expand Down
25 changes: 17 additions & 8 deletions src/renderer/components/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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',
});

Expand All @@ -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
Expand Down Expand Up @@ -215,6 +220,10 @@ function Wallet() {
<Text>
<b>Wallet Address:</b> {address}
</Text>
<Text>
<b>FLock(FLO) Balance: </b>
{roundedFLOBalance} $F
</Text>
<Text>
<b>FLock(FLC) Balance: </b>
{roundedFLCBalance} $F
Expand All @@ -225,7 +234,7 @@ function Wallet() {
</Text>
<Box gap="small" margin={{ top: 'small' }}>
<Text alignSelf="center" weight="bold">
Transfer FLC tokens
Transfer FLO tokens
</Text>
<Box direction="row" gap="small">
<TextInput
Expand Down Expand Up @@ -405,7 +414,7 @@ function Wallet() {
label={
!address
? 'Connect Wallet'
: `(${roundedFLCBalance} $F) ${truncateEthAddress(address)}`
: `(${roundedFLOBalance} $F) ${truncateEthAddress(address)}`
}
onClick={
address
Expand Down
19 changes: 14 additions & 5 deletions src/renderer/context/walletContext.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { ReactNode, createContext, useMemo } from 'react';
import { useAccount, useBalance } from 'wagmi';
import { FLOCK_ADDRESS } from 'renderer/contracts/flock';
import { FLOCK_V2_ADDRESS } from 'renderer/contracts/flockV2';

interface WalletContextProviderProps {
children: ReactNode;
}

interface IWalletContext {
flockTokenBalance: any;
FLCTokenBalance: any;
FLOTokenBalance: any;
nativeTokenBalance: any;
}

Expand All @@ -25,18 +27,25 @@ export function WalletContextProvider({
watch: true,
});

const { data: flockTokenBalance } = useBalance({
const { data: FLCTokenBalance } = useBalance({
address: address as `0x${string}`,
token: FLOCK_ADDRESS,
token: FLOCK_ADDRESS as `0x${string}`,
watch: true,
});

const { data: FLOTokenBalance } = useBalance({
address: address as `0x${string}`,
token: FLOCK_V2_ADDRESS as `0x${string}`,
watch: true,
});

const value = useMemo(
() => ({
nativeTokenBalance,
flockTokenBalance,
FLCTokenBalance,
FLOTokenBalance,
}),
[nativeTokenBalance, flockTokenBalance]
[nativeTokenBalance, FLCTokenBalance, FLOTokenBalance]
);

return (
Expand Down
Loading