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

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.4",
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.4"
83
83
  },
84
84
  "exports": {
85
85
  ".": "./src/index.ts",
@@ -2,6 +2,7 @@ import { isCompactReference, type ReferenceVariantProps } from "../presentation/
2
2
  import { CompactPill } from "../presentation/References";
3
3
  import { StakingPoolDisplay as StakingPoolPresentation } from "../presentation/StakingPoolDisplay";
4
4
  import { OnChainActionButton } from "../presentation/OnChainActionCard";
5
+ import { isCollectibleAsset } from "../presentation/gates";
5
6
  import React from "react";
6
7
  import type {
7
8
  ComponentSize,
@@ -76,7 +77,21 @@ export function StakingPoolComponent({
76
77
  pool.maxEntriesRaw,
77
78
  );
78
79
  const canEnter = signupsAvailable && !entryTargetClosed;
79
- const reward = pool.rewards[0];
80
+ const rewards = pool.rewards.map((item, index) => ({
81
+ assetId: String(item.asset.id),
82
+ name: item.asset.name,
83
+ unitName: item.asset.unitName,
84
+ decimals: item.asset.decimals,
85
+ rateRaw: item.rateRaw,
86
+ distribution: item.distribution,
87
+ intervalSecondsRaw: item.intervalRaw,
88
+ expirationSecondsRaw: item.expirationRaw,
89
+ winnerCountRaw: item.winnerCountRaw,
90
+ budgetRaw: item.budgetRaw,
91
+ // The `imageUrl` prop stands in for the first reward's art.
92
+ imageUrl: (index === 0 ? imageUrl : undefined) ?? item.asset.imageUrl,
93
+ collectible: isCollectibleAsset(item.asset),
94
+ }));
80
95
  return (
81
96
  <SizeContainer size={size} className={className}>
82
97
  <StakingPoolPresentation
@@ -103,24 +118,11 @@ export function StakingPoolComponent({
103
118
  gateId: pool.gateAppId,
104
119
  unrestricted: pool.unrestricted,
105
120
  rewardCount: pool.rewards.length,
106
- primaryReward: reward
107
- ? {
108
- assetId: String(reward.asset.id),
109
- name: reward.asset.name,
110
- unitName: reward.asset.unitName,
111
- decimals: reward.asset.decimals,
112
- rateRaw: reward.rateRaw,
113
- distribution: reward.distribution,
114
- intervalSecondsRaw: reward.intervalRaw,
115
- expirationSecondsRaw: reward.expirationRaw,
116
- winnerCountRaw: reward.winnerCountRaw,
117
- budgetRaw: reward.budgetRaw,
118
- imageUrl: imageUrl ?? reward.asset.imageUrl,
119
- }
120
- : undefined,
121
+ rewards,
122
+ primaryReward: rewards[0],
121
123
  }}
122
124
  action={
123
- // When the pool can't be joined, the card's time line says why.
125
+ // When the pool can't be joined, the card's status and time say why.
124
126
  showEnterButton && onEnter && canEnter ? (
125
127
  <OnChainActionButton
126
128
  label="Join pool"
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
 
@@ -1,26 +1,36 @@
1
1
  // Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
2
- import React, { useEffect, useState } from "react";
2
+ import React, { useCallback, useEffect, useRef, useState } from "react";
3
3
  import { Image, Pressable, StyleSheet, View } from "react-native";
4
+ import * as Haptics from "expo-haptics";
4
5
  import {
6
+ BottomSheetModal,
7
+ BottomSheetBackdrop,
8
+ BottomSheetScrollView,
9
+ } from "./sheets";
10
+ import {
11
+ ChevronRightIcon,
5
12
  OutlineArrowPathIcon as ArrowPathIcon,
6
13
  StakingPoolIcon,
7
14
  } from "./icons";
8
15
  import { formatShortDistance, isShortDistanceDate } from "./format";
9
16
  import { PLUGIN_COLORS } from "./pluginColors";
10
- import { useIsAssetSubject } from "./subject";
11
17
 
12
- import { Text } from "./runtime";
13
- import { useAppTheme } from "./runtime";
18
+ import {
19
+ AppPresentationProvider,
20
+ Text,
21
+ useAppTheme,
22
+ usePresentation,
23
+ } from "./runtime";
14
24
 
15
25
  import { ContractMenu } from "./ContractMenu";
16
26
  import { formatAtomicAmount } from "./format";
17
27
  import {
18
28
  OnChainActionCard,
19
- OnChainActionHeader,
20
29
  OnChainMetric,
21
30
  OnChainMetricGrid,
22
31
  } from "./OnChainActionCard";
23
- import { AdaptiveImage } from "./AdaptiveImage";
32
+ import { ProgressBar } from "./ProgressBar";
33
+ import { StatusBadge } from "./StatusBadge";
24
34
 
25
35
  export type StakingPoolStatus =
26
36
  | "draft"
@@ -44,8 +54,10 @@ export interface StakingPoolRewardDisplayData {
44
54
  winnerCountRaw?: string;
45
55
  /** Reward asset still reserved for this reward, in base units. */
46
56
  budgetRaw?: string;
47
- /** Reward asset art; when present it becomes the card's header. */
57
+ /** Reward asset art: a token's icon or a collectible's picture. */
48
58
  imageUrl?: string;
59
+ /** One of a kind or a small edition: named by its title, with square art. */
60
+ collectible?: boolean;
49
61
  }
50
62
 
51
63
  export interface StakingPoolDisplayData {
@@ -71,6 +83,8 @@ export interface StakingPoolDisplayData {
71
83
  unrestricted?: boolean;
72
84
  finalized?: boolean;
73
85
  rewardCount?: number;
86
+ /** Every reward, in reward order. Defaults to just the primary reward. */
87
+ rewards?: StakingPoolRewardDisplayData[];
74
88
  primaryReward?: StakingPoolRewardDisplayData;
75
89
  }
76
90
 
@@ -243,6 +257,339 @@ export function stakingPoolTimerLabel(
243
257
  }
244
258
  }
245
259
 
260
+ const MAX_REWARD_ICONS = 4;
261
+ const REWARD_ICON_SIZE = 40;
262
+
263
+ /** What the status pill says. A pool that is open but full says so instead. */
264
+ function statusBadgeFor(
265
+ status: StakingPoolStatus,
266
+ entryTargetClosed: boolean,
267
+ ): { label: string; variant: "success" | "warning" | "info" | "neutral" } | undefined {
268
+ if (entryTargetClosed) return { label: "Entries closed", variant: "neutral" };
269
+ switch (status) {
270
+ case "signups":
271
+ return { label: "Sign-ups open", variant: "info" };
272
+ case "active":
273
+ return { label: "Active", variant: "success" };
274
+ case "upcoming":
275
+ return { label: "Upcoming", variant: "neutral" };
276
+ case "ended":
277
+ case "final":
278
+ return { label: "Ended", variant: "neutral" };
279
+ case "draft":
280
+ return { label: "Draft", variant: "warning" };
281
+ default:
282
+ return undefined;
283
+ }
284
+ }
285
+
286
+ const SHEET_SPRING = {
287
+ damping: 70,
288
+ stiffness: 900,
289
+ mass: 2,
290
+ overshootClamping: false,
291
+ };
292
+
293
+ /** "2,500 AKTA"; a single collectible goes by its title, not "1 PUP". */
294
+ function rewardValueLabel(reward: StakingPoolRewardDisplayData): string {
295
+ const amount = formatStakeAmount(reward.rateRaw, reward.decimals);
296
+ if (reward.collectible && reward.name) {
297
+ return amount === "1" ? reward.name : `${amount} × ${reward.name}`;
298
+ }
299
+ const unit =
300
+ reward.unitName || reward.name || (reward.assetId ? `#${reward.assetId}` : "");
301
+ return `${amount} ${unit}`.trim();
302
+ }
303
+
304
+ /** "Shared evenly every week · 5,000 AKTA left". */
305
+ function rewardTermsLabel(reward: StakingPoolRewardDisplayData): string {
306
+ return [
307
+ [rewardSplitLabel(reward), cycleLabel(reward.intervalSecondsRaw)]
308
+ .filter(Boolean)
309
+ .join(" "),
310
+ budgetLabel(reward),
311
+ ]
312
+ .filter(Boolean)
313
+ .join(" · ");
314
+ }
315
+
316
+ /** One reward's picture: a token's round icon, or a collectible's art in a rounded square. */
317
+ function RewardArt({
318
+ reward,
319
+ size,
320
+ ring,
321
+ }: {
322
+ reward: StakingPoolRewardDisplayData;
323
+ size: number;
324
+ /** Outline colour, so overlapped art reads as separate pieces. */
325
+ ring?: string;
326
+ }) {
327
+ const { theme } = useAppTheme();
328
+ const color = PLUGIN_COLORS.StakingPool;
329
+ const border = ring ? 2 : 0;
330
+ return (
331
+ <View
332
+ style={{
333
+ alignItems: "center",
334
+ backgroundColor: reward.imageUrl ? theme.colors.background : `${color}1f`,
335
+ borderColor: ring,
336
+ // Collectible art is cropped to a rounded square so it isn't cut to a circle.
337
+ borderRadius: reward.collectible ? Math.round(size * 0.27) : size / 2,
338
+ borderWidth: border,
339
+ height: size,
340
+ justifyContent: "center",
341
+ overflow: "hidden",
342
+ width: size,
343
+ }}
344
+ >
345
+ {reward.imageUrl ? (
346
+ <Image
347
+ source={{ uri: reward.imageUrl }}
348
+ accessibilityLabel={reward.name}
349
+ style={{ width: size - border * 2, height: size - border * 2 }}
350
+ />
351
+ ) : (
352
+ <StakingPoolIcon size={Math.round(size * 0.45)} color={color} />
353
+ )}
354
+ </View>
355
+ );
356
+ }
357
+
358
+ /** The pool's reward art, overlapped: one piece per distinct reward asset. */
359
+ function RewardArtStack({
360
+ rewards,
361
+ ring,
362
+ }: {
363
+ rewards: StakingPoolRewardDisplayData[];
364
+ ring: string;
365
+ }) {
366
+ const { theme } = useAppTheme();
367
+ const distinct = rewards.filter(
368
+ (item, index) =>
369
+ !item.assetId ||
370
+ rewards.findIndex((other) => other.assetId === item.assetId) === index,
371
+ );
372
+ const shown = distinct.slice(0, MAX_REWARD_ICONS);
373
+ const more = distinct.length - shown.length;
374
+ return (
375
+ <View style={{ alignItems: "center", flexDirection: "row" }}>
376
+ {shown.map((reward, index) => (
377
+ <View
378
+ key={`${reward.assetId ?? ""}-${index}`}
379
+ style={{
380
+ marginLeft: index
381
+ ? reward.collectible || shown[index - 1].collectible
382
+ ? -8
383
+ : -12
384
+ : 0,
385
+ }}
386
+ >
387
+ <RewardArt reward={reward} size={REWARD_ICON_SIZE} ring={ring} />
388
+ </View>
389
+ ))}
390
+ {more > 0 ? (
391
+ <Text
392
+ size="xxs"
393
+ weight="bold"
394
+ style={{ color: theme.colors.textDim, marginLeft: 6 }}
395
+ >
396
+ +{more}
397
+ </Text>
398
+ ) : null}
399
+ </View>
400
+ );
401
+ }
402
+
403
+ /** Every reward a pool pays, one row each, for the rewards sheet. */
404
+ function RewardList({
405
+ rewards,
406
+ count,
407
+ }: {
408
+ rewards: StakingPoolRewardDisplayData[];
409
+ count: number;
410
+ }) {
411
+ const { theme } = useAppTheme();
412
+ const unlisted = count - rewards.length;
413
+ return (
414
+ <View style={{ gap: 6 }}>
415
+ <View style={{ gap: 4 }}>
416
+ <Text size="md" weight="bold">
417
+ {`${count.toLocaleString()} rewards`}
418
+ </Text>
419
+ <Text size="xs" style={{ color: theme.colors.textDim }}>
420
+ What this pool pays the people who join it.
421
+ </Text>
422
+ </View>
423
+ {rewards.map((reward, index) => {
424
+ const value = rewardValueLabel(reward);
425
+ const terms = rewardTermsLabel(reward);
426
+ return (
427
+ <View
428
+ key={`${reward.assetId ?? ""}-${index}`}
429
+ accessible
430
+ accessibilityLabel={`${value}, ${terms}`}
431
+ style={{
432
+ alignItems: "center",
433
+ flexDirection: "row",
434
+ gap: 12,
435
+ paddingVertical: 8,
436
+ }}
437
+ >
438
+ <RewardArt reward={reward} size={REWARD_ICON_SIZE} />
439
+ <View style={{ flex: 1, gap: 2 }}>
440
+ <Text size="sm" weight="semiBold" numberOfLines={2}>
441
+ {value}
442
+ </Text>
443
+ <Text
444
+ size="xxs"
445
+ numberOfLines={2}
446
+ style={{ color: theme.colors.textDim }}
447
+ >
448
+ {terms}
449
+ </Text>
450
+ </View>
451
+ </View>
452
+ );
453
+ })}
454
+ {unlisted > 0 ? (
455
+ <Text size="xs" style={{ color: theme.colors.textDim }}>
456
+ {`And ${unlisted.toLocaleString()} more.`}
457
+ </Text>
458
+ ) : null}
459
+ </View>
460
+ );
461
+ }
462
+
463
+ /**
464
+ * What the pool pays, as one row: the reward art and its words side by side. One
465
+ * reward is spelled out. Several are counted, and the row opens the full list in a
466
+ * bottom sheet, the same way a gate's requirements open.
467
+ */
468
+ function PoolRewards({
469
+ rewards,
470
+ count,
471
+ ring,
472
+ dimmed,
473
+ }: {
474
+ rewards: StakingPoolRewardDisplayData[];
475
+ count: number;
476
+ ring: string;
477
+ dimmed: boolean;
478
+ }) {
479
+ const { theme } = useAppTheme();
480
+ const presentation = usePresentation();
481
+ const PortalProvider =
482
+ presentation.components?.PortalProvider ?? React.Fragment;
483
+ const sheetRef = useRef<BottomSheetModal>(null);
484
+ useEffect(() => {
485
+ const sheet = sheetRef.current;
486
+ return () => sheet?.dismiss();
487
+ }, []);
488
+ const open = useCallback(() => {
489
+ Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
490
+ sheetRef.current?.present();
491
+ }, []);
492
+ const several = count > 1;
493
+ const first = rewards[0];
494
+ const names = [
495
+ ...new Set(
496
+ rewards
497
+ .map((reward) =>
498
+ reward.collectible ? reward.name : reward.unitName || reward.name,
499
+ )
500
+ .filter((name): name is string => !!name),
501
+ ),
502
+ ];
503
+ const title = several
504
+ ? `${count.toLocaleString()} rewards`
505
+ : rewardValueLabel(first);
506
+ const detail = several
507
+ ? names.length > 2
508
+ ? `${names.slice(0, 2).join(", ")} and ${names.length - 2} more`
509
+ : names.join(" and ")
510
+ : rewardTermsLabel(first);
511
+ const row = (
512
+ <View
513
+ style={{
514
+ alignItems: "center",
515
+ flexDirection: "row",
516
+ gap: 10,
517
+ opacity: dimmed ? 0.6 : 1,
518
+ }}
519
+ >
520
+ <RewardArtStack rewards={rewards} ring={ring} />
521
+ <View style={{ flex: 1, gap: 1, minWidth: 0 }}>
522
+ <Text size="sm" weight="semiBold" numberOfLines={1}>
523
+ {title}
524
+ </Text>
525
+ {detail ? (
526
+ <Text
527
+ size="xxs"
528
+ numberOfLines={several ? 1 : 2}
529
+ style={{ color: theme.colors.textDim }}
530
+ >
531
+ {detail}
532
+ </Text>
533
+ ) : null}
534
+ </View>
535
+ {several ? (
536
+ <ChevronRightIcon size={16} color={theme.colors.textDim} />
537
+ ) : null}
538
+ </View>
539
+ );
540
+ if (!several) {
541
+ return (
542
+ <View accessible accessibilityLabel={`Reward: ${title}, ${detail}`}>
543
+ {row}
544
+ </View>
545
+ );
546
+ }
547
+ return (
548
+ <>
549
+ <Pressable
550
+ accessibilityRole="button"
551
+ accessibilityLabel={`${title}: ${detail}`}
552
+ accessibilityHint="Shows every reward"
553
+ onPress={open}
554
+ style={({ pressed }) => (pressed ? { opacity: 0.7 } : null)}
555
+ >
556
+ {row}
557
+ </Pressable>
558
+ <BottomSheetModal
559
+ ref={sheetRef}
560
+ enableDynamicSizing
561
+ backgroundStyle={{ backgroundColor: theme.colors.background }}
562
+ handleIndicatorStyle={{ backgroundColor: theme.colors.border }}
563
+ animationConfigs={SHEET_SPRING}
564
+ backdropComponent={(
565
+ props: React.ComponentProps<typeof BottomSheetBackdrop>,
566
+ ) => (
567
+ <BottomSheetBackdrop
568
+ {...props}
569
+ appearsOnIndex={0}
570
+ disappearsOnIndex={-1}
571
+ pressBehavior="close"
572
+ />
573
+ )}
574
+ >
575
+ <PortalProvider>
576
+ <AppPresentationProvider {...presentation}>
577
+ <BottomSheetScrollView
578
+ contentContainerStyle={{
579
+ paddingHorizontal: 20,
580
+ paddingTop: 4,
581
+ paddingBottom: 40,
582
+ }}
583
+ >
584
+ <RewardList rewards={rewards} count={count} />
585
+ </BottomSheetScrollView>
586
+ </AppPresentationProvider>
587
+ </PortalProvider>
588
+ </BottomSheetModal>
589
+ </>
590
+ );
591
+ }
592
+
246
593
  export function StakingPoolDisplay({
247
594
  data,
248
595
  notice,
@@ -252,58 +599,48 @@ export function StakingPoolDisplay({
252
599
  const { theme } = useAppTheme();
253
600
  const poolColor = PLUGIN_COLORS.StakingPool;
254
601
  const reward = data.primaryReward;
255
- // On the reward's own page its art is already shown above.
256
- const onSubjectPage = useIsAssetSubject(reward?.assetId);
257
602
  const live =
258
603
  data.status === "upcoming" ||
259
604
  data.status === "signups" ||
260
605
  data.status === "active";
606
+ const over = data.status === "ended" || data.status === "final";
261
607
  const now = useNow(live);
608
+ const capacity =
609
+ data.maxEntries != null && data.maxEntries > 0 ? data.maxEntries : undefined;
262
610
  const entryTargetClosed =
263
611
  (data.status === "signups" ||
264
612
  (data.status === "active" && data.allowLateSignups === true)) &&
265
- data.maxEntries != null &&
266
- data.maxEntries > 0 &&
613
+ capacity != null &&
267
614
  data.entryCount != null &&
268
- data.entryCount >= data.maxEntries - 1;
615
+ data.entryCount >= capacity - 1;
269
616
  const endingSoon =
270
617
  data.status === "active" &&
271
618
  !!data.endTime &&
272
619
  data.endTime.getTime() - now < 60 * 60 * 1000;
273
- const timerLabel = entryTargetClosed
274
- ? "Entries closed"
275
- : stakingPoolTimerLabel(data, now);
620
+ const timerLabel = stakingPoolTimerLabel(data, now);
621
+ const status = statusBadgeFor(data.status, entryTargetClosed);
276
622
  const entries =
277
623
  data.entryCount == null
278
624
  ? undefined
279
- : data.maxEntries != null && data.maxEntries > 0
280
- ? `${data.entryCount.toLocaleString()} of ${data.maxEntries.toLocaleString()} entries`
625
+ : capacity != null
626
+ ? `${data.entryCount.toLocaleString()} of ${capacity.toLocaleString()} entries`
281
627
  : `${data.entryCount.toLocaleString()} ${data.entryCount === 1 ? "entry" : "entries"}`;
628
+ const filled =
629
+ capacity != null && data.entryCount != null
630
+ ? Math.min(1, data.entryCount / capacity)
631
+ : undefined;
282
632
  const stakeFigure = stakeFigureFor(data);
283
- const rewardIcon = reward?.imageUrl ? (
284
- <Image
285
- source={{ uri: reward.imageUrl }}
286
- style={{ width: 16, height: 16, borderRadius: 8 }}
287
- />
288
- ) : null;
289
- const moreRewards =
290
- data.rewardCount && data.rewardCount > 1
291
- ? `+${data.rewardCount - 1} more ${data.rewardCount === 2 ? "reward" : "rewards"}`
633
+ const totalStaked =
634
+ data.stakeDecimals != null &&
635
+ data.totalStaked &&
636
+ /^\d+$/.test(data.totalStaked) &&
637
+ BigInt(data.totalStaked) > BigInt(0)
638
+ ? `${formatStakeAmount(data.totalStaked, data.stakeDecimals)} ${data.stakeUnitName ?? ""}`.trim()
292
639
  : undefined;
293
- const budgetLeft = reward ? budgetLabel(reward) : undefined;
294
- const rewardDetail = reward
295
- ? [
296
- [rewardSplitLabel(reward), cycleLabel(reward.intervalSecondsRaw)]
297
- .filter(Boolean)
298
- .join(" "),
299
- budgetLeft,
300
- moreRewards,
301
- ]
302
- .filter(Boolean)
303
- .join(" · ")
304
- : undefined;
640
+ const rewards = data.rewards ?? (reward ? [reward] : []);
641
+ const rewardTotal = Math.max(data.rewardCount ?? 0, rewards.length);
305
642
  // Say who can join only when the pool says so; unknown stays unsaid.
306
- const subtitle = [
643
+ const terms = [
307
644
  poolTypeLabel(data.poolType),
308
645
  data.unrestricted === true
309
646
  ? "Open to anyone"
@@ -314,52 +651,125 @@ export function StakingPoolDisplay({
314
651
  .filter(Boolean)
315
652
  .join(" · ");
316
653
 
654
+ // Read top to bottom: what it is and whether it is open, what it pays (art and
655
+ // words side by side), how full it is, the terms, then the way in.
317
656
  return (
318
657
  <OnChainActionCard
319
- accessibilityLabel={[data.title, "staking pool", timerLabel]
658
+ accessibilityLabel={[data.title, "staking pool", status?.label, timerLabel]
320
659
  .filter(Boolean)
321
660
  .join(", ")}
322
661
  testID={`staking-pool-card-${data.id}`}
323
- media={
324
- reward?.imageUrl && !onSubjectPage ? (
325
- <AdaptiveImage
326
- uri={reward.imageUrl}
327
- assetId={reward.assetId}
328
- maxHeight={220}
329
- borderRadiusTop={0}
330
- fill
331
- />
332
- ) : undefined
333
- }
334
662
  >
335
- <OnChainActionHeader
336
- eyebrow="Staking pool"
337
- eyebrowColor={poolColor}
338
- eyebrowIcon={<StakingPoolIcon size={13} color={poolColor} />}
339
- title={data.title}
340
- subtitle={subtitle}
341
- menu={<ContractMenu appId={data.id} embedType="StakingPool" />}
342
- />
663
+ <View style={{ gap: 2 }}>
664
+ <View style={{ alignItems: "center", flexDirection: "row", gap: 8 }}>
665
+ <View
666
+ style={{
667
+ alignItems: "center",
668
+ flex: 1,
669
+ flexDirection: "row",
670
+ gap: 4,
671
+ minWidth: 0,
672
+ }}
673
+ >
674
+ <StakingPoolIcon size={13} color={poolColor} />
675
+ <Text
676
+ size="xxs"
677
+ weight="semiBold"
678
+ style={{
679
+ color: poolColor,
680
+ letterSpacing: 0.6,
681
+ textTransform: "uppercase",
682
+ }}
683
+ >
684
+ Staking pool
685
+ </Text>
686
+ </View>
687
+ {status ? (
688
+ <StatusBadge label={status.label} variant={status.variant} />
689
+ ) : null}
690
+ <ContractMenu appId={data.id} embedType="StakingPool" />
691
+ </View>
692
+ <Text
693
+ accessibilityRole="header"
694
+ size="md"
695
+ weight="semiBold"
696
+ numberOfLines={2}
697
+ style={over ? { color: theme.colors.textDim } : undefined}
698
+ >
699
+ {data.title}
700
+ </Text>
701
+ <View style={{ flexDirection: "row", flexWrap: "wrap" }}>
702
+ <Text size="xs" style={{ color: theme.colors.textDim }}>
703
+ {timerLabel ? `${terms} · ` : terms}
704
+ </Text>
705
+ {timerLabel ? (
706
+ <Text
707
+ size="xs"
708
+ weight={endingSoon ? "semiBold" : undefined}
709
+ accessibilityLiveRegion="polite"
710
+ style={{
711
+ color: endingSoon
712
+ ? (theme.colors.secondary ?? theme.colors.primary)
713
+ : theme.colors.textDim,
714
+ }}
715
+ >
716
+ {timerLabel}
717
+ </Text>
718
+ ) : null}
719
+ </View>
720
+ </View>
343
721
 
344
- <OnChainMetricGrid>
345
- {reward ? (
346
- <OnChainMetric
347
- label="Reward"
348
- valueIcon={rewardIcon}
349
- value={`${formatStakeAmount(reward.rateRaw, reward.decimals)} ${reward.unitName || ""}`.trim()}
350
- secondary={rewardDetail}
351
- />
352
- ) : null}
353
- {stakeFigure ? (
354
- <OnChainMetric
355
- label={stakeFigure.label}
356
- value={stakeFigure.value}
357
- secondary={entries}
358
- />
359
- ) : (
360
- <OnChainMetric label="Entries" value={entries ?? "Not indexed"} />
361
- )}
362
- </OnChainMetricGrid>
722
+ {rewards.length ? (
723
+ <PoolRewards
724
+ rewards={rewards}
725
+ count={rewardTotal}
726
+ ring={theme.colors.accentBackground}
727
+ dimmed={over}
728
+ />
729
+ ) : null}
730
+
731
+ {entries ? (
732
+ <View style={{ gap: 8 }}>
733
+ <View
734
+ style={{
735
+ alignItems: "baseline",
736
+ flexDirection: "row",
737
+ gap: 8,
738
+ justifyContent: "space-between",
739
+ }}
740
+ >
741
+ <Text size="xs" weight="semiBold">
742
+ {entries}
743
+ </Text>
744
+ {filled != null ? (
745
+ <Text size="xs" style={{ color: theme.colors.textDim }}>
746
+ {filled >= 1 ? "Full" : `${Math.floor(filled * 100)}%`}
747
+ </Text>
748
+ ) : null}
749
+ </View>
750
+ {filled != null ? (
751
+ <ProgressBar
752
+ progress={
753
+ data.entryCount ? Math.max(filled, 0.02) : 0
754
+ }
755
+ height={6}
756
+ color={over ? theme.colors.textDim : theme.colors.primary}
757
+ trackColor={`${theme.colors.textDim}26`}
758
+ />
759
+ ) : null}
760
+ </View>
761
+ ) : null}
762
+
763
+ {stakeFigure || totalStaked ? (
764
+ <OnChainMetricGrid>
765
+ {stakeFigure ? (
766
+ <OnChainMetric label={stakeFigure.label} value={stakeFigure.value} />
767
+ ) : null}
768
+ {totalStaked ? (
769
+ <OnChainMetric label="Total staked" value={totalStaked} />
770
+ ) : null}
771
+ </OnChainMetricGrid>
772
+ ) : null}
363
773
 
364
774
  {notice ? (
365
775
  <View style={[styles.notice, { backgroundColor: `${theme.colors.warning}12` }]}>
@@ -381,25 +791,7 @@ export function StakingPoolDisplay({
381
791
  ) : null}
382
792
  </View>
383
793
  ) : null}
384
- {timerLabel || action ? (
385
- <View style={{ gap: 8 }}>
386
- {timerLabel ? (
387
- <Text
388
- size="xs"
389
- weight="semiBold"
390
- accessibilityLiveRegion="polite"
391
- style={{
392
- color: endingSoon
393
- ? (theme.colors.secondary ?? theme.colors.primary)
394
- : theme.colors.textDim,
395
- }}
396
- >
397
- {timerLabel}
398
- </Text>
399
- ) : null}
400
- {action}
401
- </View>
402
- ) : null}
794
+ {action}
403
795
  </OnChainActionCard>
404
796
  );
405
797
  }
@@ -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}