-
Notifications
You must be signed in to change notification settings - Fork 22
/
url.ts
90 lines (79 loc) · 2.22 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
import queryString from 'query-string'
import { ActionKeyAndDataNoId, DaoPageMode, DaoTabId } from '@dao-dao/types'
import { DaoProposalSingleAdapterId } from './constants/adapters'
import { encodeJsonToBase64 } from './messages'
// 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 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 profile transaction builder with a pre-filled
// transaction form.
export const getActionBuilderPrefillPath = (
actions: ActionKeyAndDataNoId[]
) => {
const base = '/actions'
const query = `?${queryString.stringify({
prefill: encodeJsonToBase64({
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?: ActionKeyAndDataNoId[]
title?: string
description?: string
}): string =>
encodeJsonToBase64({
id: DaoProposalSingleAdapterId,
data: {
title,
description,
actionData: actions.map((action, index) => ({
_id: index.toString(),
...action,
})),
},
})