Skip to content

Commit

Permalink
feat/correctly deploying erc1155 or erc20 token
Browse files Browse the repository at this point in the history
  • Loading branch information
scguaquetam committed Nov 6, 2024
1 parent 308e982 commit b4d6b9d
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 161 deletions.
83 changes: 27 additions & 56 deletions components/deployToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export type DeployFormData = {
maxSupply: string;
strategy: DEPLOY_STRATEGY_ENUM;
image: File | null;
tokenID?: number;
};

const DeployToken: React.FC = () => {
Expand All @@ -33,7 +32,6 @@ const DeployToken: React.FC = () => {
maxSupply: "",
strategy: DEPLOY_STRATEGY_ENUM.DEFLATIONARY,
image: null as File | null,
tokenID: 0,
});

const router = useRouter();
Expand All @@ -51,9 +49,6 @@ const DeployToken: React.FC = () => {
}
return value === "";
} else if (erc1155){
if (key === "tokenID") {
return value === "";
}
if (key === "image") {
return !value;
}
Expand Down Expand Up @@ -164,9 +159,34 @@ const DeployToken: React.FC = () => {
<span className={(!isLoggedIn ? "cursor-default " : "") + "w-11 h-6 bg-card rounded-full border border-input toggle-bg"}></span>
</label>
</div>
<div className="w-auto">
<div className="flex-row flex gap-2 items-center">
<label htmlFor="gasless">Gasless</label>
<Tooltip>
<TooltipTrigger>
<HelpCircleIcon className="w-4 h-4" />
</TooltipTrigger>
<TooltipContent>
<p>{"Active this option if you don\'t have enough rBTC."}</p>
</TooltipContent>
</Tooltip>

</div>
<label className={(!isLoggedIn ? "cursor-default " : "") + "flex relative items-center cursor-pointer mt-2"}>
<input
checked={gasless}
name="gasless"
type="checkbox"
className="sr-only"
disabled={!isLoggedIn}
onChange={(e) => setGasless(Boolean(e.target.checked))}
/>
<span className={(!isLoggedIn ? "cursor-default " : "") + "w-11 h-6 bg-card rounded-full border border-input toggle-bg"}></span>
</label>
</div>
</div>
<div className="flex flex-row gap-10 w-full">
{erc20 && <div className="w-full">
{erc20 && <div className="w-full">
<div className="flex-row flex gap-2 items-center">
<label htmlFor="strategy" className="block">
Strategy
Expand All @@ -192,56 +212,7 @@ const DeployToken: React.FC = () => {
<option value={DEPLOY_STRATEGY_ENUM.INFLATIONARY}>{DEPLOY_STRATEGY.INFLATIONARY.name}</option>
</select>
</div>}
{erc1155 && <div className="w-full">
<div className="flex-row flex gap-2 items-center">
<label htmlFor="tokenID" className="">
Token ID
</label>
<Tooltip>
<TooltipTrigger>
<HelpCircleIcon className="w-4 h-4" />
</TooltipTrigger>
<TooltipContent>
<p>Enter the ID for the initial mint token.</p>
</TooltipContent>
</Tooltip>
</div>

<input
type="text"
name="tokenID"
id="tokenID"
disabled={!isLoggedIn}
value={formData.tokenID}
onChange={handleChange}
className="mt-2 w-full px-3 py-2 border border-[hsl(var(--border))] rounded-md bg-[hsl(var(--card))] focus:border-gray-200 focus:outline-none"
/>
</div>}
<div className="w-full">
<div className="flex-row flex gap-2 items-center">
<label htmlFor="gasless">Gasless</label>
<Tooltip>
<TooltipTrigger>
<HelpCircleIcon className="w-4 h-4" />
</TooltipTrigger>
<TooltipContent>
<p>{"Active this option if you don\'t have enough rBTC."}</p>
</TooltipContent>
</Tooltip>

</div>
<label className={(!isLoggedIn ? "cursor-default " : "") + "flex relative items-center cursor-pointer mt-2"}>
<input
checked={gasless}
name="gasless"
type="checkbox"
className="sr-only"
disabled={!isLoggedIn}
onChange={(e) => setGasless(Boolean(e.target.checked))}
/>
<span className={(!isLoggedIn ? "cursor-default " : "") + "w-11 h-6 bg-card rounded-full border border-input toggle-bg"}></span>
</label>
</div>


</div>
<div className="my-4 flex flex-row gap-10">
Expand Down
2 changes: 1 addition & 1 deletion components/listTokens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const ListTokens: React.FC = () => {
<td className="py-3 px-4 text-center">{token.currentSupply}</td>
<td className=" text-center">
<div className={(token.strategy == DEPLOY_STRATEGY_ENUM.DEFLATIONARY ? "bg-custom-cyan" : "bg-custom-orange") + " font-bold text-background py-1 rounded-full"}>
{token.strategy}
{`${token.strategy !== DEPLOY_STRATEGY_ENUM.ERC1155 ? 'erc20 ' : ''}${token.strategy}`}
</div>
</td>
<td className="py-3 px-4 items-center text-center">
Expand Down
31 changes: 16 additions & 15 deletions components/ui/dialog/deployTokenDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
CopyIcon,
InfoCircleIcon,
} from '@/components/icons'
import useDeployToken, { DeployERC20Props } from '@/hooks/useDeployToken'
import useDeployToken, {
DeployERC1155Props,
DeployERC20Props,
} from '@/hooks/useDeployToken'
import { copyToClipboard, formatAddress } from '@/lib/utils'
import { Tooltip, TooltipTrigger } from '../tooltip'
import { useAuth } from '@/context/AuthContext'
Expand All @@ -32,8 +35,14 @@ function DeployTokenDialog({
erc20,
}: props) {
const { env } = useAuth()
const { deployERC20, isError, setIsError, contractAddress, txHash } =
useDeployToken()
const {
deployERC20,
isError,
setIsError,
contractAddress,
txHash,
deployERC1155,
} = useDeployToken()
const [isDeployed, setIsDeployed] = useState<boolean>(false)

const [txHashCopied, setTxHashCopied] = useState(false)
Expand Down Expand Up @@ -76,42 +85,34 @@ function DeployTokenDialog({
maxSupply,
initialSupply,
}: DeployFormData) => {
console.log('deployformdatatoprops process running')

let cid = ''

if (image) {
cid = await UploadImageIpfs(image)
console.log('cid is ', cid)

if (!cid) {
console.log('Error uploading image to IPFS')
setIsError(true)
}
}

return {
strategy,
name,
symbol,
maxSupply,
initialSupply,
cid,
} as DeployERC20Props
} as DeployERC20Props | DeployERC1155Props
}

const init = () => {
setIsError(false)
try {
console.log('Deploying contract with params: ', params)
setTimeout(async () => {
const props = await deployFormDataToProps(params)
console.log('Deploying contract with props: ', props)
return;
if(erc20){
deployERC20(props, gasless)
if (erc20) {
deployERC20(props as DeployERC20Props, gasless)
} else {

deployERC1155(props as DeployERC1155Props, gasless)
}
}, 1500)
} catch (error: any) {
Expand Down
3 changes: 2 additions & 1 deletion constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export const ROUTER = {
}
export enum DEPLOY_STRATEGY_ENUM {
INFLATIONARY = "inflationary",
DEFLATIONARY = "deflationary"
DEFLATIONARY = "deflationary",
ERC1155 = "erc1155"
}

export const DEPLOY_STRATEGY = {
Expand Down
4 changes: 2 additions & 2 deletions contracts/abi/ERC1155Token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const InflationaryTokenAbi = [
const ERC1155TokenAbi = [
{
"inputs": [
{
Expand Down Expand Up @@ -589,4 +589,4 @@ const InflationaryTokenAbi = [
}
]

export default InflationaryTokenAbi;
export default ERC1155TokenAbi;
10 changes: 0 additions & 10 deletions contracts/abi/MemeTokenERC1155Factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ const MemeTokenERC1155FactoryAbi = [
"internalType": "string",
"name": "uri",
"type": "string"
},
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "initialSupply",
"type": "uint256"
}
],
"name": "createERC1155Token",
Expand Down
Loading

0 comments on commit b4d6b9d

Please sign in to comment.