Skip to content

Commit

Permalink
use token factory tokens for bitsong instead of cw20
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed May 20, 2024
1 parent a1428e2 commit dca38c3
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 45 deletions.
4 changes: 2 additions & 2 deletions packages/stateful/components/dao/CreateDaoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const InnerCreateDaoForm = ({
cached.creator.data = merge(
{},
// Start with defaults.
creator?.defaultConfig,
creator?.makeDefaultConfig(chainContext.config),
// Overwrite with existing values.
cached.creator.data
)
Expand Down Expand Up @@ -238,7 +238,7 @@ export const InnerCreateDaoForm = ({
// Use overrides passed into component.
override
)
}, [_newDaoAtom, chainId, override])
}, [_newDaoAtom, chainContext.config, chainId, override])

const form = useForm<NewDao>({
defaultValues: defaultForm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
InputErrorMessage,
VotingPowerDistribution,
VotingPowerDistributionEntry,
useSupportedChainContext,
} from '@dao-dao/stateless'
import {
CreateDaoCustomValidator,
Expand Down Expand Up @@ -39,6 +40,7 @@ export const GovernanceConfigurationInput = ({
}: DaoCreationGovernanceConfigInputProps<CreatorData>) => {
const { t } = useTranslation()
const { address: walletAddress, isWalletConnected } = useWallet()
const { config: chainConfig } = useSupportedChainContext()

const {
fields: tierFields,
Expand All @@ -51,13 +53,15 @@ export const GovernanceConfigurationInput = ({

const addTierRef = useRef<HTMLButtonElement>(null)
const addTier = useCallback(() => {
appendTier(cloneDeep(MembershipBasedCreator.defaultConfig.tiers[0]))
appendTier(
cloneDeep(MembershipBasedCreator.makeDefaultConfig(chainConfig).tiers[0])
)
// Scroll button to bottom of screen.
addTierRef.current?.scrollIntoView({
behavior: 'smooth',
block: 'end',
})
}, [appendTier])
}, [appendTier, chainConfig])

// Fill in default first tier info if tiers not yet edited.
const [loadedPage, setLoadedPage] = useState(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { useForm } from 'react-hook-form'

import { CHAIN_ID } from '@dao-dao/storybook'
import { NewDao } from '@dao-dao/types'
import { MembershipBasedCreatorId } from '@dao-dao/utils'
import {
MembershipBasedCreatorId,
getSupportedChainConfig,
} from '@dao-dao/utils'

import { MembershipBasedCreator } from '.'
import { makeDefaultNewDao } from '../../recoil/atoms'
Expand All @@ -28,7 +31,9 @@ const Template: ComponentStory<typeof TierCard> = (args) => {
...makeDefaultNewDao(CHAIN_ID),
creator: {
id: MembershipBasedCreatorId,
data: MembershipBasedCreator.defaultConfig,
data: MembershipBasedCreator.makeDefaultConfig(
getSupportedChainConfig(CHAIN_ID)!
),
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/stateful/creators/MembershipBased/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const MembershipBasedCreator: DaoCreator = {
suppliesI18nKey: 'daoCreator.MembershipBased.supplies',
membershipI18nKey: 'daoCreator.MembershipBased.membership',
},
defaultConfig: {
makeDefaultConfig: () => ({
tiers: [
{
name: '',
Expand All @@ -27,7 +27,7 @@ export const MembershipBasedCreator: DaoCreator = {
],
},
],
},
}),
governanceConfig: {
Input: GovernanceConfigurationInput,
Review: GovernanceConfigurationReview,
Expand Down
4 changes: 2 additions & 2 deletions packages/stateful/creators/NftBased/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export const NftBasedCreator: DaoCreator = {
suppliesI18nKey: 'daoCreator.NftBased.supplies',
membershipI18nKey: 'daoCreator.NftBased.membership',
},
defaultConfig: {
makeDefaultConfig: () => ({
tokenType: GovernanceTokenType.Existing,
existingGovernanceTokenDenomOrAddress: '',
unstakingDuration: {
value: 2,
units: DurationUnits.Weeks,
},
},
}),
governanceConfig: {
Input: GovernanceConfigurationInput,
Review: GovernanceConfigurationReview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export const GovernanceConfigurationInput = ({

const {
chain: { chain_id: chainId, bech32_prefix: bech32Prefix },
config: { createWithCw20 },
config,
} = useSupportedChainContext()
const isCw20 = !!createWithCw20
const isCw20 = !!config.createWithCw20

const {
fields: tierFields,
Expand All @@ -89,13 +89,13 @@ export const GovernanceConfigurationInput = ({

const addTierRef = useRef<HTMLButtonElement>(null)
const addTier = useCallback(() => {
appendTier(cloneDeep(TokenBasedCreator.defaultConfig.tiers[0]))
appendTier(cloneDeep(TokenBasedCreator.makeDefaultConfig(config).tiers[0]))
// Scroll button to bottom of screen.
addTierRef.current?.scrollIntoView({
behavior: 'smooth',
block: 'end',
})
}, [appendTier])
}, [appendTier, config])

// Load token factory denom creation fee.
const tokenFactoryDenomCreationFeeLoading = useCachedLoading(
Expand Down Expand Up @@ -323,13 +323,18 @@ export const GovernanceConfigurationInput = ({
<>
<SegmentedControls
className="mt-8 mb-4 w-max"
disabled={config.noCreateNewTokens}
onSelect={(tokenType) => setValue('creator.data.tokenType', tokenType)}
selected={data.tokenType}
tabs={[
{
label: t('button.createAToken'),
value: GovernanceTokenType.New,
},
...(config.noCreateNewTokens
? []
: [
{
label: t('button.createAToken'),
value: GovernanceTokenType.New,
},
]),
{
label: t('button.useExistingToken'),
value: GovernanceTokenType.Existing,
Expand Down
6 changes: 4 additions & 2 deletions packages/stateful/creators/TokenBased/TierCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useForm } from 'react-hook-form'

import { CHAIN_ID } from '@dao-dao/storybook'
import { NewDao } from '@dao-dao/types'
import { TokenBasedCreatorId } from '@dao-dao/utils'
import { TokenBasedCreatorId, getSupportedChainConfig } from '@dao-dao/utils'

import { TokenBasedCreator } from '.'
import { makeDefaultNewDao } from '../../recoil/atoms'
Expand All @@ -27,7 +27,9 @@ const Template: ComponentStory<typeof TierCard> = (args) => {
...makeDefaultNewDao(CHAIN_ID),
creator: {
id: TokenBasedCreatorId,
data: TokenBasedCreator.defaultConfig,
data: TokenBasedCreator.makeDefaultConfig(
getSupportedChainConfig(CHAIN_ID)!
),
},
},
})
Expand Down
8 changes: 5 additions & 3 deletions packages/stateful/creators/TokenBased/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const TokenBasedCreator: DaoCreator<CreatorData> = {
suppliesI18nKey: 'daoCreator.TokenBased.supplies',
membershipI18nKey: 'daoCreator.TokenBased.membership',
},
defaultConfig: {
makeDefaultConfig: ({ noCreateNewTokens = false }) => ({
tiers: [
{
name: '',
Expand All @@ -30,7 +30,9 @@ export const TokenBasedCreator: DaoCreator<CreatorData> = {
],
},
],
tokenType: GovernanceTokenType.New,
tokenType: noCreateNewTokens
? GovernanceTokenType.Existing
: GovernanceTokenType.New,
newInfo: {
initialSupply: 10000000,
initialTreasuryPercent: 90,
Expand All @@ -47,7 +49,7 @@ export const TokenBasedCreator: DaoCreator<CreatorData> = {
type: 'percent',
value: 10,
},
},
}),
governanceConfig: {
Input: GovernanceConfigurationInput,
Review: GovernanceConfigurationReview,
Expand Down
7 changes: 6 additions & 1 deletion packages/stateful/recoil/atoms/newDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
MembershipBasedCreatorId,
convertCosmosVetoConfigToVeto,
getNativeTokenForChainId,
getSupportedChainConfig,
} from '@dao-dao/utils'

import { MembershipBasedCreator } from '../../creators/MembershipBased'
Expand All @@ -31,7 +32,11 @@ export const makeDefaultNewDao = (chainId: string): NewDao => ({
imageUrl: undefined,
creator: {
id: MembershipBasedCreatorId,
data: cloneDeep(MembershipBasedCreator.defaultConfig),
data: cloneDeep(
MembershipBasedCreator.makeDefaultConfig(
getSupportedChainConfig(chainId)!
)
),
},
// Default to single and multiple choice proposal configuration.
proposalModuleAdapters: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ComponentMeta, ComponentStory } from '@storybook/react'

import { TokenBasedCreator } from '@dao-dao/stateful/creators/TokenBased'
import { CHAIN_ID } from '@dao-dao/storybook'
import {
WalletProviderDecorator,
makeCreateDaoFormDecorator,
makeDappLayoutDecorator,
} from '@dao-dao/storybook/decorators'
import { TokenBasedCreatorId } from '@dao-dao/utils'
import { TokenBasedCreatorId, getSupportedChainConfig } from '@dao-dao/utils'

import { CreateDaoGovernance } from './CreateDaoGovernance'

Expand All @@ -23,7 +24,9 @@ export default {
'https://ipfs.stargaze.zone/ipfs/QmbGvE3wmxex8KiBbbvMjR8f9adR28s3XkiZSTuGmHoMHV/33.jpg',
creator: {
id: TokenBasedCreatorId,
data: TokenBasedCreator.defaultConfig,
data: TokenBasedCreator.makeDefaultConfig(
getSupportedChainConfig(CHAIN_ID)!
),
},
}),
makeDappLayoutDecorator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'

import { TokenBasedCreator } from '@dao-dao/stateful/creators/TokenBased'
import { DaoProposalSingleAdapter } from '@dao-dao/stateful/proposal-module-adapter/adapters/DaoProposalSingle'
import { CHAIN_ID } from '@dao-dao/storybook'
import { WalletProviderDecorator } from '@dao-dao/storybook/decorators'
import { makeCreateDaoFormDecorator } from '@dao-dao/storybook/decorators/makeCreateDaoFormDecorator'
import { makeDappLayoutDecorator } from '@dao-dao/storybook/decorators/makeDappLayoutDecorator'
import { DaoProposalSingleAdapterId, TokenBasedCreatorId } from '@dao-dao/utils'
import {
DaoProposalSingleAdapterId,
TokenBasedCreatorId,
getSupportedChainConfig,
} from '@dao-dao/utils'

import { CreateDaoReview } from './CreateDaoReview'

Expand All @@ -23,9 +28,13 @@ export default {
creator: {
id: TokenBasedCreatorId,
data: {
...TokenBasedCreator.defaultConfig,
...TokenBasedCreator.makeDefaultConfig(
getSupportedChainConfig(CHAIN_ID)!
),
newInfo: {
...TokenBasedCreator.defaultConfig.newInfo,
...TokenBasedCreator.makeDefaultConfig(
getSupportedChainConfig(CHAIN_ID)!
).newInfo,
symbol: 'TST',
name: 'Test Token',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'

import { TokenBasedCreator } from '@dao-dao/stateful/creators/TokenBased'
import { DaoProposalSingleAdapter } from '@dao-dao/stateful/proposal-module-adapter'
import { CHAIN_ID } from '@dao-dao/storybook'
import {
WalletProviderDecorator,
makeCreateDaoFormDecorator,
makeDappLayoutDecorator,
} from '@dao-dao/storybook/decorators'
import { DaoProposalSingleAdapterId, TokenBasedCreatorId } from '@dao-dao/utils'
import {
DaoProposalSingleAdapterId,
TokenBasedCreatorId,
getSupportedChainConfig,
} from '@dao-dao/utils'

import { CreateDaoStart } from './CreateDaoStart'

Expand All @@ -21,9 +26,13 @@ export default {
creator: {
id: TokenBasedCreatorId,
data: {
...TokenBasedCreator.defaultConfig,
...TokenBasedCreator.makeDefaultConfig(
getSupportedChainConfig(CHAIN_ID)!
),
newInfo: {
...TokenBasedCreator.defaultConfig.newInfo,
...TokenBasedCreator.makeDefaultConfig(
getSupportedChainConfig(CHAIN_ID)!
).newInfo,
symbol: 'TST',
name: 'Test Token',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
validateRequired,
} from '@dao-dao/utils'

import { useSupportedChainContext } from '../../../../hooks'
import { Button } from '../../../buttons'
import { InputErrorMessage, TextAreaInput, TextInput } from '../../../inputs'
import { DaoCreatorCard } from '../DaoCreatorCard'
Expand All @@ -32,6 +33,7 @@ export const CreateDaoStart = ({
}: CreateDaoContext) => {
const { t } = useTranslation()
const daoChainId = watch('chainId')
const { config: chainConfig } = useSupportedChainContext()

const data = watch()

Expand Down Expand Up @@ -125,7 +127,7 @@ export const CreateDaoStart = ({
suppliesI18nKey,
membershipI18nKey,
},
defaultConfig,
makeDefaultConfig,
}) => (
<DaoCreatorCard
key={id}
Expand All @@ -137,7 +139,7 @@ export const CreateDaoStart = ({
resetField('creator', {
defaultValue: {
id,
data: cloneDeep(defaultConfig),
data: cloneDeep(makeDefaultConfig(chainConfig)),
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'

import { TokenBasedCreator } from '@dao-dao/stateful/creators/TokenBased'
import { DaoProposalSingleAdapter } from '@dao-dao/stateful/proposal-module-adapter'
import { CHAIN_ID } from '@dao-dao/storybook'
import { WalletProviderDecorator } from '@dao-dao/storybook/decorators'
import { makeCreateDaoFormDecorator } from '@dao-dao/storybook/decorators/makeCreateDaoFormDecorator'
import { makeDappLayoutDecorator } from '@dao-dao/storybook/decorators/makeDappLayoutDecorator'
import { DaoProposalSingleAdapterId, TokenBasedCreatorId } from '@dao-dao/utils'
import {
DaoProposalSingleAdapterId,
TokenBasedCreatorId,
getSupportedChainConfig,
} from '@dao-dao/utils'

import { CreateDaoVoting } from './CreateDaoVoting'

Expand All @@ -23,9 +28,13 @@ export default {
creator: {
id: TokenBasedCreatorId,
data: {
...TokenBasedCreator.defaultConfig,
...TokenBasedCreator.makeDefaultConfig(
getSupportedChainConfig(CHAIN_ID)!
),
newInfo: {
...TokenBasedCreator.defaultConfig.newInfo,
...TokenBasedCreator.makeDefaultConfig(
getSupportedChainConfig(CHAIN_ID)!
).newInfo,
symbol: 'TST',
name: 'Test Token',
},
Expand Down
Loading

0 comments on commit dca38c3

Please sign in to comment.