Skip to content

Commit

Permalink
finish multimint transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Oct 23, 2024
1 parent 0ef9669 commit 71b3940
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 164 deletions.
57 changes: 21 additions & 36 deletions components/factory/components/MyDenoms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PiInfo } from 'react-icons/pi';
import { ExtendedMetadataSDKType, shiftDigits } from '@/utils';
import { MultiMintModal } from '@/components/factory/modals';
import { MultiBurnModal } from '../modals/multiMfxBurnModal';

import { usePoaGetAdmin } from '@/hooks';
export default function MyDenoms({
denoms,
isLoading,
Expand Down Expand Up @@ -45,6 +45,8 @@ export default function MyDenoms({
}
};

const { poaAdmin, isPoaAdminLoading } = usePoaGetAdmin();

useEffect(() => {
const { denom, action } = router.query;
if (denom && typeof denom === 'string') {
Expand Down Expand Up @@ -217,6 +219,8 @@ export default function MyDenoms({
onClose={handleCloseModal}
/>
<MintModal
admin={poaAdmin ?? ''}
isPoaAdminLoading={isPoaAdminLoading}
denom={selectedDenom}
address={address}
refetch={refetchDenoms}
Expand Down Expand Up @@ -245,42 +249,22 @@ export default function MyDenoms({
}}
/>
<MultiMintModal
admin={poaAdmin ?? 'manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj'}
address={address}
denom={selectedDenom}
exponent={selectedDenom?.denom_units[1]?.exponent ?? 0}
refetch={refetchDenoms}
isOpen={modalType === 'multimint'}
onClose={handleCloseModal}
payoutPairs={[{ address: '', amount: '' }]} // Initialize with empty pair
updatePayoutPair={(index, field, value) => {
// ... existing update logic ...
}}
addPayoutPair={() => {
// ... existing add logic ...
}}
removePayoutPair={index => {
// ... existing remove logic ...
}}
handleMultiMint={async () => {
// ... existing multi mint logic ...
handleCloseModal();
}}
isSigning={false}
/>
<MultiBurnModal
admin={address}
address={address}
denom={selectedDenom}
exponent={selectedDenom?.denom_units[1]?.exponent ?? 0}
refetch={refetchDenoms}
isOpen={modalType === 'multiburn'}
onClose={handleCloseModal}
burnPairs={[{ address: '', amount: '' }]}
updateBurnPair={(index, field, value) => {
// Implementation will be handled in BurnForm
}}
addBurnPair={() => {
// Implementation will be handled in BurnForm
}}
removeBurnPair={index => {
// Implementation will be handled in BurnForm
}}
handleMultiBurn={async () => {
// Implementation will be handled in BurnForm
handleCloseModal();
}}
isSigning={false}
/>
</div>
);
Expand Down Expand Up @@ -341,16 +325,17 @@ function TokenRow({
</span>
</div>
</td>
<td
className="rounded-r-[12px] w-1/4"
onClick={e => e.stopPropagation()} // Stop propagation at the cell level
>
<td className="rounded-r-[12px] w-1/4" onClick={e => e.stopPropagation()}>
<div className="flex space-x-2">
<button className="btn btn-sm btn-outline btn-square btn-primary group" onClick={onMint}>
<MintIcon className="w-5 h-5 text-current group-hover:text-white" />
</button>

<button className="btn btn-sm btn-outline btn-square btn-error group" onClick={onBurn}>
<button
disabled={denom.base.includes('umfx')}
className="btn btn-sm btn-outline btn-square btn-error group"
onClick={onBurn}
>
<BurnIcon className="w-5 h-5 text-current group-hover:text-white" />
</button>

Expand Down
50 changes: 9 additions & 41 deletions components/factory/forms/MintForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import Yup from '@/utils/yupExtensions';
import { NumberInput, TextInput } from '@/components/react/inputs';
import { ExtendedMetadataSDKType, truncateString } from '@/utils';

interface PayoutPair {
address: string;
amount: string;
}

export default function MintForm({
isAdmin,
admin,
Expand All @@ -41,12 +36,9 @@ export default function MintForm({
const [amount, setAmount] = useState('');
const [recipient, setRecipient] = useState(address);

const { setToastMessage } = useToast();
const { tx, isSigning, setIsSigning } = useTx(chainName);
const { estimateFee } = useFeeEstimation(chainName);
const { mint } = osmosis.tokenfactory.v1beta1.MessageComposer.withTypeUrl;
const { payout } = liftedinit.manifest.v1.MessageComposer.withTypeUrl;
const { submitProposal } = cosmos.group.v1.MessageComposer.withTypeUrl;

const exponent =
denom?.denom_units?.find((unit: { denom: string }) => unit.denom === denom.display)?.exponent ||
Expand All @@ -70,39 +62,15 @@ export default function MintForm({
const amountInBaseUnits = BigInt(parseFloat(amount) * Math.pow(10, exponent)).toString();

let msg;
if (isMFX) {
const payoutMsg = payout({
authority: admin ?? '',
payoutPairs: [
{
address: recipient,
coin: { denom: denom.base, amount: amountInBaseUnits },
},
],
});
const encodedMessage = Any.fromPartial({
typeUrl: payoutMsg.typeUrl,
value: MsgPayout.encode(payoutMsg.value).finish(),
});
msg = submitProposal({
groupPolicyAddress: admin ?? '',
messages: [encodedMessage],
metadata: '',
proposers: [address ?? ''],
title: `Manifest Module Control: Mint MFX`,
summary: `This proposal includes a mint action for MFX.`,
exec: 0,
});
} else {
msg = mint({
amount: {
amount: amountInBaseUnits,
denom: denom.base,
},
sender: address,
mintToAddress: recipient,
});
}

msg = mint({
amount: {
amount: amountInBaseUnits,
denom: denom.base,
},
sender: address,
mintToAddress: recipient,
});

const fee = await estimateFee(address ?? '', [msg]);
await tx([msg], {
Expand Down
75 changes: 41 additions & 34 deletions components/factory/modals/BurnModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';

import BurnForm from '@/components/factory/forms/BurnForm';
import { useGroupsByAdmin, usePoaGetAdmin } from '@/hooks';
Expand All @@ -23,6 +23,7 @@ export default function BurnModal({
onClose: () => void;
onSwitchToMultiBurn: () => void;
}) {
const [isMultiBurnOpen, setIsMultiBurnOpen] = useState(false);
const { poaAdmin, isPoaAdminLoading } = usePoaGetAdmin();
const { groupByAdmin, isGroupByAdminLoading } = useGroupsByAdmin(
poaAdmin ?? 'manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj'
Expand All @@ -38,40 +39,46 @@ export default function BurnModal({
onSwitchToMultiBurn();
};

const handleMultiBurnClose = () => {
setIsMultiBurnOpen(false);
};

return (
<dialog id={`burn-modal-${denom.base}`} className={`modal ${isOpen ? 'modal-open' : ''}`}>
<div className="modal-box max-w-4xl mx-auto rounded-[24px] bg-[#F4F4FF] dark:bg-[#1D192D] shadow-lg">
<form method="dialog" onSubmit={onClose}>
<button className="btn btn-sm btn-circle btn-ghost absolute right-2 top-2 text-[#00000099] dark:text-[#FFFFFF99] hover:bg-[#0000000A] dark:hover:bg-[#FFFFFF1A]">
</button>
</form>
<h3 className="text-xl font-semibold text-[#161616] dark:text-white mb-6">
Burn{' '}
<span className="font-light text-primary">
{truncateString(denom.display ?? 'Denom', 20).toUpperCase()}
</span>
</h3>
<div className="py-4">
{isLoading ? (
<div className="skeleton h-[17rem] max-h-72 w-full"></div>
) : (
<BurnForm
isAdmin={isAdmin ?? false}
admin={poaAdmin ?? ''}
balance={balance}
totalSupply={totalSupply}
refetch={refetch}
address={address}
denom={denom}
onMultiBurnClick={handleMultiBurnOpen}
/>
)}
<>
<dialog id={`burn-modal-${denom?.base}`} className={`modal ${isOpen ? 'modal-open' : ''}`}>
<div className="modal-box max-w-4xl mx-auto rounded-[24px] bg-[#F4F4FF] dark:bg-[#1D192D] shadow-lg">
<form method="dialog" onSubmit={onClose}>
<button className="btn btn-sm btn-circle btn-ghost absolute right-2 top-2 text-[#00000099] dark:text-[#FFFFFF99] hover:bg-[#0000000A] dark:hover:bg-[#FFFFFF1A]">
</button>
</form>
<h3 className="text-xl font-semibold text-[#161616] dark:text-white mb-6">
Burn{' '}
<span className="font-light text-primary">
{truncateString(denom.display ?? 'Denom', 20).toUpperCase()}
</span>
</h3>
<div className="py-4">
{isLoading ? (
<div className="skeleton h-[17rem] max-h-72 w-full"></div>
) : (
<BurnForm
isAdmin={isAdmin ?? false}
admin={poaAdmin ?? ''}
balance={balance}
totalSupply={totalSupply}
refetch={refetch}
address={address}
denom={denom}
onMultiBurnClick={handleMultiBurnOpen}
/>
)}
</div>
</div>
</div>
<form method="dialog" className="modal-backdrop" onSubmit={onClose}>
<button>close</button>
</form>
</dialog>
<form method="dialog" className="modal-backdrop" onSubmit={onClose}>
<button>close</button>
</form>
</dialog>
</>
);
}
35 changes: 14 additions & 21 deletions components/factory/modals/MintModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default function MintModal({
totalSupply,
isOpen,
onClose,
onSwitchToMultiMint, // Add this prop
onSwitchToMultiMint,
admin,
isPoaAdminLoading,
}: {
denom: ExtendedMetadataSDKType | null;
address: string;
Expand All @@ -22,14 +24,14 @@ export default function MintModal({
totalSupply: string;
isOpen: boolean;
onClose: () => void;
onSwitchToMultiMint: () => void; // New prop
onSwitchToMultiMint: () => void;
admin: string;
isPoaAdminLoading: boolean;
}) {
const [isMultiMintOpen, setIsMultiMintOpen] = useState(false);
const [payoutPairs, setPayoutPairs] = useState([{ address: '', amount: '' }]);

const { poaAdmin, isPoaAdminLoading } = usePoaGetAdmin();
const { groupByAdmin, isGroupByAdminLoading } = useGroupsByAdmin(
poaAdmin ?? 'manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj'
admin ?? 'manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj'
);

const members = groupByAdmin?.groups?.[0]?.members;
Expand All @@ -39,7 +41,7 @@ export default function MintModal({
if (!denom) return null;

const handleMultiMintOpen = () => {
onSwitchToMultiMint(); // Use the new prop instead of managing state internally
onSwitchToMultiMint();
};

const handleMultiMintClose = () => {
Expand Down Expand Up @@ -67,7 +69,7 @@ export default function MintModal({
) : (
<MintForm
isAdmin={isAdmin ?? false}
admin={poaAdmin ?? ''}
admin={admin ?? ''}
balance={balance}
totalSupply={totalSupply}
refetch={refetch}
Expand All @@ -83,23 +85,14 @@ export default function MintModal({
</form>
</dialog>

{/* Render MultiMintModal at the same level */}
<MultiMintModal
isOpen={isMultiMintOpen}
onClose={handleMultiMintClose}
payoutPairs={payoutPairs}
updatePayoutPair={(index, field, value) => {
const newPairs = [...payoutPairs];
newPairs[index][field] = value;
setPayoutPairs(newPairs);
}}
addPayoutPair={() => setPayoutPairs([...payoutPairs, { address: '', amount: '' }])}
removePayoutPair={index => setPayoutPairs(payoutPairs.filter((_, i) => i !== index))}
handleMultiMint={async () => {
// ... handle multi mint logic ...
handleMultiMintClose();
}}
isSigning={false} // Add your signing state here
admin={admin ?? ''}
address={address}
denom={denom}
exponent={denom?.denom_units?.[1]?.exponent || 0}
refetch={refetch}
/>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions components/factory/modals/denomInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { useRouter } from 'next/router';
export const DenomInfoModal: React.FC<{
denom: MetadataSDKType | null;
modalId: string;
isOpen: boolean;
onClose: () => void;
isOpen?: boolean;
onClose?: () => void;
}> = ({ denom, modalId, isOpen, onClose }) => {
return (
<dialog id={modalId} className={`modal ${isOpen ? 'modal-open' : ''}`}>
Expand Down
Loading

0 comments on commit 71b3940

Please sign in to comment.