@akita-protocol/algomd-rn 1.0.0-alpha.1 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/presentation/icons.tsx +108 -1
- package/src/presentation/pluginColors.ts +1 -0
- package/src/presentation/runtime.tsx +11 -0
- package/src/refs/AccountRef.tsx +24 -10
- package/src/refs/GuildActions.tsx +913 -0
- package/src/refs/GuildProposalRef.tsx +60 -55
- package/src/refs/index.tsx +1 -0
- package/src/refs/primitives.tsx +51 -19
|
@@ -0,0 +1,913 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
import { Pressable, StyleSheet, View } from "react-native";
|
|
3
|
+
import * as Haptics from "expo-haptics";
|
|
4
|
+
import {
|
|
5
|
+
formatGuildPercent,
|
|
6
|
+
guildMinimumApprovals,
|
|
7
|
+
type GuildActionWarning,
|
|
8
|
+
type GuildAllowance,
|
|
9
|
+
type GuildCallerKind,
|
|
10
|
+
type GuildConsensusInfo,
|
|
11
|
+
type GuildProposalAction,
|
|
12
|
+
} from "@akita-protocol/algomd-core";
|
|
13
|
+
import { BottomSheetBackdrop, BottomSheetModal, BottomSheetScrollView } from "../presentation/sheets";
|
|
14
|
+
import { AlgoMarkIcon, BanknotesIcon, ChevronRightIcon, CircleStackIcon, ExclamationTriangleIcon, GuildIcon, PuzzlePieceIcon, UserGroupIcon } from "../presentation/icons";
|
|
15
|
+
import { PLUGIN_COLORS } from "../presentation/pluginColors";
|
|
16
|
+
import { AppPresentationProvider, Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
17
|
+
import { useHandle } from "./AccountRef";
|
|
18
|
+
import { useAssetInfo, useFormattedAmount } from "./assetInfo";
|
|
19
|
+
import { Avatar, Chip, InlinePill, Inset, KindTile, usePalette, VerifiedMark, type Tone } from "./primitives";
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* A Guild proposal's actions, written for the member deciding how to vote: which
|
|
23
|
+
* plugin, on which account, for which caller, what it may spend, and what to
|
|
24
|
+
* watch out for. A plugin or allowance action opens its full terms in a sheet.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const SHEET_SPRING = { damping: 70, stiffness: 900, mass: 2, overshootClamping: false };
|
|
28
|
+
|
|
29
|
+
const CALLER: Record<GuildCallerKind, { label: string; tone: Tone }> = {
|
|
30
|
+
members: { label: "Guild vote", tone: "good" },
|
|
31
|
+
anyone: { label: "Anyone", tone: "bad" },
|
|
32
|
+
agent: { label: "Agent", tone: "neutral" },
|
|
33
|
+
account: { label: "Personal account", tone: "warn" },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const UNITS: Array<[number, string]> = [
|
|
37
|
+
[604_800, "week"],
|
|
38
|
+
[86_400, "day"],
|
|
39
|
+
[3_600, "hour"],
|
|
40
|
+
[60, "minute"],
|
|
41
|
+
[1, "second"],
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
/** `1 day`, `6 hours`, `90 seconds`, or rounds. */
|
|
45
|
+
export function formatSpan(value: string, useRounds = false): string {
|
|
46
|
+
const n = Number(value);
|
|
47
|
+
if (!Number.isFinite(n) || n <= 0) return "None";
|
|
48
|
+
if (useRounds) return n === 1 ? "1 round" : `${n.toLocaleString("en-US")} rounds`;
|
|
49
|
+
const [size, word] = UNITS.find(([s]) => n >= s && n % s === 0) ?? [1, "second"];
|
|
50
|
+
const count = n / size;
|
|
51
|
+
return `${count.toLocaleString("en-US")} ${word}${count === 1 ? "" : "s"}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** `per day`, `every 6 hours`. */
|
|
55
|
+
export function formatCadence(value: string, useRounds = false): string {
|
|
56
|
+
const span = formatSpan(value, useRounds);
|
|
57
|
+
if (span === "None") return "per window";
|
|
58
|
+
return span.startsWith("1 ") ? `per ${span.slice(2)}` : `every ${span}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Where the action applies. `''` is the guild wallet itself. */
|
|
62
|
+
export function guildAccountLabel(escrow: string | undefined): string {
|
|
63
|
+
return escrow ? `the “${escrow}” escrow` : "the guild wallet";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function usePluginName(action: GuildProposalAction): string {
|
|
67
|
+
const presentation = usePresentation();
|
|
68
|
+
const id = action.pluginAppId;
|
|
69
|
+
return (id && presentation.applicationLabel?.(id)) || action.name || (id ? `Plugin #${id}` : "Plugin");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The radius primitives give an Inset; the account group wraps it. */
|
|
73
|
+
const INSET_RADIUS = 14;
|
|
74
|
+
|
|
75
|
+
/** True inside an account group, where the group header already names the account. */
|
|
76
|
+
const InAccountGroup = React.createContext(false);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* What a proposal does if it passes, one block per action. Actions on an
|
|
80
|
+
* escrow or the guild wallet are grouped under that account, in the order
|
|
81
|
+
* the proposal first touches it.
|
|
82
|
+
*/
|
|
83
|
+
export function GuildActionList({
|
|
84
|
+
actions,
|
|
85
|
+
consensus,
|
|
86
|
+
feeAsset,
|
|
87
|
+
visible,
|
|
88
|
+
}: {
|
|
89
|
+
actions: GuildProposalAction[];
|
|
90
|
+
consensus?: GuildConsensusInfo;
|
|
91
|
+
/** The Guild's proposal fee token; ALGO when left out. */
|
|
92
|
+
feeAsset?: string;
|
|
93
|
+
visible?: boolean;
|
|
94
|
+
}) {
|
|
95
|
+
const { theme } = useAppTheme();
|
|
96
|
+
const groups: Array<{ escrow?: string; items: Array<{ action: GuildProposalAction; index: number }> }> = [];
|
|
97
|
+
actions.forEach((action, index) => {
|
|
98
|
+
const found = groups.find((g) => g.escrow === action.escrow);
|
|
99
|
+
if (found) found.items.push({ action, index });
|
|
100
|
+
else groups.push({ escrow: action.escrow, items: [{ action, index }] });
|
|
101
|
+
});
|
|
102
|
+
return (
|
|
103
|
+
<FeeAssetContext.Provider value={feeAsset || "0"}>
|
|
104
|
+
<ConsensusContext.Provider value={consensus}>
|
|
105
|
+
<View style={{ gap: 14 }}>
|
|
106
|
+
{groups.map((group) => {
|
|
107
|
+
// Inside a tinted group the cards sit tighter, one shared surface.
|
|
108
|
+
const items = (
|
|
109
|
+
<View style={{ gap: group.escrow === undefined ? 8 : 2 }}>
|
|
110
|
+
{group.items.map(({ action, index }) => (
|
|
111
|
+
<GuildActionItem key={`${action.type}:${index}`} action={action} visible={visible} />
|
|
112
|
+
))}
|
|
113
|
+
</View>
|
|
114
|
+
);
|
|
115
|
+
if (group.escrow === undefined) return <React.Fragment key="none">{items}</React.Fragment>;
|
|
116
|
+
return (
|
|
117
|
+
<View key={`escrow:${group.escrow}`} style={[styles.accountGroup, { backgroundColor: `${theme.colors.primary}14` }]}>
|
|
118
|
+
<AccountGroupLabel escrow={group.escrow} />
|
|
119
|
+
<InAccountGroup.Provider value>{items}</InAccountGroup.Provider>
|
|
120
|
+
</View>
|
|
121
|
+
);
|
|
122
|
+
})}
|
|
123
|
+
</View>
|
|
124
|
+
</ConsensusContext.Provider>
|
|
125
|
+
</FeeAssetContext.Provider>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function AccountGroupLabel({ escrow }: { escrow: string }) {
|
|
130
|
+
const { theme } = useAppTheme();
|
|
131
|
+
return (
|
|
132
|
+
<View style={styles.accountLabel} accessibilityRole="header" accessibilityLabel={escrow ? `On the ${escrow} escrow` : "On the guild wallet"}>
|
|
133
|
+
<CircleStackIcon size={12} color={theme.colors.primary} />
|
|
134
|
+
<Text size="xs" weight="bold" numberOfLines={1} style={{ color: theme.colors.primary, letterSpacing: 0.5, flexShrink: 1 }}>
|
|
135
|
+
{(escrow ? `${escrow} escrow` : "Guild wallet").toUpperCase()}
|
|
136
|
+
</Text>
|
|
137
|
+
</View>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function GuildActionItem({ action, visible }: { action: GuildProposalAction; visible?: boolean }) {
|
|
142
|
+
if (action.install || action.type === 40 || action.type === 41) return <PluginAction action={action} visible={visible} />;
|
|
143
|
+
if (action.allowances || action.removedAssets) return <AllowanceAction action={action} visible={visible} />;
|
|
144
|
+
return <PlainAction action={action} />;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function PlainAction({ action }: { action: GuildProposalAction }) {
|
|
148
|
+
const { theme } = useAppTheme();
|
|
149
|
+
const presentation = usePresentation();
|
|
150
|
+
const plugin = action.pluginAppId ? presentation.applicationLabel?.(action.pluginAppId) ?? `#${action.pluginAppId}` : undefined;
|
|
151
|
+
return (
|
|
152
|
+
<View style={styles.plainRow}>
|
|
153
|
+
<View style={[styles.dot, { backgroundColor: theme.colors.primary }]} />
|
|
154
|
+
<Text size="xs" style={{ flex: 1 }}>
|
|
155
|
+
{action.label}
|
|
156
|
+
{plugin ? ` · ${plugin}` : ""}
|
|
157
|
+
</Text>
|
|
158
|
+
</View>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Action headers use a small tile beside a one-line title. */
|
|
163
|
+
const TILE = 18;
|
|
164
|
+
const HEAD_GAP = 8;
|
|
165
|
+
|
|
166
|
+
/** A tappable action block whose full terms open in a sheet. */
|
|
167
|
+
function ActionBlock({
|
|
168
|
+
Icon = PuzzlePieceIcon,
|
|
169
|
+
iconColor,
|
|
170
|
+
title,
|
|
171
|
+
account,
|
|
172
|
+
subtitle,
|
|
173
|
+
head,
|
|
174
|
+
accessibilityLabel,
|
|
175
|
+
sheet,
|
|
176
|
+
children,
|
|
177
|
+
}: {
|
|
178
|
+
Icon?: React.ComponentType<{ size?: number; color?: string }>;
|
|
179
|
+
iconColor?: string;
|
|
180
|
+
title: string;
|
|
181
|
+
/** The account the action applies to, inlined after the title as a pill: "on", "to" or "from". */
|
|
182
|
+
account?: { escrow: string; preposition: string };
|
|
183
|
+
/** A line of text, or a node such as the caller, under the title. */
|
|
184
|
+
subtitle?: React.ReactNode;
|
|
185
|
+
/** Draws this in place of the tile and title, when the action's subject is its own header. The sheet keeps the title. */
|
|
186
|
+
head?: React.ReactNode;
|
|
187
|
+
accessibilityLabel: string;
|
|
188
|
+
sheet: React.ReactNode;
|
|
189
|
+
children?: React.ReactNode;
|
|
190
|
+
}) {
|
|
191
|
+
const { theme } = useAppTheme();
|
|
192
|
+
const presentation = usePresentation();
|
|
193
|
+
const grouped = React.useContext(InAccountGroup);
|
|
194
|
+
const PortalProvider = presentation.components?.PortalProvider ?? React.Fragment;
|
|
195
|
+
const sheetRef = useRef<BottomSheetModal>(null);
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
const current = sheetRef.current;
|
|
198
|
+
return () => current?.dismiss();
|
|
199
|
+
}, []);
|
|
200
|
+
const open = useCallback(() => {
|
|
201
|
+
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
|
|
202
|
+
sheetRef.current?.present();
|
|
203
|
+
}, []);
|
|
204
|
+
return (
|
|
205
|
+
<>
|
|
206
|
+
<Pressable accessibilityRole="button" accessibilityLabel={accessibilityLabel} onPress={open} style={({ pressed }) => pressed && { opacity: 0.8 }}>
|
|
207
|
+
<Inset style={{ gap: 10, padding: 12 }}>
|
|
208
|
+
{head ? (
|
|
209
|
+
<View style={styles.head}>
|
|
210
|
+
<View style={{ flex: 1, minWidth: 0 }}>{head}</View>
|
|
211
|
+
<ChevronRightIcon size={16} color={theme.colors.textDim} />
|
|
212
|
+
</View>
|
|
213
|
+
) : (
|
|
214
|
+
<View>
|
|
215
|
+
<View style={styles.head}>
|
|
216
|
+
<KindTile Icon={Icon} color={iconColor} size={TILE} />
|
|
217
|
+
<Text size="sm" weight="semiBold" numberOfLines={2} style={{ flex: 1, minWidth: 0 }}>
|
|
218
|
+
{title}
|
|
219
|
+
{account && !grouped ? (
|
|
220
|
+
<>
|
|
221
|
+
{` ${account.preposition} `}
|
|
222
|
+
<EscrowPill escrow={account.escrow} />
|
|
223
|
+
</>
|
|
224
|
+
) : null}
|
|
225
|
+
</Text>
|
|
226
|
+
<ChevronRightIcon size={16} color={theme.colors.textDim} />
|
|
227
|
+
</View>
|
|
228
|
+
{!subtitle ? null : (
|
|
229
|
+
<View style={styles.underTitle}>
|
|
230
|
+
{typeof subtitle === "string" ? (
|
|
231
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim }}>
|
|
232
|
+
{subtitle}
|
|
233
|
+
</Text>
|
|
234
|
+
) : (
|
|
235
|
+
subtitle
|
|
236
|
+
)}
|
|
237
|
+
</View>
|
|
238
|
+
)}
|
|
239
|
+
</View>
|
|
240
|
+
)}
|
|
241
|
+
{children}
|
|
242
|
+
</Inset>
|
|
243
|
+
</Pressable>
|
|
244
|
+
<BottomSheetModal
|
|
245
|
+
ref={sheetRef}
|
|
246
|
+
enableDynamicSizing
|
|
247
|
+
backgroundStyle={{ backgroundColor: theme.colors.background }}
|
|
248
|
+
handleIndicatorStyle={{ backgroundColor: theme.colors.border }}
|
|
249
|
+
animationConfigs={SHEET_SPRING}
|
|
250
|
+
backdropComponent={(props: React.ComponentProps<typeof BottomSheetBackdrop>) => (
|
|
251
|
+
<BottomSheetBackdrop {...props} appearsOnIndex={0} disappearsOnIndex={-1} pressBehavior="close" />
|
|
252
|
+
)}
|
|
253
|
+
>
|
|
254
|
+
<PortalProvider>
|
|
255
|
+
<AppPresentationProvider {...presentation}>
|
|
256
|
+
<BottomSheetScrollView contentContainerStyle={{ paddingHorizontal: 20, paddingTop: 4, paddingBottom: 40, gap: 22 }}>
|
|
257
|
+
<View style={{ gap: 2 }}>
|
|
258
|
+
<Text size="lg" weight="bold">
|
|
259
|
+
{title}
|
|
260
|
+
{account ? (
|
|
261
|
+
<>
|
|
262
|
+
{` ${account.preposition} `}
|
|
263
|
+
<EscrowPill escrow={account.escrow} />
|
|
264
|
+
</>
|
|
265
|
+
) : null}
|
|
266
|
+
</Text>
|
|
267
|
+
{!subtitle ? null : typeof subtitle === "string" ? (
|
|
268
|
+
<Text size="xs" style={{ color: theme.colors.textDim }}>
|
|
269
|
+
{subtitle}
|
|
270
|
+
</Text>
|
|
271
|
+
) : (
|
|
272
|
+
subtitle
|
|
273
|
+
)}
|
|
274
|
+
</View>
|
|
275
|
+
{sheet}
|
|
276
|
+
</BottomSheetScrollView>
|
|
277
|
+
</AppPresentationProvider>
|
|
278
|
+
</PortalProvider>
|
|
279
|
+
</BottomSheetModal>
|
|
280
|
+
</>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The caller, labelled by kind, as one flat row like an allowance: who it
|
|
286
|
+
* is (or "Guild vote", "Anyone"), what that means, and a kind chip.
|
|
287
|
+
*/
|
|
288
|
+
function CallerLine({ action, visible, compact }: { action: GuildProposalAction; visible?: boolean; compact?: boolean }) {
|
|
289
|
+
const kind = action.callerKind ?? "account";
|
|
290
|
+
if (action.caller && kind !== "members" && kind !== "anyone") return <AccountCaller address={action.caller} kind={kind} visible={visible} compact={compact} />;
|
|
291
|
+
return (
|
|
292
|
+
<CallerRow
|
|
293
|
+
leading={<CallerIcon kind={kind} />}
|
|
294
|
+
title={CALLER[kind].label}
|
|
295
|
+
subtitle={compact ? "Caller" : kind === "members" ? "Each use needs a guild vote" : "Any account can call it"}
|
|
296
|
+
chip={compact ? undefined : CALLER[kind]}
|
|
297
|
+
/>
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** An escrow, or the guild wallet, picked out of an action's sentence. */
|
|
302
|
+
function EscrowPill({ escrow }: { escrow: string }) {
|
|
303
|
+
const { theme } = useAppTheme();
|
|
304
|
+
return (
|
|
305
|
+
<InlinePill
|
|
306
|
+
highlight
|
|
307
|
+
label={escrow || "Guild wallet"}
|
|
308
|
+
leading={<CircleStackIcon size={12} color={theme.colors.primary} />}
|
|
309
|
+
accessibilityLabel={escrow ? `the ${escrow} escrow` : "the guild wallet"}
|
|
310
|
+
/>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* When each use of the plugin needs its own guild proposal, what those
|
|
316
|
+
* proposals will need: the vote rules members set here, for a plugin members
|
|
317
|
+
* call by vote.
|
|
318
|
+
*/
|
|
319
|
+
function ExecutionLines({ action }: { action: GuildProposalAction }) {
|
|
320
|
+
const install = action.install!;
|
|
321
|
+
const feeAsset = React.useContext(FeeAssetContext);
|
|
322
|
+
const fee = useFormattedAmount(install.vote.fee, feeAsset);
|
|
323
|
+
if (action.callerKind !== "members") return <TermLine label="Each use">Needs a guild proposal</TermLine>;
|
|
324
|
+
const { approval, participation, minimumApprovals, duration, power } = install.vote;
|
|
325
|
+
return (
|
|
326
|
+
<View style={styles.terms}>
|
|
327
|
+
<RequirementLines approval={approval} minimumApprovals={minimumApprovals} participation={participation} />
|
|
328
|
+
{duration !== "0" ? <TermLine label="Voting period">{formatSpan(duration)}</TermLine> : null}
|
|
329
|
+
{install.vote.fee !== "0" ? (
|
|
330
|
+
<TermLine label="Proposal fee">
|
|
331
|
+
<TokenAmount assetId={feeAsset} amount={fee} />
|
|
332
|
+
</TermLine>
|
|
333
|
+
) : null}
|
|
334
|
+
{power !== "0" ? <TermLine label="Power to propose">{power}</TermLine> : null}
|
|
335
|
+
</View>
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** An amount with its token's icon in front, as a term's value. */
|
|
340
|
+
function TokenAmount({ assetId, amount }: { assetId: string; amount: string }) {
|
|
341
|
+
const { theme } = useAppTheme();
|
|
342
|
+
const info = useAssetInfo(assetId === "0" ? undefined : assetId);
|
|
343
|
+
return (
|
|
344
|
+
<View style={styles.miniPart}>
|
|
345
|
+
{assetId === "0" ? (
|
|
346
|
+
<Avatar size={14} icon={<AlgoMarkIcon size={8} color={theme.colors.text} />} />
|
|
347
|
+
) : (
|
|
348
|
+
<Avatar uri={info.image} size={14} initial={info.label} />
|
|
349
|
+
)}
|
|
350
|
+
<Text size="xxs" weight="medium" numberOfLines={1}>
|
|
351
|
+
{amount}
|
|
352
|
+
</Text>
|
|
353
|
+
</View>
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** A compact term under a plugin row: small dim label, small value at the end. */
|
|
358
|
+
function TermLine({ label, children }: { label: string; children: React.ReactNode }) {
|
|
359
|
+
const { theme } = useAppTheme();
|
|
360
|
+
return (
|
|
361
|
+
<View style={styles.term}>
|
|
362
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim, flexShrink: 0 }}>
|
|
363
|
+
{label}
|
|
364
|
+
</Text>
|
|
365
|
+
{typeof children === "string" ? (
|
|
366
|
+
<Text size="xxs" weight="medium" numberOfLines={1} style={{ flexShrink: 1, textAlign: "right" }}>
|
|
367
|
+
{children}
|
|
368
|
+
</Text>
|
|
369
|
+
) : (
|
|
370
|
+
children
|
|
371
|
+
)}
|
|
372
|
+
</View>
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** The fixed point the consensus contract uses for percentages: 100000 = 100%. */
|
|
377
|
+
const PERCENT_SCALE = 100_000;
|
|
378
|
+
/** Past this many signers, seats give way to a meter. */
|
|
379
|
+
const MAX_SEATS = 12;
|
|
380
|
+
|
|
381
|
+
/** The Guild's consensus, for the requirement marks under its actions. */
|
|
382
|
+
const ConsensusContext = React.createContext<GuildConsensusInfo | undefined>(undefined);
|
|
383
|
+
/** The Guild's proposal fee token, "0" for ALGO. Each use's proposal pays its fee in it. */
|
|
384
|
+
const FeeAssetContext = React.createContext("0");
|
|
385
|
+
|
|
386
|
+
const compactNumber = (value: bigint) =>
|
|
387
|
+
new Intl.NumberFormat("en-US", { notation: "compact", maximumFractionDigits: 1 }).format(Number(value));
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* What a vote needs to pass, one short line per requirement, drawn for how
|
|
391
|
+
* the Guild's consensus counts votes: the yes share, the approval floor
|
|
392
|
+
* (seats for one-vote signers, a meter for weighted signers, a voting power
|
|
393
|
+
* floor for locked tokens and subscriptions), and turnout.
|
|
394
|
+
* A signer floor that already covers the yes share and turnout stands alone.
|
|
395
|
+
* Every mark carries its number in text, so nothing rests on colour.
|
|
396
|
+
*/
|
|
397
|
+
export function RequirementLines({ approval, minimumApprovals, participation }: { approval: string; minimumApprovals: string; participation: string }) {
|
|
398
|
+
const consensus = React.useContext(ConsensusContext);
|
|
399
|
+
const { tone } = usePalette();
|
|
400
|
+
const kind = consensus?.kind ?? "unknown";
|
|
401
|
+
const minimum = BigInt(guildMinimumApprovals(minimumApprovals, consensus));
|
|
402
|
+
const lines: Array<{ key: string; label: string; mark?: React.ReactNode; value: string; spoken: string }> = [];
|
|
403
|
+
|
|
404
|
+
// On a signer Guild the floor is counted against every signer, so when it is
|
|
405
|
+
// at least the yes share and the turnout asked for, it already implies both:
|
|
406
|
+
// a multisig then reads as just "x of y". Only show the others when they bite.
|
|
407
|
+
const signerTotal =
|
|
408
|
+
kind === "signers" ? BigInt(consensus?.memberCount || "0") : kind === "weighted-signers" ? BigInt(consensus?.totalPower || "0") : 0n;
|
|
409
|
+
const impliedByFloor = (percent: string) => signerTotal > 0n && minimum * BigInt(PERCENT_SCALE) >= BigInt(percent) * signerTotal;
|
|
410
|
+
|
|
411
|
+
if (approval !== "0" && !impliedByFloor(approval)) {
|
|
412
|
+
const pct = formatGuildPercent(approval);
|
|
413
|
+
lines.push({ key: "yes", label: "Yes votes", mark: <MiniMeter value={Number(approval) / PERCENT_SCALE} color={tone("good")} />, value: pct, spoken: `${pct} of votes yes` });
|
|
414
|
+
}
|
|
415
|
+
if (kind === "signers" || kind === "weighted-signers") {
|
|
416
|
+
const total = signerTotal;
|
|
417
|
+
if (minimum > 0n && total > 0n) {
|
|
418
|
+
const value = `${minimum} of ${total}`;
|
|
419
|
+
lines.push({
|
|
420
|
+
key: "floor",
|
|
421
|
+
label: kind === "signers" ? "Signers" : "Approval weight",
|
|
422
|
+
mark:
|
|
423
|
+
kind === "signers" && total <= BigInt(MAX_SEATS) ? (
|
|
424
|
+
<Seats total={Number(total)} filled={Number(minimum)} color={tone("good")} />
|
|
425
|
+
) : (
|
|
426
|
+
<MiniMeter value={Number(minimum) / Number(total)} color={tone("good")} />
|
|
427
|
+
),
|
|
428
|
+
value,
|
|
429
|
+
spoken: `${value} ${kind === "signers" ? "signers" : "weight"} approving`,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
} else if (minimum > 0n) {
|
|
433
|
+
// Locked-token and subscription power has no everyday unit, so it reads as plain voting power.
|
|
434
|
+
const value = `≥ ${compactNumber(minimum)}`;
|
|
435
|
+
const label = kind === "locked-token" || kind === "subscriptions" ? "Voting power" : "Approvals";
|
|
436
|
+
lines.push({ key: "floor", label, value, spoken: `${label} ${value}` });
|
|
437
|
+
}
|
|
438
|
+
// Only signer consensus knows all the power that could vote; the others never set turnout.
|
|
439
|
+
if (participation !== "0" && !impliedByFloor(participation)) {
|
|
440
|
+
const pct = formatGuildPercent(participation);
|
|
441
|
+
lines.push({ key: "turnout", label: "Turnout", mark: <MiniMeter value={Number(participation) / PERCENT_SCALE} color={tone("neutral")} />, value: pct, spoken: `${pct} turnout` });
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (!lines.length) return <TermLine label="To pass">Any approval</TermLine>;
|
|
445
|
+
return (
|
|
446
|
+
<>
|
|
447
|
+
{lines.map((line) => (
|
|
448
|
+
<TermLine key={line.key} label={line.label}>
|
|
449
|
+
<View style={styles.miniPart} accessible accessibilityLabel={`Needs ${line.spoken}`}>
|
|
450
|
+
{line.mark}
|
|
451
|
+
<Text size="xxs" weight="medium" numberOfLines={1}>
|
|
452
|
+
{line.value}
|
|
453
|
+
</Text>
|
|
454
|
+
</View>
|
|
455
|
+
</TermLine>
|
|
456
|
+
))}
|
|
457
|
+
</>
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** One small seat per signer, the first `filled` of them in `color`. */
|
|
462
|
+
function Seats({ total, filled, color }: { total: number; filled: number; color: string }) {
|
|
463
|
+
const { theme } = useAppTheme();
|
|
464
|
+
return (
|
|
465
|
+
<View style={styles.dots}>
|
|
466
|
+
{Array.from({ length: total }, (_, i) => (
|
|
467
|
+
<View key={i} style={[styles.dot6, { backgroundColor: i < filled ? color : theme.colors.border }]} />
|
|
468
|
+
))}
|
|
469
|
+
</View>
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function MiniMeter({ value, color }: { value: number; color: string }) {
|
|
474
|
+
const { theme } = useAppTheme();
|
|
475
|
+
const width = `${Math.max(0, Math.min(1, value)) * 100}%` as `${number}%`;
|
|
476
|
+
return (
|
|
477
|
+
<View style={[styles.meter, { backgroundColor: theme.colors.border }]}>
|
|
478
|
+
<View style={{ width, height: "100%", borderRadius: 2, backgroundColor: color }} />
|
|
479
|
+
</View>
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** The guild's banner for a guild vote; a group for anyone. */
|
|
484
|
+
function CallerIcon({ kind }: { kind: GuildCallerKind }) {
|
|
485
|
+
const { theme } = useAppTheme();
|
|
486
|
+
return <Avatar size={28} icon={kind === "members" ? <GuildIcon size={16} color={PLUGIN_COLORS.Guild} /> : <UserGroupIcon size={14} color={theme.colors.textDim} />} />;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function AccountCaller({ address, kind, visible, compact }: { address: string; kind: GuildCallerKind; visible?: boolean; compact?: boolean }) {
|
|
490
|
+
const presentation = usePresentation();
|
|
491
|
+
const { id, name, handle } = useHandle(address, visible);
|
|
492
|
+
const row = (
|
|
493
|
+
<CallerRow
|
|
494
|
+
leading={<Avatar uri={id?.avatar} size={28} initial={name} />}
|
|
495
|
+
title={name}
|
|
496
|
+
verified={id?.nameVerified}
|
|
497
|
+
subtitle={compact ? "Caller" : handle}
|
|
498
|
+
chip={compact ? undefined : CALLER[kind]}
|
|
499
|
+
/>
|
|
500
|
+
);
|
|
501
|
+
if (!presentation.onOpenAccount) return row;
|
|
502
|
+
return (
|
|
503
|
+
<Pressable accessibilityRole="button" accessibilityLabel={`Open ${name}, caller`} onPress={() => presentation.onOpenAccount!(address)}>
|
|
504
|
+
{row}
|
|
505
|
+
</Pressable>
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function CallerRow({ leading, title, verified, subtitle, chip }: { leading: React.ReactNode; title: string; verified?: boolean; subtitle?: string; chip?: { label: string; tone: Tone } }) {
|
|
510
|
+
const { theme } = useAppTheme();
|
|
511
|
+
return (
|
|
512
|
+
<View style={styles.allowance}>
|
|
513
|
+
<View style={styles.lead}>{leading}</View>
|
|
514
|
+
<View style={{ flex: 1, minWidth: 0, gap: 1 }}>
|
|
515
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 3 }}>
|
|
516
|
+
<Text size="xs" weight="semiBold" numberOfLines={1} style={{ flexShrink: 1 }}>
|
|
517
|
+
{title}
|
|
518
|
+
</Text>
|
|
519
|
+
{verified ? <VerifiedMark size={12} /> : null}
|
|
520
|
+
</View>
|
|
521
|
+
{subtitle ? (
|
|
522
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim }}>
|
|
523
|
+
{subtitle}
|
|
524
|
+
</Text>
|
|
525
|
+
) : null}
|
|
526
|
+
</View>
|
|
527
|
+
{chip ? <Chip label={chip.label} tone={chip.tone} /> : null}
|
|
528
|
+
</View>
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Warnings as a tinted box in the most
|
|
534
|
+
* severe tone, each line a small icon centred on the first line of its text.
|
|
535
|
+
*/
|
|
536
|
+
function Warnings({ warnings, limit }: { warnings: GuildActionWarning[]; limit?: number }) {
|
|
537
|
+
const { theme, tone } = usePalette();
|
|
538
|
+
const shown = limit ? warnings.slice(0, limit) : warnings;
|
|
539
|
+
const more = warnings.length - shown.length;
|
|
540
|
+
const box = tone(warnings.some((w) => w.tone === "bad") ? "bad" : "warn");
|
|
541
|
+
return (
|
|
542
|
+
<View accessibilityRole="alert" style={[styles.notice, { backgroundColor: `${box}1A` }]}>
|
|
543
|
+
{shown.map((w) => (
|
|
544
|
+
<View key={w.text} style={styles.warning}>
|
|
545
|
+
<View style={styles.warningIcon}>
|
|
546
|
+
<ExclamationTriangleIcon size={12} color={tone(w.tone)} />
|
|
547
|
+
</View>
|
|
548
|
+
<Text size="xxs" weight="medium" style={{ color: theme.colors.text, flex: 1 }}>
|
|
549
|
+
{w.text}
|
|
550
|
+
</Text>
|
|
551
|
+
</View>
|
|
552
|
+
))}
|
|
553
|
+
{more > 0 ? (
|
|
554
|
+
<Text size="xxs" style={{ color: theme.colors.textDim, marginLeft: 18 }}>
|
|
555
|
+
{`${more} more in the details`}
|
|
556
|
+
</Text>
|
|
557
|
+
) : null}
|
|
558
|
+
</View>
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function PluginAction({ action, visible }: { action: GuildProposalAction; visible?: boolean }) {
|
|
563
|
+
const name = usePluginName(action);
|
|
564
|
+
const removing = action.type === 40 || action.type === 41;
|
|
565
|
+
const title = removing ? "Remove plugin" : "Install plugin";
|
|
566
|
+
const account = action.escrow === undefined ? undefined : guildAccountLabel(action.escrow);
|
|
567
|
+
const warnings = action.warnings ?? [];
|
|
568
|
+
return (
|
|
569
|
+
<ActionBlock
|
|
570
|
+
title={title}
|
|
571
|
+
account={action.escrow !== undefined ? { escrow: action.escrow, preposition: removing ? "from" : "on" } : undefined}
|
|
572
|
+
accessibilityLabel={`${title} ${name}${account ? `, ${removing ? "from" : "on"} ${account}` : ""}${warnings.length ? `, ${warnings.length} warnings` : ""}`}
|
|
573
|
+
sheet={<PluginSheet action={action} name={name} visible={visible} />}
|
|
574
|
+
head={<PluginRow action={action} name={name} title={title} preposition={removing ? "from" : "on"} visible={visible} />}
|
|
575
|
+
>
|
|
576
|
+
{action.install?.useExecutionKey ? <ExecutionLines action={action} /> : null}
|
|
577
|
+
{warnings.length ? <Warnings warnings={warnings} limit={2} /> : null}
|
|
578
|
+
</ActionBlock>
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* The plugin action's header: what is done to which plugin on the left, under
|
|
584
|
+
* a small label naming the action, and who may call it on the right. The
|
|
585
|
+
* plugin's own name needs no "Plugin" tag beneath it.
|
|
586
|
+
*/
|
|
587
|
+
function PluginRow({
|
|
588
|
+
action,
|
|
589
|
+
name,
|
|
590
|
+
title,
|
|
591
|
+
preposition,
|
|
592
|
+
visible,
|
|
593
|
+
}: {
|
|
594
|
+
action: GuildProposalAction;
|
|
595
|
+
name: string;
|
|
596
|
+
title: string;
|
|
597
|
+
preposition: string;
|
|
598
|
+
visible?: boolean;
|
|
599
|
+
}) {
|
|
600
|
+
const { theme } = useAppTheme();
|
|
601
|
+
const presentation = usePresentation();
|
|
602
|
+
const icon = action.pluginAppId ? presentation.applicationIcon?.(action.pluginAppId) : undefined;
|
|
603
|
+
const grouped = React.useContext(InAccountGroup);
|
|
604
|
+
const escrow = grouped ? undefined : action.escrow;
|
|
605
|
+
return (
|
|
606
|
+
<View style={styles.allowance}>
|
|
607
|
+
<KindTile Icon={icon?.Icon ?? PuzzlePieceIcon} color={icon?.color} size={28} />
|
|
608
|
+
<View style={{ flex: 1, minWidth: 0, gap: 1 }}>
|
|
609
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim }}>
|
|
610
|
+
{title}
|
|
611
|
+
{escrow !== undefined ? (
|
|
612
|
+
<>
|
|
613
|
+
{` ${preposition} `}
|
|
614
|
+
<Text size="xxs" weight="semiBold" style={{ color: theme.colors.primary }}>
|
|
615
|
+
{escrow || "guild wallet"}
|
|
616
|
+
</Text>
|
|
617
|
+
</>
|
|
618
|
+
) : null}
|
|
619
|
+
</Text>
|
|
620
|
+
<Text size="xs" weight="semiBold" numberOfLines={1}>
|
|
621
|
+
{name}
|
|
622
|
+
</Text>
|
|
623
|
+
</View>
|
|
624
|
+
<View style={{ alignItems: "flex-end", flexShrink: 1 }}>
|
|
625
|
+
<CallerName action={action} visible={visible} />
|
|
626
|
+
</View>
|
|
627
|
+
</View>
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/** The caller's name for the right of a plugin row: a small avatar and name, or the members / anyone icon and label. */
|
|
632
|
+
function CallerName({ action, visible }: { action: GuildProposalAction; visible?: boolean }) {
|
|
633
|
+
const kind = action.callerKind ?? "account";
|
|
634
|
+
const { theme, tone: color } = usePalette();
|
|
635
|
+
if (action.caller && kind !== "members" && kind !== "anyone") return <AccountCallerName address={action.caller} visible={visible} />;
|
|
636
|
+
const { label, tone } = CALLER[kind];
|
|
637
|
+
return (
|
|
638
|
+
<View style={styles.callerName}>
|
|
639
|
+
{kind === "members" ? <GuildIcon size={16} color={PLUGIN_COLORS.Guild} /> : <UserGroupIcon size={14} color={color(tone)} />}
|
|
640
|
+
<Text size="xs" weight="semiBold" numberOfLines={1} style={{ color: tone === "bad" ? color(tone) : theme.colors.text, flexShrink: 1 }}>
|
|
641
|
+
{label}
|
|
642
|
+
</Text>
|
|
643
|
+
</View>
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function AccountCallerName({ address, visible }: { address: string; visible?: boolean }) {
|
|
648
|
+
const presentation = usePresentation();
|
|
649
|
+
const { id, name } = useHandle(address, visible);
|
|
650
|
+
const value = (
|
|
651
|
+
<View style={styles.callerName}>
|
|
652
|
+
<Avatar uri={id?.avatar} size={16} initial={name} />
|
|
653
|
+
<View style={{ alignItems: "center", flexDirection: "row", flexShrink: 1, gap: 3 }}>
|
|
654
|
+
<Text size="xs" weight="semiBold" numberOfLines={1} style={{ flexShrink: 1 }}>
|
|
655
|
+
{name}
|
|
656
|
+
</Text>
|
|
657
|
+
{id?.nameVerified ? <VerifiedMark size={12} /> : null}
|
|
658
|
+
</View>
|
|
659
|
+
</View>
|
|
660
|
+
);
|
|
661
|
+
if (!presentation.onOpenAccount) return value;
|
|
662
|
+
return (
|
|
663
|
+
<Pressable accessibilityRole="button" accessibilityLabel={`Open ${name}, caller`} onPress={() => presentation.onOpenAccount!(address)}>
|
|
664
|
+
{value}
|
|
665
|
+
</Pressable>
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** Every term of a plugin action: what its sheet shows. */
|
|
670
|
+
export function GuildPluginDetails({ action, feeAsset, visible }: { action: GuildProposalAction; feeAsset?: string; visible?: boolean }) {
|
|
671
|
+
const name = usePluginName(action);
|
|
672
|
+
return (
|
|
673
|
+
<FeeAssetContext.Provider value={feeAsset || "0"}>
|
|
674
|
+
<PluginSheet action={action} name={name} visible={visible} />
|
|
675
|
+
</FeeAssetContext.Provider>
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function PluginSheet({ action, name, visible }: { action: GuildProposalAction; name: string; visible?: boolean }) {
|
|
680
|
+
const install = action.install;
|
|
681
|
+
const rounds = install?.useRounds ?? false;
|
|
682
|
+
const feeAsset = React.useContext(FeeAssetContext);
|
|
683
|
+
const fee = useFormattedAmount(install?.vote.fee, feeAsset);
|
|
684
|
+
return (
|
|
685
|
+
<>
|
|
686
|
+
{action.warnings?.length ? <Warnings warnings={action.warnings} /> : null}
|
|
687
|
+
<SheetGroup label="Plugin">
|
|
688
|
+
<SheetRow label="Name" value={name} />
|
|
689
|
+
{action.pluginAppId ? <SheetRow label="Application" value={`#${action.pluginAppId}`} /> : null}
|
|
690
|
+
</SheetGroup>
|
|
691
|
+
<SheetGroup label="Caller">
|
|
692
|
+
<View style={styles.sheetPad}>
|
|
693
|
+
<CallerLine action={action} visible={visible} />
|
|
694
|
+
</View>
|
|
695
|
+
</SheetGroup>
|
|
696
|
+
{install ? (
|
|
697
|
+
<SheetGroup label="Permissions">
|
|
698
|
+
<SheetRow label="Methods" value={install.methods.length ? `${install.methods.length} allowed` : "Every method"}>
|
|
699
|
+
{install.methods.length ? (
|
|
700
|
+
<View style={styles.methods}>
|
|
701
|
+
{install.methods.map((m) => (
|
|
702
|
+
<Chip key={m.selector} label={`0x${m.selector}${m.cooldown !== "0" ? ` · ${formatSpan(m.cooldown, rounds)}` : ""}`} />
|
|
703
|
+
))}
|
|
704
|
+
</View>
|
|
705
|
+
) : null}
|
|
706
|
+
</SheetRow>
|
|
707
|
+
<SheetRow label="Cooldown" value={formatSpan(install.cooldown, rounds)} />
|
|
708
|
+
<SheetRow label="Fees" value={install.coverFees ? "Guild wallet pays" : "Caller pays"} />
|
|
709
|
+
<SheetRow
|
|
710
|
+
label="Expires"
|
|
711
|
+
value={install.lastValid ? (rounds ? `Round ${Number(install.lastValid).toLocaleString("en-US")}` : new Date(Number(install.lastValid) * 1000).toLocaleDateString()) : "Never"}
|
|
712
|
+
/>
|
|
713
|
+
<SheetRow label="Each use needs a vote" value={install.useExecutionKey ? "Yes" : "No"} />
|
|
714
|
+
</SheetGroup>
|
|
715
|
+
) : null}
|
|
716
|
+
{install?.useExecutionKey && action.callerKind === "members" ? (
|
|
717
|
+
<SheetGroup label="Vote to use it">
|
|
718
|
+
<SheetRow label="Proposal fee" value={fee} />
|
|
719
|
+
<SheetRow label="Power to propose" value={install.vote.power} />
|
|
720
|
+
<SheetRow label="Voting period" value={formatSpan(install.vote.duration)} />
|
|
721
|
+
<SheetRow label="Approval" value={formatGuildPercent(install.vote.approval)} />
|
|
722
|
+
<SheetRow label="Turnout" value={formatGuildPercent(install.vote.participation)} />
|
|
723
|
+
<SheetRow label="Minimum approvals" value={install.vote.minimumApprovals} />
|
|
724
|
+
</SheetGroup>
|
|
725
|
+
) : null}
|
|
726
|
+
{install?.allowances.length ? (
|
|
727
|
+
<SheetGroup label="Allowances">
|
|
728
|
+
{install.allowances.map((a, i) => (
|
|
729
|
+
<View key={`${a.assetId}:${i}`} style={styles.sheetPad}>
|
|
730
|
+
<AllowanceRow allowance={a} visible={visible} />
|
|
731
|
+
</View>
|
|
732
|
+
))}
|
|
733
|
+
</SheetGroup>
|
|
734
|
+
) : null}
|
|
735
|
+
</>
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/*
|
|
740
|
+
* The sheet follows the Akita agent install review: an uppercase label, then a
|
|
741
|
+
* rounded card on the sheet background with a hairline between its rows.
|
|
742
|
+
*/
|
|
743
|
+
function SheetGroup({ label, children }: { label: string; children: React.ReactNode }) {
|
|
744
|
+
const { theme } = useAppTheme();
|
|
745
|
+
const rows = React.Children.toArray(children).filter(React.isValidElement);
|
|
746
|
+
return (
|
|
747
|
+
<View>
|
|
748
|
+
<Text size="xs" weight="bold" accessibilityRole="header" style={[styles.groupLabel, { color: theme.colors.textDim }]}>
|
|
749
|
+
{label.toUpperCase()}
|
|
750
|
+
</Text>
|
|
751
|
+
<View style={[styles.group, { backgroundColor: theme.colors.accentBackground }]}>
|
|
752
|
+
{rows.map((row, i) => (
|
|
753
|
+
<React.Fragment key={row.key ?? i}>
|
|
754
|
+
{i > 0 ? <View style={[styles.divider, { backgroundColor: theme.colors.border }]} /> : null}
|
|
755
|
+
{row}
|
|
756
|
+
</React.Fragment>
|
|
757
|
+
))}
|
|
758
|
+
</View>
|
|
759
|
+
</View>
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/** A label on the left and its value on the right, with optional content below. */
|
|
764
|
+
function SheetRow({ label, value, children }: { label: string; value: string; children?: React.ReactNode }) {
|
|
765
|
+
const { theme } = useAppTheme();
|
|
766
|
+
return (
|
|
767
|
+
<View style={styles.sheetPad}>
|
|
768
|
+
<View style={styles.sheetRow}>
|
|
769
|
+
<Text size="sm" numberOfLines={1} style={{ color: theme.colors.textDim, flexShrink: 0 }}>
|
|
770
|
+
{label}
|
|
771
|
+
</Text>
|
|
772
|
+
<Text size="sm" weight="semiBold" numberOfLines={1} style={{ flexShrink: 1, textAlign: "right" }}>
|
|
773
|
+
{value}
|
|
774
|
+
</Text>
|
|
775
|
+
</View>
|
|
776
|
+
{children}
|
|
777
|
+
</View>
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function AllowanceAction({ action, visible }: { action: GuildProposalAction; visible?: boolean }) {
|
|
782
|
+
const account = guildAccountLabel(action.escrow);
|
|
783
|
+
const removing = !!action.removedAssets;
|
|
784
|
+
const count = removing ? (action.removedAssets ?? []).length : (action.allowances ?? []).length;
|
|
785
|
+
const title = `${removing ? "Remove" : "Add"} ${count === 1 ? "allowance" : "allowances"}`;
|
|
786
|
+
const body = removing ? <RemovedAssets assets={action.removedAssets!} visible={visible} /> : <AllowanceRows allowances={action.allowances ?? []} visible={visible} />;
|
|
787
|
+
return (
|
|
788
|
+
<ActionBlock
|
|
789
|
+
Icon={BanknotesIcon}
|
|
790
|
+
title={title}
|
|
791
|
+
account={{ escrow: action.escrow ?? "", preposition: removing ? "from" : "to" }}
|
|
792
|
+
accessibilityLabel={`${title} ${removing ? "from" : "to"} ${account}, ${count} asset${count === 1 ? "" : "s"}`}
|
|
793
|
+
sheet={
|
|
794
|
+
<>
|
|
795
|
+
<SheetGroup label={removing ? "Assets" : "Allowances"}>
|
|
796
|
+
{removing ? (
|
|
797
|
+
<View style={styles.sheetPad}>{body}</View>
|
|
798
|
+
) : (
|
|
799
|
+
(action.allowances ?? []).map((a, i) => (
|
|
800
|
+
<View key={`${a.assetId}:${i}`} style={styles.sheetPad}>
|
|
801
|
+
<AllowanceRow allowance={a} visible={visible} />
|
|
802
|
+
</View>
|
|
803
|
+
))
|
|
804
|
+
)}
|
|
805
|
+
</SheetGroup>
|
|
806
|
+
</>
|
|
807
|
+
}
|
|
808
|
+
>
|
|
809
|
+
{body}
|
|
810
|
+
</ActionBlock>
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
function RemovedAssets({ assets, visible }: { assets: string[]; visible?: boolean }) {
|
|
815
|
+
return (
|
|
816
|
+
<View style={styles.methods}>
|
|
817
|
+
{assets.map((id) => (
|
|
818
|
+
<AssetChip key={id} id={id} visible={visible} />
|
|
819
|
+
))}
|
|
820
|
+
</View>
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function AssetChip({ id, visible }: { id: string; visible?: boolean }) {
|
|
825
|
+
const info = useAssetInfo(id, visible);
|
|
826
|
+
return <Chip label={info.label} />;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
function AllowanceRows({ allowances, visible }: { allowances: GuildAllowance[]; visible?: boolean }) {
|
|
830
|
+
return (
|
|
831
|
+
<View style={{ gap: 10 }}>
|
|
832
|
+
{allowances.map((a, i) => (
|
|
833
|
+
<AllowanceRow key={`${a.assetId}:${i}`} allowance={a} visible={visible} />
|
|
834
|
+
))}
|
|
835
|
+
</View>
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
const KIND: Record<GuildAllowance["kind"], string> = {
|
|
840
|
+
flat: "One-time",
|
|
841
|
+
window: "Rolling window",
|
|
842
|
+
drip: "Drip",
|
|
843
|
+
unknown: "Unknown kind",
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
/** One allowance, as the agent install review shows it: asset, strategy, amount and cadence. */
|
|
847
|
+
export function AllowanceRow({ allowance, visible }: { allowance: GuildAllowance; visible?: boolean }) {
|
|
848
|
+
const { theme } = useAppTheme();
|
|
849
|
+
const info = useAssetInfo(allowance.assetId, visible);
|
|
850
|
+
const amount = useFormattedAmount(allowance.amount, allowance.assetId);
|
|
851
|
+
const max = useFormattedAmount(allowance.max, allowance.assetId);
|
|
852
|
+
const [value, cadence] =
|
|
853
|
+
allowance.kind === "drip"
|
|
854
|
+
? [max, `refills ${amount} ${formatCadence(allowance.interval, allowance.useRounds)}`]
|
|
855
|
+
: allowance.kind === "window"
|
|
856
|
+
? [amount, formatCadence(allowance.interval, allowance.useRounds)]
|
|
857
|
+
: [amount, "one time"];
|
|
858
|
+
return (
|
|
859
|
+
<View style={styles.allowance} accessibilityLabel={`${info.label} ${KIND[allowance.kind]}: ${value}, ${cadence}`}>
|
|
860
|
+
<View style={styles.lead}>
|
|
861
|
+
<Avatar uri={info.image} size={28} initial={info.label} />
|
|
862
|
+
</View>
|
|
863
|
+
<View style={{ flex: 1, minWidth: 0, gap: 1 }}>
|
|
864
|
+
<Text size="xs" weight="semiBold" numberOfLines={1}>
|
|
865
|
+
{info.label}
|
|
866
|
+
</Text>
|
|
867
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim }}>
|
|
868
|
+
{KIND[allowance.kind]}
|
|
869
|
+
</Text>
|
|
870
|
+
</View>
|
|
871
|
+
<View style={{ alignItems: "flex-end", gap: 1, flexShrink: 1 }}>
|
|
872
|
+
<Text size="xs" weight="bold" numberOfLines={1}>
|
|
873
|
+
{value}
|
|
874
|
+
</Text>
|
|
875
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim }}>
|
|
876
|
+
{cadence}
|
|
877
|
+
</Text>
|
|
878
|
+
</View>
|
|
879
|
+
</View>
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
const styles = StyleSheet.create({
|
|
884
|
+
head: { alignItems: "center", flexDirection: "row", gap: HEAD_GAP },
|
|
885
|
+
// Lines a subtitle up under the title, past the tile.
|
|
886
|
+
underTitle: { paddingLeft: TILE + HEAD_GAP },
|
|
887
|
+
plainRow: { alignItems: "flex-start", flexDirection: "row", gap: 8 },
|
|
888
|
+
dot: { borderRadius: 3, height: 6, marginTop: 6, width: 6 },
|
|
889
|
+
notice: { borderRadius: 12, gap: 4, paddingHorizontal: 10, paddingVertical: 8 },
|
|
890
|
+
warning: { alignItems: "flex-start", flexDirection: "row", gap: 6 },
|
|
891
|
+
// As tall as an xxs line (18), so the icon centres on the first line.
|
|
892
|
+
warningIcon: { alignItems: "center", height: 18, justifyContent: "center", width: 12 },
|
|
893
|
+
// The Inset's radius plus the padding, so inner and outer corners stay concentric.
|
|
894
|
+
accountGroup: { borderRadius: INSET_RADIUS + 4, padding: 4 },
|
|
895
|
+
// Lines the label's icon up with the action tiles below (4 + 12).
|
|
896
|
+
accountLabel: { alignItems: "center", flexDirection: "row", gap: 6, paddingBottom: 6, paddingHorizontal: 12, paddingTop: 6 },
|
|
897
|
+
groupLabel: { letterSpacing: 0.5, marginBottom: 8, marginHorizontal: 4 },
|
|
898
|
+
group: { borderRadius: 16, overflow: "hidden" },
|
|
899
|
+
divider: { height: 1, marginHorizontal: 16 },
|
|
900
|
+
sheetPad: { gap: 10, paddingHorizontal: 16, paddingVertical: 12 },
|
|
901
|
+
sheetRow: { alignItems: "center", flexDirection: "row", gap: 12, justifyContent: "space-between", minHeight: 26 },
|
|
902
|
+
methods: { flexDirection: "row", flexWrap: "wrap", gap: 6 },
|
|
903
|
+
allowance: { alignItems: "center", flexDirection: "row", gap: 10 },
|
|
904
|
+
terms: { gap: 4 },
|
|
905
|
+
miniPart: { alignItems: "center", flexDirection: "row", gap: 4 },
|
|
906
|
+
meter: { borderRadius: 2, height: 4, overflow: "hidden", width: 24 },
|
|
907
|
+
dots: { flexDirection: "row", gap: 2 },
|
|
908
|
+
dot6: { borderRadius: 3, height: 6, width: 6 },
|
|
909
|
+
term: { alignItems: "center", flexDirection: "row", gap: 12, justifyContent: "space-between" },
|
|
910
|
+
callerName: { alignItems: "center", flexDirection: "row", gap: 6, maxWidth: "100%" },
|
|
911
|
+
// As wide as the action's 36px tile, so names line up with its title.
|
|
912
|
+
lead: { alignItems: "center", width: 36 },
|
|
913
|
+
});
|