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

Various fixes #1441

Merged
merged 4 commits into from
Nov 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ export const makeUpgradeV1ToV2Action: ActionMaker<UpgradeV1ToV2Data> = ({
info: {
admin: { core_module: {} },
code_id: codeIds.DaoPreProposeSingle,
label: `DAO_${name}_pre-propose-${DaoProposalSingleAdapter.id}`,
label: `DAO_${name.trim()}_pre-propose-${
DaoProposalSingleAdapter.id
}`,
msg: Buffer.from(
JSON.stringify({
deposit_info: depositInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { coins } from '@cosmjs/amino'
import { coins } from '@cosmjs/stargate'
import { useCallback } from 'react'
import { useFormContext } from 'react-hook-form'
import { constSelector, useRecoilValue } from 'recoil'
Expand All @@ -15,7 +15,7 @@ import {
UseTransformToCosmos,
} from '@dao-dao/types/actions'
import {
convertDenomToMicroDenomWithDecimals,
convertDenomToMicroDenomStringWithDecimals,
convertMicroDenomToDenomWithDecimals,
decodePolytoneExecuteMsg,
isDecodedStargateMsg,
Expand Down Expand Up @@ -105,11 +105,6 @@ export const makeCommunityPoolDepositAction: ActionMaker<
throw new Error(`Unknown token: ${denom}`)
}

const microAmount = convertDenomToMicroDenomWithDecimals(
amount,
token.decimals
)

return maybeMakePolytoneExecuteMessage(
currentChainId,
chainId,
Expand All @@ -118,7 +113,13 @@ export const makeCommunityPoolDepositAction: ActionMaker<
typeUrl: MsgFundCommunityPool.typeUrl,
value: MsgFundCommunityPool.fromPartial({
depositor: address,
amount: coins(microAmount, denom),
amount: coins(
convertDenomToMicroDenomStringWithDecimals(
amount,
token.decimals
),
denom
),
}),
},
})
Expand Down
12 changes: 7 additions & 5 deletions packages/stateful/actions/core/treasury/ManageStaking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,13 @@ const InnerComponent: ActionComponent = (props) => {
: {
loading: false,
data: coin(
balances.data.find(
({ token: { chainId, denomOrAddress } }) =>
chainId === nativeToken.chainId &&
denomOrAddress === nativeToken.denomOrAddress
)?.balance ?? 0,
BigInt(
balances.data.find(
({ token: { chainId, denomOrAddress } }) =>
chainId === nativeToken.chainId &&
denomOrAddress === nativeToken.denomOrAddress
)?.balance ?? 0
).toString(),
nativeToken.denomOrAddress
),
}
Expand Down
9 changes: 5 additions & 4 deletions packages/stateful/actions/core/treasury/Spend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
UseTransformToCosmos,
} from '@dao-dao/types/actions'
import {
convertDenomToMicroDenomWithDecimals,
convertDenomToMicroDenomStringWithDecimals,
convertMicroDenomToDenomWithDecimals,
decodePolytoneExecuteMsg,
getChainForChainId,
Expand Down Expand Up @@ -155,9 +155,10 @@ const useTransformToCosmos: UseTransformToCosmos<SpendData> = () => {
throw new Error(`Unknown token: ${denom}`)
}

const amount = BigInt(
convertDenomToMicroDenomWithDecimals(_amount, token.decimals)
).toString()
const amount = convertDenomToMicroDenomStringWithDecimals(
_amount,
token.decimals
)

let msg: CosmosMsgForEmpty | undefined
if (toChainId !== fromChainId) {
Expand Down
9 changes: 5 additions & 4 deletions packages/stateful/actions/core/treasury/WyndSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { ExecuteSwapOperationsMsg } from '@dao-dao/types/contracts/WyndexMultiHo
import {
DAO_DAO_DAO_ADDRESS,
WYND_MULTI_HOP_CONTRACT,
convertDenomToMicroDenomStringWithDecimals,
convertDenomToMicroDenomWithDecimals,
convertMicroDenomToDenomWithDecimals,
encodeMessageAsBase64,
Expand Down Expand Up @@ -525,16 +526,16 @@ const useTransformToCosmos: UseTransformToCosmos<WyndSwapData> = () => {
return
}

const inAmount = convertDenomToMicroDenomWithDecimals(
const inAmount = convertDenomToMicroDenomStringWithDecimals(
tokenInAmount,
tokenIn.decimals
).toString()
)
const minOutAmount =
_minOutAmount !== undefined
? convertDenomToMicroDenomWithDecimals(
? convertDenomToMicroDenomStringWithDecimals(
_minOutAmount,
tokenOut.decimals
).toString()
)
: undefined

const msg: ExecuteSwapOperationsMsg = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
UseTransformToCosmos,
} from '@dao-dao/types/actions'
import {
convertDenomToMicroDenomWithDecimals,
convertDenomToMicroDenomStringWithDecimals,
encodeMessageAsBase64,
makeWasmMessage,
objectMatchesStructure,
Expand Down Expand Up @@ -141,10 +141,10 @@ const useTransformToCosmos: UseTransformToCosmos<PerformTokenSwapData> = () => {
}

// Convert amount to micro amount.
const amount = convertDenomToMicroDenomWithDecimals(
const amount = convertDenomToMicroDenomStringWithDecimals(
selfParty.amount,
selfParty.decimals
).toString()
)

return selfParty.type === 'cw20'
? makeWasmMessage({
Expand Down
12 changes: 9 additions & 3 deletions packages/stateful/components/SelfRelayExecuteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ export const SelfRelayExecuteModal = ({
{
bank: {
send: {
amount: coins(fundsNeeded, relayer.feeToken.denom),
amount: coins(
BigInt(fundsNeeded).toString(),
relayer.feeToken.denom
),
to_address: relayer.relayerAddress,
},
},
Expand Down Expand Up @@ -472,7 +475,10 @@ export const SelfRelayExecuteModal = ({
grant: {
authorization: SendAuthorization.toProtoMsg(
SendAuthorization.fromPartial({
spendLimit: coins(newBalance, relayer.feeToken.denom),
spendLimit: coins(
BigInt(newBalance).toString(),
relayer.feeToken.denom
),
})
),
expiration: {
Expand Down Expand Up @@ -837,7 +843,7 @@ export const SelfRelayExecuteModal = ({
await client.sign.sendTokens(
relayerAddress,
wallet.address,
coins(remainingTokensAfterFee, feeDenom),
coins(BigInt(remainingTokensAfterFee).toString(), feeDenom),
fee
)

Expand Down
6 changes: 3 additions & 3 deletions packages/stateful/components/WalletStakingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@dao-dao/stateless'
import {
CHAIN_GAS_MULTIPLIER,
convertDenomToMicroDenomWithDecimals,
convertDenomToMicroDenomStringWithDecimals,
convertMicroDenomToDenomWithDecimals,
cwMsgToEncodeObject,
processError,
Expand Down Expand Up @@ -110,10 +110,10 @@ export const WalletStakingModal = (props: WalletStakingModalProps) => {

setLoading(true)
try {
const microAmount = convertDenomToMicroDenomWithDecimals(
const microAmount = convertDenomToMicroDenomStringWithDecimals(
amount,
nativeToken.decimals
).toString()
)

if (mode === StakingMode.Stake) {
await signingCosmWasmClient.signAndBroadcast(
Expand Down
2 changes: 1 addition & 1 deletion packages/stateful/components/dao/CreateDaoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export const InnerCreateDaoForm = ({
automatically_add_cw721s: true,
description,
image_url: imageUrl ?? null,
name,
name: name.trim(),
proposal_modules_instantiate_info: proposalModuleInstantiateInfos,
// Placeholder. Should be replaced by creator's mutate function.
voting_module_instantiate_info: {
Expand Down
6 changes: 3 additions & 3 deletions packages/stateful/components/dao/DaoTokenDepositModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@dao-dao/stateless'
import {
CHAIN_GAS_MULTIPLIER,
convertDenomToMicroDenomWithDecimals,
convertDenomToMicroDenomStringWithDecimals,
convertMicroDenomToDenomWithDecimals,
processError,
} from '@dao-dao/utils'
Expand Down Expand Up @@ -101,10 +101,10 @@ export const DaoTokenDepositModal = ({

setLoading(true)
try {
const microAmount = convertDenomToMicroDenomWithDecimals(
const microAmount = convertDenomToMicroDenomStringWithDecimals(
amount,
token.decimals
).toString()
)

if (token.type === 'native') {
await signingCosmWasmClient.sendTokens(
Expand Down
4 changes: 2 additions & 2 deletions packages/stateful/components/gov/GovProposalStatusAndInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
} from '@dao-dao/types'
import {
CHAIN_GAS_MULTIPLIER,
convertDenomToMicroDenomWithDecimals,
convertDenomToMicroDenomStringWithDecimals,
convertMicroDenomToDenomWithDecimals,
formatPercentOf100,
getGovPath,
Expand Down Expand Up @@ -297,7 +297,7 @@ const InnerProposalStatusAndInfo = ({
proposalId: Long.fromString(proposalId.toString()),
depositor: walletAddress,
amount: coins(
convertDenomToMicroDenomWithDecimals(
convertDenomToMicroDenomStringWithDecimals(
depositValue,
depositToken.decimals
),
Expand Down
12 changes: 8 additions & 4 deletions packages/stateful/components/pages/MeBalances.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { waitForAll, waitForAllSettled } from 'recoil'
import { waitForAllSettled } from 'recoil'

import {
MeBalances as StatelessMeBalances,
Expand Down Expand Up @@ -28,7 +28,7 @@ export const MeBalances = () => {

const tokensWithoutLazyInfo = useCachedLoading(
walletAddress
? waitForAll(
? waitForAllSettled(
getSupportedChains().map(({ chain }) =>
walletTokenCardInfosSelector({
chainId: chain.chain_id,
Expand All @@ -45,7 +45,9 @@ export const MeBalances = () => {

const flattenedTokensWithoutLazyInfo = tokensWithoutLazyInfo.loading
? []
: tokensWithoutLazyInfo.data.flat()
: tokensWithoutLazyInfo.data.flatMap((loadable) =>
loadable.state === 'hasValue' ? loadable.contents : []
)

// Load separately so they cache separately.
const tokenLazyInfos = useCachedLoading(
Expand All @@ -64,7 +66,9 @@ export const MeBalances = () => {
)

const tokens: LoadingData<TokenCardInfo[]> =
tokensWithoutLazyInfo.loading || tokenLazyInfos.loading
tokensWithoutLazyInfo.loading ||
tokenLazyInfos.loading ||
flattenedTokensWithoutLazyInfo.length !== tokenLazyInfos.data.length
? {
loading: true,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/stateful/creators/MembershipBased/mutate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const mutate: DaoCreatorMutate<CreatorData> = (
msg.voting_module_instantiate_info = {
admin: { core_module: {} },
code_id: codeIds.DaoVotingCw4,
label: `DAO_${name}_${MembershipBasedCreatorId}`,
label: `DAO_${name.trim()}_${MembershipBasedCreatorId}`,
msg: Buffer.from(
JSON.stringify(votingModuleAdapterInstantiateMsg),
'utf8'
Expand Down
2 changes: 1 addition & 1 deletion packages/stateful/creators/NftBased/mutate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const mutate: DaoCreatorMutate<CreatorData> = (
msg.voting_module_instantiate_info = {
admin: { core_module: {} },
code_id: codeIds.DaoVotingCw721Staked,
label: `DAO_${daoName}_${NftBasedCreatorId}`,
label: `DAO_${daoName.trim()}_${NftBasedCreatorId}`,
msg: Buffer.from(
JSON.stringify(votingModuleAdapterInstantiateMsg),
'utf8'
Expand Down
2 changes: 1 addition & 1 deletion packages/stateful/creators/TokenBased/mutate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const mutate: DaoCreatorMutate<CreatorData> = (
msg.voting_module_instantiate_info = {
admin: { core_module: {} },
code_id: codeIds.DaoVotingTokenStaked,
label: `DAO_${daoName}_${TokenBasedCreatorId}`,
label: `DAO_${daoName.trim()}_${TokenBasedCreatorId}`,
msg: Buffer.from(
JSON.stringify(votingModuleAdapterInstantiateMsg),
'utf8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ export const makeUsePublishProposal =
// Native token deposit if exists.
const proposeFunds =
requiredProposalDeposit && depositInfoNativeTokenDenom
? coins(requiredProposalDeposit, depositInfoNativeTokenDenom)
? coins(
BigInt(requiredProposalDeposit).toString(),
depositInfoNativeTokenDenom
)
: undefined

// Recreate form data with just the expected fields to remove any fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const getInstantiateInfo: DaoCreationGetInstantiateInfo = (
info: {
admin: { core_module: {} },
code_id: codeIds.DaoPreProposeMultiple,
label: `DAO_${name}_pre-propose-${DaoProposalMultipleAdapterId}`,
label: `DAO_${name.trim()}_pre-propose-${DaoProposalMultipleAdapterId}`,
msg: Buffer.from(
JSON.stringify(preProposeMultipleInstantiateMsg),
'utf8'
Expand All @@ -112,7 +112,7 @@ export const getInstantiateInfo: DaoCreationGetInstantiateInfo = (
return {
admin: { core_module: {} },
code_id: codeIds.DaoProposalMultiple,
label: `DAO_${name}_${DaoProposalMultipleAdapterId}`,
label: `DAO_${name.trim()}_${DaoProposalMultipleAdapterId}`,
msg: Buffer.from(JSON.stringify(msg), 'utf8').toString('base64'),
// TODO(neutron-2.3.0): add back in here and in instantiate schema.
...(chainId !== ChainId.NeutronMainnet && {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ export const makeUsePublishProposal =
// Native token deposit if exists.
const proposeFunds =
requiredProposalDeposit && depositInfoNativeTokenDenom
? coins(requiredProposalDeposit, depositInfoNativeTokenDenom)
? coins(
BigInt(requiredProposalDeposit).toString(),
depositInfoNativeTokenDenom
)
: undefined

// Recreate form data with just the expected fields to remove any fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const getInstantiateInfo: DaoCreationGetInstantiateInfo<
info: {
admin: { core_module: {} },
code_id: codeIds.DaoPreProposeSingle,
label: `DAO_${name}_pre-propose-${DaoProposalSingleAdapterId}`,
label: `DAO_${name.trim()}_pre-propose-${DaoProposalSingleAdapterId}`,
msg: Buffer.from(
JSON.stringify(preProposeSingleInstantiateMsg),
'utf8'
Expand All @@ -115,7 +115,7 @@ export const getInstantiateInfo: DaoCreationGetInstantiateInfo<
return {
admin: { core_module: {} },
code_id: codeIds.DaoProposalSingle,
label: `DAO_${name}_${DaoProposalSingleAdapterId}`,
label: `DAO_${name.trim()}_${DaoProposalSingleAdapterId}`,
msg: Buffer.from(JSON.stringify(msg), 'utf8').toString('base64'),
// TODO(neutron-2.3.0): add back in here and in instantiate schema.
...(chainId !== ChainId.NeutronMainnet && {
Expand Down
Loading
Loading