-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.jsx
41 lines (39 loc) · 1.11 KB
/
common.jsx
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
const contractAccountId =
props.contractAccountId ||
(context.widgetSrc ?? "web4_profile.testnet").split("/", 1)[0];
const widgetAccountId =
props.widgetAccountId ||
(context.widgetSrc ?? "web4_profile.testnet").split("/", 1)[0];
function widget(widgetName, widgetProps, key) {
widgetProps = {
...widgetProps,
contractAccountId: props.contractAccountId,
widgetAccountId: props.widgetAccountId,
referral: props.referral,
};
return (
<Widget
src={`${widgetAccountId}/widget/${widgetName}`}
props={widgetProps}
key={key}
/>
);
}
function href(widgetName, linkProps) {
linkProps = { ...linkProps };
if (props.contractAccountId) {
linkProps.contractAccountId = props.contractAccountId;
}
if (props.widgetAccountId) {
linkProps.widgetAccountId = props.widgetAccountId;
}
if (props.referral) {
linkProps.referral = props.referral;
}
const linkPropsQuery = Object.entries(linkProps)
.map(([key, value]) => `${key}=${value}`)
.join("&");
return `#/${widgetAccountId}/widget/pages.${widgetName}${
linkPropsQuery ? "?" : ""
}${linkPropsQuery}`;
}