forked from akure/dao-dao-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.ts
117 lines (102 loc) · 2.81 KB
/
url.ts
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import queryString from 'query-string'
import {
DaoPageMode,
DaoTabId,
PartialCategorizedActionKeyAndDataNoId,
} from '@dao-dao/types'
import { DaoProposalSingleAdapterId } from './constants/adapters'
// Create a path to a DAO page based on the app's page mode.
export const getDaoPath = (
mode: DaoPageMode,
coreAddress: string,
path?: string,
params?: Record<string, unknown>
) => {
const base =
(mode === DaoPageMode.Dapp ? `/dao/${coreAddress}` : `/${coreAddress}`) +
(path ? `/${path}` : '')
const query = params ? `?${queryString.stringify(params)}` : ''
return base + query
}
// Create a path to a DAO proposal page based on the app's page mode.
export const getDaoProposalPath = (
mode: DaoPageMode,
coreAddress: string,
proposalId: string,
params?: Record<string, unknown>
) => {
const base = getDaoPath(
mode,
coreAddress,
`${DaoTabId.Proposals}/${proposalId}`
)
const query = params ? `?${queryString.stringify(params)}` : ''
return base + query
}
// Create a path to a gov page.
export const getGovPath = (
chain: string,
path?: string,
params?: Record<string, unknown>
) => {
const base = `/gov/${chain}` + (path ? `/${path}` : '')
const query = params ? `?${queryString.stringify(params)}` : ''
return base + query
}
// Create a path to a gov proposal page.
export const getGovProposalPath = (
chain: string,
proposalId: string,
params?: Record<string, unknown>
) => {
const base = getGovPath(chain, `${DaoTabId.Proposals}/${proposalId}`)
const query = params ? `?${queryString.stringify(params)}` : ''
return base + query
}
// Create a path to an account's page.
export const getAccountPath = (
address: string,
path?: string,
params?: Record<string, unknown>
) => {
const base = `/account/${address}` + (path ? `/${path}` : '')
const query = params ? `?${queryString.stringify(params)}` : ''
return base + query
}
// Create a path for the Me page transaction builder with a pre-filled
// transaction form.
export const getMeTxPrefillPath = (
actions: PartialCategorizedActionKeyAndDataNoId[]
) => {
const base = '/me/tx'
const query = `?${queryString.stringify({
prefill: JSON.stringify({
actions: actions.map((action, index) => ({
_id: index.toString(),
...action,
})),
}),
})}`
return base + query
}
// Create prefill URL parameter for a DAO's single choice proposal module.
export const getDaoProposalSinglePrefill = ({
title = '',
description = '',
actions = [],
}: {
actions?: PartialCategorizedActionKeyAndDataNoId[]
title?: string
description?: string
}): string =>
JSON.stringify({
id: DaoProposalSingleAdapterId,
data: {
title,
description,
actionData: actions.map((action, index) => ({
_id: index.toString(),
...action,
})),
},
})