@@ -5,40 +5,28 @@ import {
55} from '@heroicons/react/outline'
66import { ViewState } from './types'
77import useMembersListStore from 'stores/useMembersListStore'
8- import { PublicKey , TransactionInstruction } from '@solana/web3.js'
9- import useRealm from '@ hooks/useRealm'
10- import Input from '@ components/inputs/Input'
8+ import { PublicKey } from '@solana/web3.js'
9+ import useRealm from 'hooks/useRealm'
10+ import Input from 'components/inputs/Input'
1111import Button , { SecondaryButton } from '@components/Button'
12- import Textarea from '@ components/inputs/Textarea'
12+ import Textarea from 'components/inputs/Textarea'
1313import VoteBySwitch from 'pages/dao/[symbol]/proposal/components/VoteBySwitch'
14- import {
15- getMintMinAmountAsDecimal ,
16- parseMintNaturalAmountFromDecimal ,
17- } from '@tools/sdk/units'
18- import { precision } from '@utils/formatting'
14+ import { getMintMinAmountAsDecimal } from '@tools/sdk/units'
15+ import { precision } from 'utils/formatting'
1916import useWalletStore from 'stores/useWalletStore'
20- import { getMintSchema } from '@ utils/validations'
17+ import { getMintSchema } from 'utils/validations'
2118import { useEffect , useState } from 'react'
22- import { MintForm , UiInstruction } from '@utils/uiTypes/proposalCreationTypes'
23- import { validateInstruction } from '@utils/instructionTools'
24- import useGovernanceAssets from '@hooks/useGovernanceAssets'
25- import {
26- ASSOCIATED_TOKEN_PROGRAM_ID ,
27- Token ,
28- TOKEN_PROGRAM_ID ,
29- } from '@solana/spl-token'
30- import {
31- getInstructionDataFromBase64 ,
32- serializeInstructionToBase64 ,
33- } from '@models/serialisation'
34- import { getATA } from '@utils/ataTools'
35- import { RpcContext } from '@models/core/api'
36- import { Governance } from '@models/accounts'
37- import { ParsedAccount } from '@models/core/accounts'
19+ import { MintForm , UiInstruction } from 'utils/uiTypes/proposalCreationTypes'
20+ import useGovernanceAssets from 'hooks/useGovernanceAssets'
21+ import { getInstructionDataFromBase64 } from 'models/serialisation'
22+ import { RpcContext } from 'models/core/api'
23+ import { Governance } from 'models/accounts'
24+ import { ParsedAccount } from 'models/core/accounts'
3825import { useRouter } from 'next/router'
3926import { createProposal } from 'actions/createProposal'
40- import { notify } from '@utils/notifications'
41- import useQueryContext from '@hooks/useQueryContext'
27+ import { notify } from 'utils/notifications'
28+ import useQueryContext from 'hooks/useQueryContext'
29+ import { getMintInstruction } from 'utils/instructionTools'
4230
4331interface AddMemberForm extends MintForm {
4432 description : string
@@ -110,57 +98,16 @@ const AddMember = () => {
11098 propertyName : 'amount' ,
11199 } )
112100 }
113- //TODO common getMintInstruction
114101 async function getInstruction ( ) : Promise < UiInstruction > {
115- const isValid = await validateInstruction ( { schema, form, setFormErrors } )
116- let serializedInstruction = ''
117- const prerequisiteInstructions : TransactionInstruction [ ] = [ ]
118- if ( isValid && programId && form . mintAccount ?. governance ?. pubkey ) {
119- //this is the original owner
120- const destinationAccount = new PublicKey ( form . destinationAccount )
121- const mintPK = form . mintAccount . governance . info . governedAccount
122- const mintAmount = parseMintNaturalAmountFromDecimal (
123- form . amount ! ,
124- form . mintAccount . mintInfo ?. decimals
125- )
126- //we find true receiver address if its wallet and we need to create ATA the ata address will be the receiver
127- const { currentAddress : receiverAddress , needToCreateAta } = await getATA (
128- connection ,
129- destinationAccount ,
130- mintPK ,
131- wallet !
132- )
133- //we push this createATA instruction to transactions to create right before creating proposal
134- //we don't want to create ata only when instruction is serialized
135- if ( needToCreateAta ) {
136- prerequisiteInstructions . push (
137- Token . createAssociatedTokenAccountInstruction (
138- ASSOCIATED_TOKEN_PROGRAM_ID , // always ASSOCIATED_TOKEN_PROGRAM_ID
139- TOKEN_PROGRAM_ID , // always TOKEN_PROGRAM_ID
140- mintPK , // mint
141- receiverAddress , // ata
142- destinationAccount , // owner of token account
143- wallet ! . publicKey ! // fee payer
144- )
145- )
146- }
147- const transferIx = Token . createMintToInstruction (
148- TOKEN_PROGRAM_ID ,
149- form . mintAccount . governance . info . governedAccount ,
150- receiverAddress ,
151- form . mintAccount . governance ! . pubkey ,
152- [ ] ,
153- mintAmount
154- )
155- serializedInstruction = serializeInstructionToBase64 ( transferIx )
156- }
157- const obj : UiInstruction = {
158- serializedInstruction,
159- isValid,
160- governance : form . mintAccount ?. governance ,
161- prerequisiteInstructions : prerequisiteInstructions ,
162- }
163- return obj
102+ return getMintInstruction ( {
103+ schema,
104+ form,
105+ programId,
106+ connection,
107+ wallet,
108+ governedMintInfoAccount : form . mintAccount ,
109+ setFormErrors,
110+ } )
164111 }
165112 //TODO common handle propose
166113 const handlePropose = async ( ) => {
0 commit comments