Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Press and support cross-chain Presses #1456

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"createAProposal": "Create a proposal",
"createAToken": "Create a token",
"createAccount": "Create account",
"createCrossChainAccount": "Create cross-chain account",
"createDAO": "Create DAO",
"createNftCollection": "Create NFT collection",
"createSubDao": "Create SubDAO",
Expand Down Expand Up @@ -397,8 +398,10 @@
"proposalNotFound": "Proposal not found.",
"relayerAlreadySetUp": "Relayer already set up.",
"relayerNotSetUp": "Relayer not set up.",
"selectAChainToContinue": "Select a chain to continue.",
"simulationFailedInvalidProposalActions": "Simulation failed. Verify your proposal actions are valid.",
"stakeInsufficient": "The DAO has {{amount}} ${{tokenSymbol}} staked, which is insufficient.",
"stargazeDaoNoCrossChainAccountsForPress": "This Stargaze DAO has no cross-chain accounts, and Press does not work on Stargaze. Create a cross-chain account for the DAO before setting up Press.",
"subDaoAlreadyExists": "SubDAO already exists.",
"tokenSwapContractNotChosen": "You must create a token swap or enter the address of an existing token swap before using this action.",
"tooFewChoices": "The proposal must have at least two choices.",
Expand Down Expand Up @@ -762,7 +765,7 @@
"createNftCollectionDescription_gov": "Create a new NFT collection controlled by the chain.",
"createNftCollectionDescription_wallet": "Create a new NFT collection controlled by you.",
"createPostDescription": "Create a post on the DAO's press.",
"createPressContract": "To publish content, you must first create a press contract.",
"createPressContract": "To set up Press, you must first create a smart contract to manage it.",
"createStep1": "Pick a DAO type and name it",
"createStep2": "Governance configuration",
"createStep3": "Voting configuration",
Expand Down Expand Up @@ -978,6 +981,7 @@
"searchMessages": "Search messages",
"searchNftsPlaceholder": "Find an NFT...",
"searchValidatorsPlaceholder": "Find a validator...",
"selectPressChain": "Each post will be minted as an NFT on this chain and then deposited into the DAO's treasury.",
"selfRelayDescription": "One or more messages in this proposal require self-relaying across chains since automatic relayers do not exist or are inactive right now.",
"setUpDiscordNotificationsTooltip": "Set up Discord notifications",
"signedInAs": "Signed in as {{name}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ const Component: ActionComponent<undefined, GovernanceVoteData> = (props) => {
: constSelector(undefined)
)

const address = getChainAddressForActionOptions(options, chainId)
const existingVotesLoading = loadableToLoadingData(
useRecoilValueLoadable(
proposalId
proposalId && address
? govProposalVoteSelector({
proposalId: Number(proposalId),
voter: getChainAddressForActionOptions(options, chainId),
voter: address,
chainId,
})
: constSelector(undefined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const makeValidatorActionsAction: ActionMaker<ValidatorActionsData> = (

const getValidatorAddress = (chainId: string) =>
toValidatorAddress(
getChainAddressForActionOptions(options, chainId),
getChainAddressForActionOptions(options, chainId) || '',
getChainForChainId(chainId).bech32_prefix
)

Expand Down Expand Up @@ -181,8 +181,11 @@ export const makeValidatorActionsAction: ActionMaker<ValidatorActionsData> = (

const data = useDefaults()

// Check this is a stargate message.
if (!isDecodedStargateMsg(msg)) {
if (
!thisAddress ||
// Check this is a stargate message.
!isDecodedStargateMsg(msg)
) {
return { match: false }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export const makeCreateNftCollectionAction: ActionMaker<
}

const creator = getChainAddressForActionOptions(options, chainId)
if (!creator) {
throw new Error(t('error.loadingData'))
}

return maybeMakePolytoneExecuteMessage(
currentChainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,19 @@ export const InstantiateNftCollection: ActionComponent = (props) => {
toast.error(t('error.loadingData'))
return
}

if (!walletAddress) {
toast.error(t('error.logInToContinue'))
return
}

if (!codeIds.Cw721Base) {
const minter = getChainAddressForActionOptions(options, chainId)
if (!codeIds.Cw721Base || !minter) {
toast.error(t('error.invalidChain'))
return
}

const signingCosmWasmClient = await getSigningCosmWasmClient()

setInstantiating(true)
try {
const minter = getChainAddressForActionOptions(options, chainId)
const signingCosmWasmClient = await getSigningCosmWasmClient()
const contractAddress = await instantiateSmartContract(
signingCosmWasmClient,
walletAddress,
Expand Down
3 changes: 2 additions & 1 deletion packages/stateful/actions/core/nfts/MintNft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const Component: ActionComponent<undefined, MintNftData> = (props) => {
fieldName={props.fieldNamePrefix + 'chainId'}
onChange={(chainId) => {
// Update recipient to correct address.
const newAddress = getChainAddressForActionOptions(options, chainId)
const newAddress =
getChainAddressForActionOptions(options, chainId) || ''

setValue(
(props.fieldNamePrefix + 'mintMsg.owner') as 'mintMsg.owner',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const Component: ActionComponent = (props) => {
setValue((props.fieldNamePrefix + 'funds') as 'funds', [])
setValue(
(props.fieldNamePrefix + 'admin') as 'admin',
getChainAddressForActionOptions(options, chainId)
getChainAddressForActionOptions(options, chainId) || ''
)
}}
/>
Expand Down
19 changes: 9 additions & 10 deletions packages/stateful/actions/core/treasury/ManageStaking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { coin, parseCoins } from '@cosmjs/amino'
import { useCallback } from 'react'
import { useFormContext } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { constSelector } from 'recoil'

import {
nativeDelegationInfoSelector,
Expand Down Expand Up @@ -189,8 +190,6 @@ const InnerComponent: ActionComponent = (props) => {
throw new Error(t('error.missingNativeToken'))
}

const address = getChainAddressForActionOptions(options, chainId)

// These need to be loaded via cached loadables to avoid displaying a loader
// when this data updates on a schedule. Manually trigger a suspense loader
// the first time when the initial data is still loading.
Expand All @@ -215,15 +214,15 @@ const InnerComponent: ActionComponent = (props) => {
),
}

const address = getChainAddressForActionOptions(options, chainId)
const loadingNativeDelegationInfo = useCachedLoading(
nativeDelegationInfoSelector({
chainId,
address,
}),
{
delegations: [],
unbondingDelegations: [],
}
address
? nativeDelegationInfoSelector({
chainId,
address,
})
: constSelector(undefined),
undefined
)

const loadingValidators = useCachedLoading(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ export const InstantiateTokenSwap: ActionComponent<
return
}

const signingCosmWasmClient = await getSigningCosmWasmClient()

setInstantiating(true)

try {
const instantiateMsg: InstantiateMsg = {
counterparty_one: {
Expand Down Expand Up @@ -110,6 +107,7 @@ export const InstantiateTokenSwap: ActionComponent<
},
}

const signingCosmWasmClient = await getSigningCosmWasmClient()
const contractAddress = await instantiateSmartContract(
signingCosmWasmClient,
walletAddress,
Expand Down
4 changes: 2 additions & 2 deletions packages/stateful/components/StargazeNftImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ export const InnerStargazeNftImportModal = ({
return
}

const signingCosmWasmClient = await getSigningCosmWasmClient()

setLoading(true)
try {
const signingCosmWasmClient = await getSigningCosmWasmClient()

const selectedNfts = nfts.data.filter((nft) =>
selected.includes(getIdForNft(nft))
)
Expand Down
4 changes: 2 additions & 2 deletions packages/stateful/components/WalletStakingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ export const WalletStakingModal = (props: WalletStakingModalProps) => {
return
}

const signingCosmWasmClient = await getSigningCosmWasmClient()

setLoading(true)
try {
const signingCosmWasmClient = await getSigningCosmWasmClient()

const microAmount = convertDenomToMicroDenomStringWithDecimals(
amount,
nativeToken.decimals
Expand Down
3 changes: 1 addition & 2 deletions packages/stateful/components/WalletTokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ export const WalletTokenCard = (props: TokenCardInfo) => {
return
}

const signingCosmWasmClient = await getSigningCosmWasmClient()

setClaimLoading(true)
try {
const signingCosmWasmClient = await getSigningCosmWasmClient()
await signingCosmWasmClient.signAndBroadcast(
walletAddress,
(lazyInfo.loading ? [] : lazyInfo.data.stakingInfo!.stakes).map(
Expand Down
3 changes: 1 addition & 2 deletions packages/stateful/components/dao/DaoTokenDepositModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export const DaoTokenDepositModal = ({
return
}

const signingCosmWasmClient = await getSigningCosmWasmClient()

setLoading(true)
try {
const microAmount = convertDenomToMicroDenomStringWithDecimals(
Expand All @@ -107,6 +105,7 @@ export const DaoTokenDepositModal = ({
)

if (token.type === 'native') {
const signingCosmWasmClient = await getSigningCosmWasmClient()
await signingCosmWasmClient.sendTokens(
address,
depositAddress,
Expand Down
3 changes: 1 addition & 2 deletions packages/stateful/components/pages/MeTransactionBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ export const MeTransactionBuilder = () => {
return
}

const signingCosmWasmClient = await getSigningCosmWasmClient()

setLoading(true)
setError('')
setTxHash('')

try {
const signingCosmWasmClient = await getSigningCosmWasmClient()
const encodeObjects = data.map((msg) =>
cwMsgToEncodeObject(msg, walletAddress)
)
Expand Down
3 changes: 1 addition & 2 deletions packages/stateful/hooks/useInstantiateAndExecute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ export const useInstantiateAndExecute = (
throw new Error(t('error.logInToContinue'))
}

const signingCosmWasmClient = await getSigningCosmWasmClient()

// Get the checksum of the contract code.
const checksum = fromHex(codeDetailsLoadable.contents.checksum)
// Random salt.
Expand Down Expand Up @@ -118,6 +116,7 @@ export const useInstantiateAndExecute = (
),
]

const signingCosmWasmClient = await getSigningCosmWasmClient()
const response = (await signingCosmWasmClient.signAndBroadcast(
address,
messages.map((msg) => cwMsgToEncodeObject(msg, address)),
Expand Down
23 changes: 11 additions & 12 deletions packages/stateful/widgets/core.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { ChainId, Widget } from '@dao-dao/types'
import { Widget } from '@dao-dao/types'

import {
PressWidget,
RetroactiveCompensationWidget,
VestingPaymentsWidget,
WyndDepositWidget,
} from './widgets'

// Add widgets here.
export const getWidgets = (chainId: string): readonly Widget[] => [
// MintNftWidget,

VestingPaymentsWidget,
RetroactiveCompensationWidget,
PressWidget,

// WYND only available on Juno mainnet.
...(chainId === ChainId.JunoMainnet ? [WyndDepositWidget] : []),
]
export const getWidgets = (chainId: string): readonly Widget[] =>
[
// MintNftWidget,
VestingPaymentsWidget,
RetroactiveCompensationWidget,
PressWidget,
].filter(
(widget) =>
!widget.supportedChainIds || widget.supportedChainIds.includes(chainId)
)

export const getWidgetById = (chainId: string, id: string) =>
getWidgets(chainId).find((widget) => widget.id === id)
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ export const MintNftRenderer = ({
return
}

const signingCosmWasmClient = await getSigningCosmWasmClient()

setMinting(true)
try {
const signingCosmWasmClient = await getSigningCosmWasmClient()
await signingCosmWasmClient.execute(
walletAddress,
contract,
Expand Down
Loading
Loading