Skip to content

Commit

Permalink
fix: diff indicator on edit delegation (#3013)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmadek authored Jan 21, 2025
1 parent aac3b70 commit f9488a3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/renderer/entities/governance/ui/BalanceDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const BalanceDiff = memo(({ from, to, asset, lock = BN_ZERO }: Props) =>
to={<AssetBalance value={realTo} asset={asset} showSymbol={false} className="text-inherit" />}
diff={<AssetBalance value={diff.abs()} asset={asset} className="text-inherit" />}
suffix={asset.symbol}
equal={diff.isZero()}
positive={diff.gten(0)}
/>
);
Expand Down
14 changes: 8 additions & 6 deletions src/renderer/entities/governance/ui/DiffValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ type Props = {
suffix?: ReactNode;
diff: ReactNode;
positive?: boolean;
equal?: boolean;
};

export const DiffValue = ({ className, from, to, diff, suffix = null, positive }: Props) => {
export const DiffValue = ({ className, from, to, diff, suffix = null, equal, positive }: Props) => {
return (
<div className={cnTw('flex flex-col items-end', className)}>
<FootnoteText className="flex items-center gap-0.5 text-text-primary">
Expand All @@ -22,11 +23,12 @@ export const DiffValue = ({ className, from, to, diff, suffix = null, positive }
{suffix}
</FootnoteText>
<FootnoteText className="flex items-center text-tab-text-accent">
{positive ? (
<Icon name="arrowDoubleUp" size={16} className="text-inherit" />
) : (
<Icon name="arrowDoubleDown" size={16} className="text-inherit" />
)}
{!equal &&
(positive ? (
<Icon name="arrowDoubleUp" size={16} className="text-inherit" />
) : (
<Icon name="arrowDoubleDown" size={16} className="text-inherit" />
))}
<span>{diff}</span>
</FootnoteText>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/entities/governance/ui/LockPeriodDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const LockPeriodDiff = memo(({ from, to, unlock = false, lockPeriods }: P
diff={t('time.days', {
count: parseInt(formatDistanceStrict(lockPeriods[to], lockPeriods[from], { unit: 'day', locale: dateLocale })),
})}
equal={from === to}
positive={lockPeriods[to] - lockPeriods[from] >= 0}
/>
);
Expand Down
1 change: 1 addition & 0 deletions src/renderer/entities/governance/ui/LockValueDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const LockValueDiff = ({ from, to, asset }: Props) => {
to={<AssetBalance value={reusableTo} asset={asset} showSymbol={false} className="text-inherit" />}
diff={<AssetBalance value={diff} asset={asset} className="text-inherit" />}
suffix={asset.symbol}
equal={diff.isZero()}
positive={diff.gten(0)}
/>
);
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/widgets/EditDelegationModal/model/form-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const $shards = createStore<AnyAccount[]>([]);
const $delegateBalanceRange = createStore<string | string[]>(ZERO_BALANCE);
const $signatoryBalance = createStore<string>(ZERO_BALANCE);
const $proxyBalance = createStore<string>(ZERO_BALANCE);
const $previousConviction = createStore<Conviction>('None');

const $availableSignatories = createStore<AnyAccount[][]>([]);
const $proxyAccount = createStore<AnyAccount | null>(null);
Expand Down Expand Up @@ -382,6 +383,17 @@ sample({
target: $delegateForm.fields.isUnchanged.onChange,
});

sample({
clock: formInitiated,
source: $networkStore,
fn: (network, { activeDelegations, shards }) => {
const address = toAddress(shards[0].accountId, { prefix: network!.chain.addressPrefix });

return activeDelegations[address].conviction;
},
target: $previousConviction,
});

sample({
clock: txWrapperChanged,
target: spread({
Expand Down Expand Up @@ -488,6 +500,7 @@ export const formModel = {
$accountsBalances,
$delegateBalanceRange,
$proxyBalance,
$previousConviction,

$feeData,
$isFeeLoading,
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/widgets/EditDelegationModal/ui/DelegateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ const FeeSection = () => {
const isFeeLoading = useUnit(formModel.$isFeeLoading);
const isMultisig = useUnit(formModel.$isMultisig);
const accounts = useUnit(formModel.$accounts);
const previousConviction = useUnit(formModel.$previousConviction);

const lockPeriods = useStoreMap({
store: lockPeriodsModel.$lockPeriods,
Expand Down Expand Up @@ -242,7 +243,7 @@ const FeeSection = () => {
</DetailRow>

<DetailRow label={t('governance.locks.undelegatePeriod')} wrapperClassName="items-start">
<LockPeriodDiff from="None" to={conviction.value} lockPeriods={lockPeriods} />
<LockPeriodDiff from={previousConviction} to={conviction.value} lockPeriods={lockPeriods} />
</DetailRow>
</>
)}
Expand Down

0 comments on commit f9488a3

Please sign in to comment.