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

Deploy various improvements #1369

Merged
merged 4 commits into from
Sep 7, 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
2 changes: 1 addition & 1 deletion apps/dapp/.env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ NEXT_PUBLIC_WYND_REFERRAL_COMMISSION=0.01

# WebSockets API
NEXT_PUBLIC_WEB_SOCKET_PUSHER_APP_KEY=daodao
NEXT_PUBLIC_WEB_SOCKET_PUSHER_HOST=ws.indexer.zone
NEXT_PUBLIC_WEB_SOCKET_PUSHER_HOST=ws.daodao.zone
NEXT_PUBLIC_WEB_SOCKET_PUSHER_PORT=443
2 changes: 1 addition & 1 deletion apps/dapp/.env.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ NEXT_PUBLIC_WYND_REFERRAL_COMMISSION=0.01

# WebSockets API
NEXT_PUBLIC_WEB_SOCKET_PUSHER_APP_KEY=daodao
NEXT_PUBLIC_WEB_SOCKET_PUSHER_HOST=ws.indexer.zone
NEXT_PUBLIC_WEB_SOCKET_PUSHER_HOST=ws.daodao.zone
NEXT_PUBLIC_WEB_SOCKET_PUSHER_PORT=443
2 changes: 1 addition & 1 deletion apps/sda/.env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ NEXT_PUBLIC_WYND_REFERRAL_COMMISSION=0.01

# WebSockets API
NEXT_PUBLIC_WEB_SOCKET_PUSHER_APP_KEY=daodao
NEXT_PUBLIC_WEB_SOCKET_PUSHER_HOST=ws.indexer.zone
NEXT_PUBLIC_WEB_SOCKET_PUSHER_HOST=ws.daodao.zone
NEXT_PUBLIC_WEB_SOCKET_PUSHER_PORT=443
2 changes: 1 addition & 1 deletion apps/sda/.env.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ NEXT_PUBLIC_WYND_REFERRAL_COMMISSION=0.01

# WebSockets API
NEXT_PUBLIC_WEB_SOCKET_PUSHER_APP_KEY=daodao
NEXT_PUBLIC_WEB_SOCKET_PUSHER_HOST=ws.indexer.zone
NEXT_PUBLIC_WEB_SOCKET_PUSHER_HOST=ws.daodao.zone
NEXT_PUBLIC_WEB_SOCKET_PUSHER_PORT=443
15 changes: 15 additions & 0 deletions packages/state/recoil/selectors/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
} from '@dao-dao/types'
import {
MAINNET,
addressIsModule,
cosmWasmClientRouter,
cosmosSdkVersionIs47OrHigher,
cosmosValidatorToValidator,
Expand Down Expand Up @@ -890,6 +891,20 @@ export const moduleNameForAddressSelector = selectorFamily<
},
})

// Check whether or not the address is a module account.
export const addressIsModuleSelector = selectorFamily<
boolean,
WithChainId<{ address: string }>
>({
key: 'addressIsModule',
get:
({ address, chainId }) =>
async ({ get }) => {
const client = get(cosmosRpcClientForChainSelector(chainId))
return await addressIsModule(client, address)
},
})

// Get bonded and unbonded tokens. Bonded tokens represent all possible
// governance voting power.
export const chainStakingPoolSelector = selectorFamily<Pool, WithChainId<{}>>({
Expand Down
31 changes: 23 additions & 8 deletions packages/stateful/inbox/sources/OpenProposals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ProposalLineProps,
} from '../../../components/ProposalLine'
import { useOnWebSocketMessage, useWallet } from '../../../hooks'
import { followingDaosSelector } from '../../../recoil'
import { inboxOpenProposalsSelector } from './state'

export const OpenProposals: InboxSource<ProposalLineProps> = {
Expand All @@ -28,9 +29,11 @@ export const OpenProposals: InboxSource<ProposalLineProps> = {
const setRefresh = useSetRecoilState(refreshOpenProposalsAtom)
const refresh = useCallback(() => setRefresh((id) => id + 1), [setRefresh])

const chains = getSupportedChains()

const daosWithItemsLoadable = useCachedLoadable(
waitForAll(
getSupportedChains().map(({ chain }) =>
chains.map(({ chain }) =>
inboxOpenProposalsSelector({
chainId: chain.chain_id,
wallet:
Expand All @@ -45,19 +48,31 @@ export const OpenProposals: InboxSource<ProposalLineProps> = {
)
)

// Refresh when any proposal or vote is updated for any of the DAOs. Once
// the wallet votes, the item is no longer pending, so the inbox pending
// count needs to be updated.
const followingDaosLoadable = useCachedLoadable(
hexPublicKey.loading
? undefined
: waitForAll(
chains.map(({ chain }) =>
followingDaosSelector({
chainId: chain.chain_id,
walletPublicKey: hexPublicKey.data,
})
)
)
)

// Refresh when any proposal or vote is updated for any of the followed
// DAOs.
useOnWebSocketMessage(
daosWithItemsLoadable.state === 'hasValue'
? daosWithItemsLoadable.contents
.flat()
.map(({ chainId, coreAddress }) =>
followingDaosLoadable.state === 'hasValue'
? chains.flatMap(({ chain: { chain_id: chainId } }, index) =>
followingDaosLoadable.contents[index].map((coreAddress) =>
webSocketChannelNameForDao({
coreAddress,
chainId,
})
)
)
: [],
['proposal', 'vote'],
refresh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ const InnerProposalStatusAndInfo = ({
}
footer={
!polytoneState.loading &&
proposal.status === ProposalStatus.Executed && (
proposal.status === ProposalStatus.Executed &&
polytoneState.data.hasPolytoneMessages && (
<ProposalCrossChainRelayStatus state={polytoneState.data} />
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ const InnerProposalStatusAndInfo = ({
}
footer={
!polytoneState.loading &&
proposal.status === ProposalStatus.Executed && (
proposal.status === ProposalStatus.Executed &&
polytoneState.data.hasPolytoneMessages && (
<ProposalCrossChainRelayStatus state={polytoneState.data} />
)
}
Expand Down
179 changes: 104 additions & 75 deletions packages/stateful/recoil/selectors/dao/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RecoilValueReadOnly, selectorFamily, waitForAll } from 'recoil'

import {
DaoCoreV2Selectors,
addressIsModuleSelector,
contractInstantiateTimeSelector,
contractVersionSelector,
daoTvlSelector,
Expand All @@ -25,7 +26,10 @@ import {
} from '@dao-dao/types/contracts/DaoCore.v2'
import {
getChainForChainId,
getDisplayNameForChainId,
getFallbackImage,
getImageUrlForChainId,
getSupportedChainConfig,
isValidContractAddress,
parseContractVersion,
} from '@dao-dao/utils'
Expand Down Expand Up @@ -77,27 +81,99 @@ export const daoCardInfoSelector = selectorFamily<
if (
admin &&
// A DAO without a parent DAO may be its own admin.
admin !== coreAddress &&
// Ensure address is a contract.
isValidContractAddress(admin, getChainForChainId(chainId).bech32_prefix)
admin !== coreAddress
) {
// Indexer may return `adminInfo`, in which case don't query again. If
// null, there is no admin to load. Otherwise. If not null, query chain.
if ('adminInfo' in dumpedState) {
const { adminInfo } = dumpedState as IndexerDumpState
if (adminInfo) {
const {
admin: adminAdmin,
info,
config: { name, image_url },
registeredSubDao = false,
} = adminInfo
const coreVersion = info && parseContractVersion(info.version)
if (
// If address is a DAO contract.
isValidContractAddress(
admin,
getChainForChainId(chainId).bech32_prefix
)
) {
// Indexer may return `adminInfo`, in which case don't query again. If
// null, there is no admin to load. Otherwise. If not null, query
// chain.
if ('adminInfo' in dumpedState) {
const { adminInfo } = dumpedState as IndexerDumpState
if (adminInfo) {
const {
admin: adminAdmin,
info,
config: { name, image_url },
registeredSubDao = false,
} = adminInfo
const coreVersion = info && parseContractVersion(info.version)

if (coreVersion) {
parentDao = {
coreAddress: admin,
coreVersion,
name,
imageUrl: image_url || getFallbackImage(admin),
admin: adminAdmin ?? '',
registeredSubDao,
}
}
}
} else if (
get(
isContractSelector({
contractAddress: admin,
chainId,
names: [
// V1
'cw-core',
// V2
'cwd-core',
'dao-core',
],
})
)
) {
const adminAdmin = get(
DaoCoreV2Selectors.adminSelector({
contractAddress: admin,
chainId,
params: [],
})
)
const { version } = get(
DaoCoreV2Selectors.infoSelector({
contractAddress: admin,
chainId,
params: [],
})
).info
const adminVersion = parseContractVersion(version)

if (adminVersion) {
const {
name,
image_url,
}: CwCoreV1ConfigResponse | DaoCoreV2ConfigResponse = get(
// Both v1 and v2 have a config query.
DaoCoreV2Selectors.configSelector({
contractAddress: admin,
chainId,
params: [],
})
)

// Check if admin has registered the current DAO as a SubDAO.
const registeredSubDao =
adminVersion !== ContractVersion.V1
? get(
DaoCoreV2Selectors.listAllSubDaosSelector({
contractAddress: admin,
chainId,
})
).some(({ addr }) => addr === coreAddress)
: // V1 cannot have SubDAOs.
false

if (coreVersion) {
parentDao = {
coreAddress: admin,
coreVersion,
coreVersion: adminVersion,
name,
imageUrl: image_url || getFallbackImage(admin),
admin: adminAdmin ?? '',
Expand All @@ -107,68 +183,21 @@ export const daoCardInfoSelector = selectorFamily<
}
} else if (
get(
isContractSelector({
contractAddress: admin,
addressIsModuleSelector({
chainId,
names: [
// V1
'cw-core',
// V2
'cwd-core',
'dao-core',
],
address: admin,
})
)
) {
const adminAdmin = get(
DaoCoreV2Selectors.adminSelector({
contractAddress: admin,
chainId,
params: [],
})
)
const { version } = get(
DaoCoreV2Selectors.infoSelector({
contractAddress: admin,
chainId,
params: [],
})
).info
const adminVersion = parseContractVersion(version)

if (adminVersion) {
const {
name,
image_url,
}: CwCoreV1ConfigResponse | DaoCoreV2ConfigResponse = get(
// Both v1 and v2 have a config query.
DaoCoreV2Selectors.configSelector({
contractAddress: admin,
chainId,
params: [],
})
)

// Check if admin has registered the current DAO as a SubDAO.
const registeredSubDao =
adminVersion !== ContractVersion.V1
? get(
DaoCoreV2Selectors.listAllSubDaosSelector({
contractAddress: admin,
chainId,
})
).some(({ addr }) => addr === coreAddress)
: // V1 cannot have SubDAOs.
false

parentDao = {
coreAddress: admin,
coreVersion: adminVersion,
name,
imageUrl: image_url || getFallbackImage(admin),
admin: adminAdmin ?? '',
registeredSubDao,
}
// Chain module account.
const chainConfig = getSupportedChainConfig(chainId)
parentDao = chainConfig && {
coreAddress: chainConfig.name,
coreVersion: ContractVersion.Gov,
name: getDisplayNameForChainId(chainId),
imageUrl: getImageUrlForChainId(chainId),
admin: '',
registeredSubDao: false,
}
}
}
Expand Down
Loading
Loading