fix
This commit is contained in:
parent
0f32b5b89e
commit
c46ac29a89
|
@ -25,6 +25,7 @@ import {
|
|||
import { createProposal } from 'utils/governance/instructions/createProposal'
|
||||
import { getBestMarket } from 'utils/governance/listingTools'
|
||||
import { notify } from 'utils/notifications'
|
||||
import ListTokenSuccess from '../ListToken/ListTokenSuccess'
|
||||
|
||||
type FormErrors = Partial<Record<keyof ListMarketForm, string>>
|
||||
|
||||
|
@ -58,12 +59,14 @@ const ListMarket = () => {
|
|||
const availableTokens = group ? [...group.banksMapByName.keys()] : []
|
||||
const client = mangoStore((s) => s.client)
|
||||
const voter = GovernanceStore((s) => s.voter)
|
||||
|
||||
const vsrClient = GovernanceStore((s) => s.vsrClient)
|
||||
const proposals = GovernanceStore((s) => s.proposals)
|
||||
|
||||
const [advForm, setAdvForm] = useState<ListMarketForm>({
|
||||
...defaultFormValues,
|
||||
})
|
||||
const [proposalPk, setProposalPk] = useState<string | null>(null)
|
||||
const [formErrors, setFormErrors] = useState<FormErrors>({})
|
||||
const [baseToken, setBaseToken] = useState<null | string>(null)
|
||||
const [quoteToken, setQuoteToken] = useState<null | string>(null)
|
||||
|
@ -92,6 +95,7 @@ const ListMarket = () => {
|
|||
const goToHomePage = async () => {
|
||||
setCurrentView(VIEWS.BASE_TOKEN)
|
||||
setMarketPk('')
|
||||
setProposalPk('')
|
||||
setAdvForm({
|
||||
...defaultFormValues,
|
||||
})
|
||||
|
@ -99,8 +103,8 @@ const ListMarket = () => {
|
|||
const handlePropose = useCallback(async () => {
|
||||
setProposing(true)
|
||||
const index = proposals ? Object.values(proposals).length : 0
|
||||
|
||||
const proposalTx = []
|
||||
|
||||
const registerMarketix = await client!.program.methods
|
||||
.serum3RegisterMarket(advForm.marketIndex, advForm.marketName)
|
||||
.accounts({
|
||||
|
@ -113,6 +117,7 @@ const ListMarket = () => {
|
|||
payer: MANGO_DAO_WALLET,
|
||||
})
|
||||
.instruction()
|
||||
|
||||
proposalTx.push(registerMarketix)
|
||||
|
||||
const walletSigner = wallet as never
|
||||
|
@ -128,7 +133,8 @@ const ListMarket = () => {
|
|||
proposalTx,
|
||||
vsrClient!
|
||||
)
|
||||
console.log(proposalAddress)
|
||||
setProposalPk(proposalAddress.toBase58())
|
||||
setCurrentView(VIEWS.SUCCESS)
|
||||
} catch (e) {
|
||||
notify({
|
||||
title: t('error-proposal-creation'),
|
||||
|
@ -146,7 +152,7 @@ const ListMarket = () => {
|
|||
proposals,
|
||||
quoteBank,
|
||||
t,
|
||||
voter.tokenOwnerRecord,
|
||||
voter,
|
||||
vsrClient,
|
||||
wallet,
|
||||
])
|
||||
|
@ -172,13 +178,6 @@ const ListMarket = () => {
|
|||
setLoadingMarketProps(false)
|
||||
}, [baseBank, quoteBank, connection])
|
||||
|
||||
useEffect(() => {
|
||||
setAdvForm((prevForm) => ({
|
||||
...prevForm,
|
||||
openBookMarketExternalPk: marketPk,
|
||||
}))
|
||||
}, [marketPk])
|
||||
|
||||
useEffect(() => {
|
||||
const index = proposals ? Object.values(proposals).length : 0
|
||||
|
||||
|
@ -187,12 +186,19 @@ const ListMarket = () => {
|
|||
marketIndex: Number(index),
|
||||
marketName: marketName,
|
||||
proposalTitle: `List market ${marketName}`,
|
||||
openBookMarketExternalPk: marketPk,
|
||||
}))
|
||||
}, [marketName, proposals])
|
||||
}, [marketName, proposals, marketPk])
|
||||
|
||||
return (
|
||||
<div className="h-full">
|
||||
<h1 className="mb-4 flex items-center">{t('new-market-listing')}</h1>
|
||||
{proposalPk && currentView === VIEWS.SUCCESS && (
|
||||
<ListTokenSuccess
|
||||
proposalPk={proposalPk}
|
||||
token={advForm?.marketName}
|
||||
></ListTokenSuccess>
|
||||
)}
|
||||
{currentView === VIEWS.BASE_TOKEN && (
|
||||
<div className="mb-6">
|
||||
<h2 className="mb-2 text-lg">{t('before-you-list-market')}</h2>
|
||||
|
@ -223,15 +229,13 @@ const ListMarket = () => {
|
|||
onChange={(token) => setBaseToken(token)}
|
||||
className="w-full"
|
||||
>
|
||||
{availableTokens
|
||||
.filter((x) => x !== quoteToken)
|
||||
.map((token) => (
|
||||
<Select.Option key={token} value={token}>
|
||||
<div className="flex w-full items-center justify-between">
|
||||
{token}
|
||||
</div>
|
||||
</Select.Option>
|
||||
))}
|
||||
{availableTokens.map((token) => (
|
||||
<Select.Option key={token} value={token}>
|
||||
<div className="flex w-full items-center justify-between">
|
||||
{token}
|
||||
</div>
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
<div className="pb-4">
|
||||
|
@ -241,15 +245,13 @@ const ListMarket = () => {
|
|||
onChange={(token) => setQuoteToken(token)}
|
||||
className="w-full"
|
||||
>
|
||||
{availableTokens
|
||||
.filter((x) => x !== baseToken)
|
||||
.map((token) => (
|
||||
<Select.Option key={token} value={token}>
|
||||
<div className="flex w-full items-center justify-between">
|
||||
{token}
|
||||
</div>
|
||||
</Select.Option>
|
||||
))}
|
||||
{availableTokens.map((token) => (
|
||||
<Select.Option key={token} value={token}>
|
||||
<div className="flex w-full items-center justify-between">
|
||||
{token}
|
||||
</div>
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -136,6 +136,11 @@ const CreateOpenbookMarketModal = ({
|
|||
signature: sig,
|
||||
})
|
||||
}
|
||||
onClose()
|
||||
notify({
|
||||
title: t('market-created-successful'),
|
||||
type: 'success',
|
||||
})
|
||||
} catch (e) {
|
||||
notify({
|
||||
title: t('error-creating-market'),
|
||||
|
@ -145,7 +150,6 @@ const CreateOpenbookMarketModal = ({
|
|||
})
|
||||
}
|
||||
setCreating(false)
|
||||
onClose()
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -179,80 +183,82 @@ const CreateOpenbookMarketModal = ({
|
|||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose}>
|
||||
<p>Creating market will cost at least {solNeededToCreateMarket} sol</p>
|
||||
<div>
|
||||
<Label text={t('open-book-market-id')} />
|
||||
<Input
|
||||
hasError={formErrors.programId !== undefined}
|
||||
type="text"
|
||||
disabled={true}
|
||||
value={form.programId.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('programId', e.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label text={t('base-mint')} />
|
||||
<Input
|
||||
hasError={formErrors.baseMint !== undefined}
|
||||
type="text"
|
||||
disabled={true}
|
||||
value={form.baseMint.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('baseMint', e.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label text={t('quote-mint')} />
|
||||
<Input
|
||||
disabled={true}
|
||||
hasError={formErrors.quoteMint !== undefined}
|
||||
type="text"
|
||||
value={form.quoteMint.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('quoteMint', e.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label text={t('min-order')} />
|
||||
<Input
|
||||
hasError={formErrors.minimumOrderSize !== undefined}
|
||||
type="text"
|
||||
value={form.minimumOrderSize.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('minimumOrderSize', e.target.value)
|
||||
}
|
||||
/>
|
||||
{formErrors.minimumOrderSize && (
|
||||
<div className="mt-1.5 flex items-center space-x-1">
|
||||
<ExclamationCircleIcon className="h-4 w-4 text-th-down" />
|
||||
<p className="mb-0 text-xs text-th-down">
|
||||
{formErrors.minimumOrderSize}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<Label text={t('price-tick')} />
|
||||
<Input
|
||||
hasError={formErrors.minimumPriceTickSize !== undefined}
|
||||
type="text"
|
||||
value={form.minimumPriceTickSize.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('minimumPriceTickSize', e.target.value)
|
||||
}
|
||||
/>
|
||||
{formErrors.minimumPriceTickSize && (
|
||||
<div className="mt-1.5 flex items-center space-x-1">
|
||||
<ExclamationCircleIcon className="h-4 w-4 text-th-down" />
|
||||
<p className="mb-0 text-xs text-th-down">
|
||||
{formErrors.minimumPriceTickSize}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-4">
|
||||
<p>Creating market will cost at least {solNeededToCreateMarket} SOL</p>
|
||||
<div>
|
||||
<Label text={t('open-book-market-id')} />
|
||||
<Input
|
||||
hasError={formErrors.programId !== undefined}
|
||||
type="text"
|
||||
disabled={true}
|
||||
value={form.programId.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('programId', e.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label text={t('base-mint')} />
|
||||
<Input
|
||||
hasError={formErrors.baseMint !== undefined}
|
||||
type="text"
|
||||
disabled={true}
|
||||
value={form.baseMint.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('baseMint', e.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label text={t('quote-mint')} />
|
||||
<Input
|
||||
disabled={true}
|
||||
hasError={formErrors.quoteMint !== undefined}
|
||||
type="text"
|
||||
value={form.quoteMint.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('quoteMint', e.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label text={t('min-order')} />
|
||||
<Input
|
||||
hasError={formErrors.minimumOrderSize !== undefined}
|
||||
type="text"
|
||||
value={form.minimumOrderSize.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('minimumOrderSize', e.target.value)
|
||||
}
|
||||
/>
|
||||
{formErrors.minimumOrderSize && (
|
||||
<div className="mt-1.5 flex items-center space-x-1">
|
||||
<ExclamationCircleIcon className="h-4 w-4 text-th-down" />
|
||||
<p className="mb-0 text-xs text-th-down">
|
||||
{formErrors.minimumOrderSize}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<Label text={t('price-tick')} />
|
||||
<Input
|
||||
hasError={formErrors.minimumPriceTickSize !== undefined}
|
||||
type="text"
|
||||
value={form.minimumPriceTickSize.toString()}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
handleSetAdvForm('minimumPriceTickSize', e.target.value)
|
||||
}
|
||||
/>
|
||||
{formErrors.minimumPriceTickSize && (
|
||||
<div className="mt-1.5 flex items-center space-x-1">
|
||||
<ExclamationCircleIcon className="h-4 w-4 text-th-down" />
|
||||
<p className="mb-0 text-xs text-th-down">
|
||||
{formErrors.minimumPriceTickSize}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
|
|
|
@ -77,5 +77,16 @@
|
|||
"select-delegate": "Select delegate",
|
||||
"new-market-listing": "New Market Listing",
|
||||
"before-you-list-market": "Before you propose listing a market on Mango:",
|
||||
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days"
|
||||
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
|
||||
"base-token": "Base token",
|
||||
"quote-token": "Quote token",
|
||||
"market-index": "Market index",
|
||||
"creating-market-will-cost": "Creating market will cost at least",
|
||||
"open-book-market-id": "Openbook market id",
|
||||
"base-mint": "Base mint",
|
||||
"quote-mint": "Quote mint",
|
||||
"min-order": "Min order",
|
||||
"price-tick": "Price tick",
|
||||
"market-created-successful": "Market created successful",
|
||||
"error-creating-market": "Error during market creation"
|
||||
}
|
|
@ -74,5 +74,19 @@
|
|||
"no": "No",
|
||||
"current-vote": "Current Vote:",
|
||||
"use-own-wallet": "Use own wallet",
|
||||
"select-delegate": "Select delegate"
|
||||
"select-delegate": "Select delegate",
|
||||
"new-market-listing": "New Market Listing",
|
||||
"before-you-list-market": "Before you propose listing a market on Mango:",
|
||||
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
|
||||
"base-token": "Base token",
|
||||
"quote-token": "Quote token",
|
||||
"market-index": "Market index",
|
||||
"creating-market-will-cost": "Creating market will cost at least",
|
||||
"open-book-market-id": "Openbook market id",
|
||||
"base-mint": "Base mint",
|
||||
"quote-mint": "Quote mint",
|
||||
"min-order": "Min order",
|
||||
"price-tick": "Price tick",
|
||||
"market-created-successful": "Market created successful",
|
||||
"error-creating-market": "Error during market creation"
|
||||
}
|
|
@ -74,5 +74,19 @@
|
|||
"no": "No",
|
||||
"current-vote": "Current Vote:",
|
||||
"use-own-wallet": "Use own wallet",
|
||||
"select-delegate": "Select delegate"
|
||||
"select-delegate": "Select delegate",
|
||||
"new-market-listing": "New Market Listing",
|
||||
"before-you-list-market": "Before you propose listing a market on Mango:",
|
||||
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
|
||||
"base-token": "Base token",
|
||||
"quote-token": "Quote token",
|
||||
"market-index": "Market index",
|
||||
"creating-market-will-cost": "Creating market will cost at least",
|
||||
"open-book-market-id": "Openbook market id",
|
||||
"base-mint": "Base mint",
|
||||
"quote-mint": "Quote mint",
|
||||
"min-order": "Min order",
|
||||
"price-tick": "Price tick",
|
||||
"market-created-successful": "Market created successful",
|
||||
"error-creating-market": "Error during market creation"
|
||||
}
|
|
@ -74,5 +74,19 @@
|
|||
"no": "No",
|
||||
"current-vote": "Current Vote:",
|
||||
"use-own-wallet": "Use own wallet",
|
||||
"select-delegate": "Select delegate"
|
||||
"select-delegate": "Select delegate",
|
||||
"new-market-listing": "New Market Listing",
|
||||
"before-you-list-market": "Before you propose listing a market on Mango:",
|
||||
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
|
||||
"base-token": "Base token",
|
||||
"quote-token": "Quote token",
|
||||
"market-index": "Market index",
|
||||
"creating-market-will-cost": "Creating market will cost at least",
|
||||
"open-book-market-id": "Openbook market id",
|
||||
"base-mint": "Base mint",
|
||||
"quote-mint": "Quote mint",
|
||||
"min-order": "Min order",
|
||||
"price-tick": "Price tick",
|
||||
"market-created-successful": "Market created successful",
|
||||
"error-creating-market": "Error during market creation"
|
||||
}
|
|
@ -74,5 +74,19 @@
|
|||
"no": "No",
|
||||
"current-vote": "Current Vote:",
|
||||
"use-own-wallet": "Use own wallet",
|
||||
"select-delegate": "Select delegate"
|
||||
"select-delegate": "Select delegate",
|
||||
"new-market-listing": "New Market Listing",
|
||||
"before-you-list-market": "Before you propose listing a market on Mango:",
|
||||
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
|
||||
"base-token": "Base token",
|
||||
"quote-token": "Quote token",
|
||||
"market-index": "Market index",
|
||||
"creating-market-will-cost": "Creating market will cost at least",
|
||||
"open-book-market-id": "Openbook market id",
|
||||
"base-mint": "Base mint",
|
||||
"quote-mint": "Quote mint",
|
||||
"min-order": "Min order",
|
||||
"price-tick": "Price tick",
|
||||
"market-created-successful": "Market created successful",
|
||||
"error-creating-market": "Error during market creation"
|
||||
}
|
|
@ -43,7 +43,10 @@ export async function castVote(
|
|||
)
|
||||
|
||||
const { updateVoterWeightRecordIx, voterWeightPk } =
|
||||
await updateVoterWeightRecord(vsrClient, walletPubkey)
|
||||
await updateVoterWeightRecord(
|
||||
vsrClient,
|
||||
tokenOwnerRecord.account.governingTokenOwner
|
||||
)
|
||||
instructions.push(updateVoterWeightRecordIx)
|
||||
|
||||
// It is not clear that defining these extraneous fields, `deny` and `veto`, is actually necessary.
|
||||
|
@ -97,7 +100,10 @@ export async function castVote(
|
|||
|
||||
if (message) {
|
||||
const { updateVoterWeightRecordIx, voterWeightPk } =
|
||||
await updateVoterWeightRecord(vsrClient, walletPubkey)
|
||||
await updateVoterWeightRecord(
|
||||
vsrClient,
|
||||
tokenOwnerRecord.account.governingTokenOwner
|
||||
)
|
||||
instructions.push(updateVoterWeightRecordIx)
|
||||
|
||||
await withPostChatMessage(
|
||||
|
|
|
@ -53,7 +53,10 @@ export const createProposal = async (
|
|||
const useDenyOption = true
|
||||
|
||||
const { updateVoterWeightRecordIx, voterWeightPk } =
|
||||
await updateVoterWeightRecord(client, walletPk)
|
||||
await updateVoterWeightRecord(
|
||||
client,
|
||||
tokenOwnerRecord.account.governingTokenOwner
|
||||
)
|
||||
instructions.push(updateVoterWeightRecordIx)
|
||||
|
||||
const proposalAddress = await withCreateProposal(
|
||||
|
|
Loading…
Reference in New Issue