-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathProposalLine.tsx
85 lines (75 loc) · 2 KB
/
ProposalLine.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { useTranslation } from 'react-i18next'
import { LineLoader, StatusCard, useDaoIfAvailable } from '@dao-dao/stateless'
import { StatefulProposalLineProps } from '@dao-dao/types'
import {
ProposalModuleAdapterProvider,
useProposalModuleAdapter,
} from '../proposal-module-adapter'
import { DaoProviders } from './dao'
import { LinkWrapper } from './LinkWrapper'
import { SuspenseLoader } from './SuspenseLoader'
export const ProposalLine = ({
chainId,
coreAddress,
...props
}: StatefulProposalLineProps) => {
const existingDao = useDaoIfAvailable()
const content = (
<ProposalModuleAdapterProvider proposalId={props.proposalId}>
<InnerProposalLine {...props} />
</ProposalModuleAdapterProvider>
)
// If already in this DAO's context, no need to wrap in another provider.
if (
existingDao &&
existingDao.chainId === chainId &&
existingDao.coreAddress === coreAddress
) {
return content
}
return (
<DaoProviders
chainId={chainId}
coreAddress={coreAddress}
loaderFallback={<LineLoader type="proposal" />}
>
{content}
</DaoProviders>
)
}
type InnerProposalLineProps = Pick<
StatefulProposalLineProps,
'proposalId' | 'proposalViewUrl' | 'onClick' | 'openInNewTab'
>
const InnerProposalLine = ({
proposalId,
proposalViewUrl,
onClick,
openInNewTab,
}: InnerProposalLineProps) => {
const { t } = useTranslation()
const {
components: { ProposalLine, PreProposeApprovalProposalLine },
} = useProposalModuleAdapter()
const Component = proposalId.includes('*')
? PreProposeApprovalProposalLine
: ProposalLine
if (!Component) {
return (
<StatusCard
content={t('error.unsupportedApprovalFailedRender')}
style="warning"
/>
)
}
return (
<SuspenseLoader fallback={<LineLoader type="proposal" />}>
<Component
LinkWrapper={LinkWrapper}
href={proposalViewUrl}
onClick={onClick}
openInNewTab={openInNewTab}
/>
</SuspenseLoader>
)
}