@akita-protocol/algomd-rn 1.0.0-alpha.2 → 1.0.0-alpha.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akita-protocol/algomd-rn",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.3",
4
4
  "main": "src/index.ts",
5
5
  "types": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -79,7 +79,7 @@
79
79
  "vite": "^6.4.3"
80
80
  },
81
81
  "dependencies": {
82
- "@akita-protocol/algomd-core": "1.0.0-alpha.2"
82
+ "@akita-protocol/algomd-core": "1.0.0-alpha.3"
83
83
  },
84
84
  "exports": {
85
85
  ".": "./src/index.ts",
package/src/index.ts CHANGED
@@ -135,7 +135,7 @@ export {
135
135
 
136
136
  export { AppPresentationProvider } from "./presentation/runtime";
137
137
  export { AssetSubjectProvider } from "./presentation/subject";
138
- export type { AppPresentation, AppIdentity } from "./presentation/runtime";
138
+ export type { AppPresentation, AppIdentity, GuildVoteBlock, GuildVoteChoice } from "./presentation/runtime";
139
139
 
140
140
  export * from "./presentation";
141
141
 
@@ -68,6 +68,11 @@ export interface IdentityBadgeProps {
68
68
  size?: number;
69
69
  }
70
70
  export type GuildVoteChoice = "approve" | "reject" | "abstain";
71
+ /**
72
+ * Why the viewer has no vote on this proposal, e.g. "You have no vote in this
73
+ * guild.". A returned reason makes the card read-only for voting.
74
+ */
75
+ export type GuildVoteBlock = (guildAppId: string, proposalId: string) => string | undefined;
71
76
 
72
77
  export type PresentationTextProps = TextProps & {
73
78
  size?: keyof typeof sizes;
@@ -129,12 +134,22 @@ export interface AppPresentation {
129
134
  guildSubmit?: (guildAppId: string, proposalId: string) => void | Promise<void>;
130
135
  guildFinalize?: (guildAppId: string, proposalId: string) => void | Promise<void>;
131
136
  guildExecute?: (guildAppId: string, proposalId: string) => void | Promise<void>;
137
+ /**
138
+ * Withdraws an approved proposal that can't be applied (Guild `cancelProposal`).
139
+ * Offered to its creator once applying it is late or has failed.
140
+ */
141
+ guildCancel?: (guildAppId: string, proposalId: string) => void | Promise<void>;
132
142
  };
133
143
  /**
134
144
  * Why the viewer can't act on this Guild's proposals here, e.g. a chat that
135
145
  * only acts for its own Guild. A returned note replaces the card's actions.
136
146
  */
137
147
  guildActionBlock?: (guildAppId: string) => string | undefined;
148
+ /**
149
+ * Whether the viewer can vote on a proposal: the host knows membership and
150
+ * voting power. Without it the card offers votes to every viewer.
151
+ */
152
+ guildVoteBlock?: GuildVoteBlock;
138
153
  /**
139
154
  * The host closes settled guild votes and carries out approved proposals in
140
155
  * the background. Cards then say so, and offer `guildFinalize` and
@@ -9,6 +9,7 @@ import {
9
9
  type GuildCallerKind,
10
10
  type GuildConsensusInfo,
11
11
  type GuildProposalAction,
12
+ type GuildProposalPayment,
12
13
  } from "@akita-protocol/algomd-core";
13
14
  import { BottomSheetBackdrop, BottomSheetModal, BottomSheetScrollView } from "../presentation/sheets";
14
15
  import { AlgoMarkIcon, BanknotesIcon, ChevronRightIcon, CircleStackIcon, ExclamationTriangleIcon, GuildIcon, PuzzlePieceIcon, UserGroupIcon } from "../presentation/icons";
@@ -327,7 +328,7 @@ function ExecutionLines({ action }: { action: GuildProposalAction }) {
327
328
  <RequirementLines approval={approval} minimumApprovals={minimumApprovals} participation={participation} />
328
329
  {duration !== "0" ? <TermLine label="Voting period">{formatSpan(duration)}</TermLine> : null}
329
330
  {install.vote.fee !== "0" ? (
330
- <TermLine label="Proposal fee">
331
+ <TermLine label="Proposal fee per use">
331
332
  <TokenAmount assetId={feeAsset} amount={fee} />
332
333
  </TermLine>
333
334
  ) : null}
@@ -336,6 +337,23 @@ function ExecutionLines({ action }: { action: GuildProposalAction }) {
336
337
  );
337
338
  }
338
339
 
340
+ /**
341
+ * What the proposer paid for this proposal: the ALGO it holds (storage, plus
342
+ * the fee when the Guild charges ALGO) and the fee in the Guild's token.
343
+ */
344
+ export function GuildProposalPaid({ paid }: { paid: GuildProposalPayment }) {
345
+ const algo = useFormattedAmount(paid.algo, "0");
346
+ const tokens = useFormattedAmount(paid.token?.amount, paid.token?.assetId ?? "0");
347
+ return (
348
+ <TermLine label="Paid to propose">
349
+ <View style={styles.miniPart}>
350
+ <TokenAmount assetId="0" amount={algo} />
351
+ {paid.token ? <TokenAmount assetId={paid.token.assetId} amount={tokens} /> : null}
352
+ </View>
353
+ </TermLine>
354
+ );
355
+ }
356
+
339
357
  /** An amount with its token's icon in front, as a term's value. */
340
358
  function TokenAmount({ assetId, amount }: { assetId: string; amount: string }) {
341
359
  const { theme } = useAppTheme();
@@ -644,10 +662,10 @@ function CallerName({ action, visible }: { action: GuildProposalAction; visible?
644
662
  );
645
663
  }
646
664
 
665
+ /** The caller's name inside an action block. Not pressable: the block itself opens the sheet, where the caller is. */
647
666
  function AccountCallerName({ address, visible }: { address: string; visible?: boolean }) {
648
- const presentation = usePresentation();
649
667
  const { id, name } = useHandle(address, visible);
650
- const value = (
668
+ return (
651
669
  <View style={styles.callerName}>
652
670
  <Avatar uri={id?.avatar} size={16} initial={name} />
653
671
  <View style={{ alignItems: "center", flexDirection: "row", flexShrink: 1, gap: 3 }}>
@@ -658,12 +676,6 @@ function AccountCallerName({ address, visible }: { address: string; visible?: bo
658
676
  </View>
659
677
  </View>
660
678
  );
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
679
  }
668
680
 
669
681
  /** Every term of a plugin action: what its sheet shows. */
@@ -715,7 +727,7 @@ function PluginSheet({ action, name, visible }: { action: GuildProposalAction; n
715
727
  ) : null}
716
728
  {install?.useExecutionKey && action.callerKind === "members" ? (
717
729
  <SheetGroup label="Vote to use it">
718
- <SheetRow label="Proposal fee" value={fee} />
730
+ <SheetRow label="Proposal fee per use" value={fee} />
719
731
  <SheetRow label="Power to propose" value={install.vote.power} />
720
732
  <SheetRow label="Voting period" value={formatSpan(install.vote.duration)} />
721
733
  <SheetRow label="Approval" value={formatGuildPercent(install.vote.approval)} />
@@ -5,6 +5,7 @@ import {
5
5
  guildBallotOutcome,
6
6
  guildProposalStatusLabel,
7
7
  guildRequirementsText,
8
+ guildTallyText,
8
9
  splitGuildProposalId,
9
10
  type GuildBallotData,
10
11
  type GuildProposalData,
@@ -15,7 +16,7 @@ import { GuildIcon, HandThumbDownIcon, HandThumbUpIcon } from "../presentation/i
15
16
  import { PLUGIN_COLORS } from "../presentation/pluginColors";
16
17
  import { Text, useAppTheme, usePresentation, type GuildVoteChoice } from "../presentation/runtime";
17
18
  import { ActionButton, plural, useNow } from "./contractParts";
18
- import { GuildActionList } from "./GuildActions";
19
+ import { GuildActionList, GuildProposalPaid } from "./GuildActions";
19
20
  import {
20
21
  Card,
21
22
  CardHeader,
@@ -33,7 +34,7 @@ import {
33
34
  } from "./primitives";
34
35
  import type { RefViewProps } from "./types";
35
36
 
36
- type CardAction = GuildVoteChoice | "submit" | "finalize" | "execute";
37
+ type CardAction = GuildVoteChoice | "submit" | "finalize" | "execute" | "cancel";
37
38
 
38
39
  const PROGRESS: Record<CardAction, string> = {
39
40
  approve: "Voting yes…",
@@ -42,6 +43,7 @@ const PROGRESS: Record<CardAction, string> = {
42
43
  submit: "Opening the vote…",
43
44
  finalize: "Closing the vote…",
44
45
  execute: "Applying the changes…",
46
+ cancel: "Cancelling the proposal…",
45
47
  };
46
48
 
47
49
  const VOTED: Record<GuildVoteChoice, string> = {
@@ -57,6 +59,7 @@ const STATUS_TONE: Record<GuildProposalStatus, Tone> = {
57
59
  rejected: "bad",
58
60
  approved: "good",
59
61
  executed: "good",
62
+ cancelled: "neutral",
60
63
  };
61
64
 
62
65
  /** How long the host's automation gets before the card offers to do it by hand. */
@@ -158,11 +161,14 @@ function GuildProposalCard({
158
161
  const [busy, setBusy] = useState<CardAction>();
159
162
  const [error, setError] = useState<string>();
160
163
  const [voted, setVoted] = useState<GuildVoteChoice>();
164
+ const [applyFailed, setApplyFailed] = useState(false);
161
165
  const ballot = data.ballot;
162
166
  const outcome = ballot ? guildBallotOutcome(ballot, now) : undefined;
163
167
  const blocked = presentation.guildActionBlock?.(data.guildAppId);
164
168
  const open = data.status === "voting" && !!ballot && !ballot.resolved;
165
169
  const canVote = open && outcome === undefined && now <= Number(ballot!.votingEnd) && !!actions?.guildVote;
170
+ const noVote = canVote ? presentation.guildVoteBlock?.(data.guildAppId, data.proposalId) : undefined;
171
+ const isCreator = !!data.creator && data.creator === presentation.viewerAddress;
166
172
  const settled = open && outcome !== undefined;
167
173
  // Bootstrap proposals (no vote) only run for their creator, so the host's automation skips them.
168
174
  const pendingRun = data.status === "approved" && data.votingTs !== "0";
@@ -182,8 +188,9 @@ function GuildProposalCard({
182
188
  }, [waiting]);
183
189
  const canFinalize = settled && !!actions?.guildFinalize && (!automated || late);
184
190
  const canExecute = (automated ? pendingRun && late : data.status === "approved") && !!actions?.guildExecute;
185
- const canSubmit =
186
- data.status === "draft" && !!data.creator && data.creator === presentation.viewerAddress && !!actions?.guildSubmit;
191
+ const canSubmit = data.status === "draft" && isCreator && !!actions?.guildSubmit;
192
+ // An approved proposal can be impossible to apply, e.g. a plugin the wallet already has. Its creator can withdraw it.
193
+ const canCancel = pendingRun && isCreator && (late || applyFailed) && !!actions?.guildCancel;
187
194
  const statusLabel = settled ? (outcome === "approved" ? "Passed" : "Rejected") : guildProposalStatusLabel(data.status);
188
195
  const statusTone: Tone = settled ? (outcome === "approved" ? "good" : "bad") : STATUS_TONE[data.status];
189
196
 
@@ -198,9 +205,11 @@ function GuildProposalCard({
198
205
  setVoted(action);
199
206
  } else if (action === "submit") await actions?.guildSubmit?.(guildAppId, proposalId);
200
207
  else if (action === "finalize") await actions?.guildFinalize?.(guildAppId, proposalId);
208
+ else if (action === "cancel") await actions?.guildCancel?.(guildAppId, proposalId);
201
209
  else await actions?.guildExecute?.(guildAppId, proposalId);
202
210
  refresh();
203
211
  } catch (cause) {
212
+ if (action === "execute") setApplyFailed(true);
204
213
  setError(cause instanceof Error ? cause.message : "The guild transaction failed.");
205
214
  } finally {
206
215
  setBusy(undefined);
@@ -226,13 +235,15 @@ function GuildProposalCard({
226
235
 
227
236
  {data.actions.length ? <GuildActionList actions={data.actions} consensus={data.consensus} feeAsset={data.feeAsset} visible={visible} /> : null}
228
237
 
238
+ {data.paid.token || full ? <GuildProposalPaid paid={data.paid} /> : null}
239
+
229
240
  {ballot ? (
230
241
  <View style={{ gap: 6 }}>
231
- {guildRequirementsText(ballot) ? <Note>{guildRequirementsText(ballot)}</Note> : null}
242
+ {guildRequirementsText(ballot, data.consensus?.kind) ? <Note>{guildRequirementsText(ballot, data.consensus?.kind)}</Note> : null}
232
243
  <TallyBar ballot={ballot} />
233
244
  <View style={styles.legend}>
234
245
  <Text size="xxs" style={{ color: theme.colors.textDim }}>
235
- {`${ballot.votes.approvals} yes · ${ballot.votes.rejections} no · ${ballot.votes.abstains} abstain`}
246
+ {guildTallyText(ballot, data.consensus?.kind)}
236
247
  </Text>
237
248
  <Text size="xxs" style={{ color: theme.colors.textDim }}>
238
249
  {ballot.resolved ? "Closed" : settled && now <= Number(ballot.votingEnd) ? "Decided early" : timeLeft(ballot.votingEnd, now)}
@@ -249,6 +260,8 @@ function GuildProposalCard({
249
260
  <Text size="xs" weight="semiBold" style={{ color: tone("good") }}>
250
261
  {VOTED[voted]}
251
262
  </Text>
263
+ ) : noVote ? (
264
+ <Note>{noVote}</Note>
252
265
  ) : canVote ? (
253
266
  <View style={styles.buttons}>
254
267
  <ActionButton label="Abstain" variant="text" onPress={() => void run("abstain")} />
@@ -276,6 +289,15 @@ function GuildProposalCard({
276
289
  <ActionButton label="Apply the changes" onPress={() => void run("execute")} />
277
290
  ) : canSubmit ? (
278
291
  <ActionButton label="Open voting" onPress={() => void run("submit")} />
292
+ ) : data.status === "draft" && !isCreator ? (
293
+ <Note>Waiting for the proposer to open voting.</Note>
294
+ ) : null}
295
+
296
+ {canCancel && !blocked && !busy ? (
297
+ <View style={{ gap: 8 }}>
298
+ <Note>If these changes can’t be applied, you can cancel the proposal. Its reserve goes back to whoever paid it.</Note>
299
+ <ActionButton label="Cancel proposal" variant="secondary" onPress={() => void run("cancel")} />
300
+ </View>
279
301
  ) : null}
280
302
 
281
303
  {error ? <Note tone="bad">{error}</Note> : null}