Skip to content

Commit

Permalink
Centrifuge App: Add debug flag for pool create type (#1563)
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser authored Sep 6, 2023
1 parent 3e24e57 commit bc39545
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
11 changes: 11 additions & 0 deletions centrifuge-app/src/components/DebugFlags/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import { config } from '../../config'
import { ConvertEvmAddress } from './components/ConvertEvmAddress'

const params = new URLSearchParams(typeof window !== 'undefined' ? window.location.search : {})
Expand Down Expand Up @@ -46,6 +47,7 @@ export type Key =
| 'showPodAccountCreation'
| 'convertEvmAddress'
| 'showPortfolio'
| 'poolCreationType'

export const flagsConfig: Record<Key, DebugFlagConfig> = {
address: {
Expand Down Expand Up @@ -119,4 +121,13 @@ export const flagsConfig: Record<Key, DebugFlagConfig> = {
default: false,
alwaysShow: true,
},
poolCreationType: {
type: 'select',
default: config.poolCreationType || 'immediate',
options: {
immediate: 'immediate',
propose: 'propose',
notePreimage: 'notePreimage',
},
},
}
17 changes: 10 additions & 7 deletions centrifuge-app/src/pages/IssuerCreatePool/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CurrencyBalance, isSameAddress, Perquintill, Rate } from '@centrifuge/centrifuge-js'
import { CurrencyBalance, isSameAddress, Perquintill, Rate, TransactionOptions } from '@centrifuge/centrifuge-js'
import { CurrencyKey, PoolMetadataInput, TrancheInput } from '@centrifuge/centrifuge-js/dist/modules/pools'
import {
useBalances,
Expand All @@ -25,6 +25,7 @@ import { Field, FieldProps, Form, FormikErrors, FormikProvider, setIn, useFormik
import * as React from 'react'
import { useHistory } from 'react-router'
import { combineLatest, lastValueFrom, switchMap, tap } from 'rxjs'
import { useDebugFlags } from '../../components/DebugFlags'
import { PreimageHashDialog } from '../../components/Dialogs/PreimageHashDialog'
import { ShareMultisigDialog } from '../../components/Dialogs/ShareMultisigDialog'
import { FieldWithErrorMessage } from '../../components/FieldWithErrorMessage'
Expand Down Expand Up @@ -154,6 +155,8 @@ function CreatePoolForm() {
const [preimageHash, setPreimageHash] = React.useState('')
const [createdPoolId, setCreatedPoolId] = React.useState('')
const [multisigData, setMultisigData] = React.useState<{ hash: string; callData: string }>()
const { poolCreationType } = useDebugFlags()
const createType = (poolCreationType as TransactionOptions['createType']) || config.poolCreationType || 'immediate'

React.useEffect(() => {
// If the hash can't be found on Pinata the request can take a long time to time out
Expand Down Expand Up @@ -182,7 +185,7 @@ function CreatePoolForm() {
notePreimage: 'Note preimage',
}
const { execute: createPoolTx, isLoading: transactionIsPending } = useCentrifugeTransaction(
`${txMessage[config.poolCreationType || 'immediate']} 2/2`,
`${txMessage[createType]} 2/2`,
(cent) =>
(
args: [
Expand Down Expand Up @@ -251,15 +254,15 @@ function CreatePoolForm() {
onSuccess: (args) => {
if (form.values.adminMultisigEnabled) setIsMultisigDialogOpen(true)
const [, , , poolId] = args
if (config.poolCreationType === 'immediate') {
if (createType === 'immediate') {
setCreatedPoolId(poolId)
}
},
}
)

const { execute: createProxies, isLoading: createProxiesIsPending } = useCentrifugeTransaction(
`${txMessage[config.poolCreationType || 'immediate']} 1/2`,
`${txMessage[createType]} 1/2`,
(cent) => {
return (_: [nextTx: (adminProxy: string, aoProxy: string) => void], options) =>
cent.getApi().pipe(
Expand Down Expand Up @@ -395,7 +398,7 @@ function CreatePoolForm() {
CurrencyBalance.fromFloat(values.maxReserve, currency.decimals),
metadataValues,
],
{ createType: config.poolCreationType }
{ createType }
)
},
])
Expand All @@ -420,7 +423,7 @@ function CreatePoolForm() {
}, [isStoredIssuerLoading])

React.useEffect(() => {
if (config.poolCreationType === 'notePreimage') {
if (createType === 'notePreimage') {
const $events = centrifuge
.getEvents()
.pipe(
Expand All @@ -436,7 +439,7 @@ function CreatePoolForm() {
.subscribe()
return () => $events.unsubscribe()
}
}, [centrifuge])
}, [centrifuge, createType])

const formRef = React.useRef<HTMLFormElement>(null)
useFocusInvalidInput(form, formRef)
Expand Down

0 comments on commit bc39545

Please sign in to comment.