Skip to content

Commit

Permalink
Fix: delegations bugs (#2110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmadek authored Aug 19, 2024
1 parent 251c178 commit b3dfe1e
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 165 deletions.
2 changes: 1 addition & 1 deletion src/renderer/entities/wallet/lib/account-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function isNonBaseVaultAccount(account: Account, wallet: Wallet): boolean {

function getAddressesForWallet(wallet: Wallet, chain: Chain) {
const matchedAccounts = walletUtils.getAccountsBy([wallet], (account) => {
return isChainIdMatch(account, chain.chainId);
return accountUtils.isNonBaseVaultAccount(account, wallet) && isChainIdMatch(account, chain.chainId);
});

return matchedAccounts.map((a) => toAddress(a.accountId, { prefix: chain.addressPrefix }));
Expand Down
55 changes: 38 additions & 17 deletions src/renderer/shared/api/translation/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@
"message": "Tell us more about yourself so Spektr users get to know you better.",
"title": "Are you a delegate?"
},
"alreadyDelegatedError": "Already delegated",
"balanceValue": "<balance /> × {conviction}x",
"cantAddDelegationTitle": "You can't add a delegation",
"card": {
Expand Down Expand Up @@ -366,6 +367,7 @@
"selectAll": "Select all",
"treasury": "Treasury"
},
"invalidAddressError": "Invalid address",
"manyAccountsPlaceholder": "Select accounts",
"multishardDescription": "You can select multiple accounts and delegate them in several tracks. If you are already delegating an account and want to add more tracks, select it separately.",
"proxyRestrictionMessage": "Please add a new proxy connections to delegate",
Expand All @@ -378,11 +380,46 @@
"votes": "Delegated votes"
},
"title": "Add delegation on",
"tracks": {
"crowdloans": "Auction admin",
"crowdloansDescription": "Origin for starting auctions.",
"fellowshipAdmin": "Fellowship: Admin",
"fellowshipAdminDescription": "Origin for managing the composition of the fellowship.",
"fellowshipWhitelist": "Fellowship: Whitelist",
"fellowshipWhitelistDescription": "Origin commanded by members of the Polkadot Fellowship.",
"governanceCanceller": "Governance: Canceller",
"governanceCancellerDescription": "Origin able to cancel referenda.",
"governanceKiller": "Governance: Killer",
"governanceKillerDescription": "Origin able to kill referenda.",
"governanceLease": "Lease admin",
"governanceLeaseDescription": "Origin able to force slot leases.",
"governanceRegistrar": "Governance: Registrar",
"governanceRegistrarDescription": "Origin for managing the registrar.",
"mainAgenda": "Root",
"mainAgendaDescription": "Origin for upgrades, fixes, and network rescues.",
"staking": "Staking admin",
"stakingDescription": "Origin for canceling slashes.",
"treasuryAny": "Treasury: Any",
"treasuryAnyDescription": "Origin for spending (any amount of) funds until the upper limit of 10,000,000 DOT or equivalent value in stablecoins.",
"treasuryBigSpend": "Treasury: Big spend",
"treasuryBigSpendDescription": "Origin able to spend up to 1,000,000 DOT from the treasury at once or equivalent value in stablecoins.",
"treasuryBigTips": "Treasury: Big tips",
"treasuryBigTipsDescription": "Origin able to spend up to 1,000 DOT from the treasury at once or equivalent value in stablecoins.",
"treasuryMediumSpend": "Treasury: Medium spend",
"treasuryMediumSpendDescription": "Origin able to spend up to 100,000 DOT from the treasury at once or equivalent value in stablecoins.",
"treasurySmallSpend": "Treasury: Small spend",
"treasurySmallSpendDescription": "Origin able to spend up to 10,000 DOT from the treasury at once or equivalent value in stablecoins.",
"treasurySmallTips": "Treasury: Small tips",
"treasurySmallTipsDescription": "Origin able to spend up to 250 DOT from the treasury at once or equivalent value in stablecoins.",
"wishForChange": "Wish for change",
"wishForChangeDescription": "Origin for signaling that the network wishes for some change."
},
"tracksLabel": "Tracks",
"viewDelegationButton": "View delegations",
"votesLabel": "Voting power",
"votesValue": "<votes /> votes",
"walletTypeRestrictionError": "You can't add a delegation in that wallet type",
"yourAccountError": "You cannot delegate to the same account",
"yourDelegation": "Your Delegation",
"yourDelegationsTitle": "Your delegations"
},
Expand Down Expand Up @@ -469,45 +506,29 @@
"cancelled": "Cancelled",
"completed": "Completed",
"crowdloans": "Crowdloans",
"crowdloansDescription": "Origin for starting auctions.",
"deciding": "Deciding",
"executed": "Executed",
"fellowshipAdmin": "Fellowship: Admin",
"fellowshipAdminDescription": "Origin for managing the composition of the fellowship.",
"fellowshipWhitelist": "Fellowship: Whitelist",
"fellowshipWhitelistDescription": "Origin commanded by any members of the Polkadot Fellowship (no Dan grade needed).",
"governanceCanceller": "Governance: Canceller",
"governanceCancellerDescription": "Origin able to cancel referenda.",
"governanceKiller": "Governance: Killer",
"governanceKillerDescription": "Origin able to kill referenda.",
"governanceLease": "Governance: Lease",
"governanceLeaseDescription": "Origin able to force slot leases.",
"governanceRegistrar": "Governance: Registrar",
"governanceRegistrarDescription": "Origin for managing the registrar.",
"killed": "Killed",
"mainAgenda": "Main agenda",
"mainAgendaDescription": "Origin for upgrades, fixes, and network rescues.",
"ongoing": "Ongoing",
"passing": "Passing",
"referendumTitle": "Referendum #{ index }",
"rejected": "Rejected",
"staking": "Staking",
"stakingDescription": "Origin for canceling slashes.",
"timedOut": "Timed out",
"treasuryAny": "Treasury: Any",
"treasuryAnyDescription": "Origin for spending (any amount of) funds until the upper limit of 10,000,000 DOT.",
"treasuryBigSpend": "Treasury: Big spend",
"treasuryBigSpendDescription": "Origin able to spend up to 1,000,000 DOT from the treasury at once.",
"treasuryBigTips": "Treasury: Big tips",
"treasuryBigTipsDescription": "Origin able to spend up to 1,000 DOT from the treasury at once.",
"treasuryMediumSpend": "Treasury: Medium spend",
"treasuryMediumSpendDescription": "Origin able to spend up to 100,000 DOT from the treasury at once.",
"treasurySmallDescription": "Origin able to spend up to 10,000 DOT from the treasury at once.",
"treasurySmallSpend": "Treasury: Small spend",
"treasurySmallTips": "Treasury: Small tips",
"treasurySmallTipsDescription": "Origin able to spend up to 250 DOT from the treasury at once.",
"wishForChange": "Wish for change",
"wishForChangeDescription": "Origin for signaling that the network wishes for some change."
"wishForChange": "Wish for change"
},
"searchPlaceholder": "Search",
"timeline": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ export const delegateDetailsModel = {
$delegate,
$activeAccounts,
$activeTracks,
$uniqueTracks: $activeTracks.map((tracks) => [...new Set(...Object.values(tracks))]),
$uniqueTracks: $activeTracks.map((tracks) => [
...new Set(
Object.values(tracks)
.map((t) => [...t])
.flat(),
),
]),
$activeDelegations: delegationAggregate.$activeDelegations,

$isAddAvailable,
Expand Down
50 changes: 26 additions & 24 deletions src/renderer/widgets/DelegateDetails/ui/YourDelegation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const YourDelegation = () => {
{activeAccounts.length === 1 ? (
<AddressWithExplorers type="short" address={activeAccounts[0]} explorers={chain?.explorers} />
) : (
activeAccounts.length
<FootnoteText className="text-text-secondary">{activeAccounts.length}</FootnoteText>
)}
</DetailRow>

Expand All @@ -52,29 +52,31 @@ export const YourDelegation = () => {
</Tooltip>
</DetailRow>

<DetailRow label={t('governance.addDelegation.votesLabel')}>
<FootnoteText>
<Trans
t={t}
i18nKey="governance.addDelegation.votesValue"
components={{
votes: (
<AssetBalance
value={activeDelegations[activeAccounts[0]]?.balance
.mul(
new BN(
votingService.getConvictionMultiplier(activeDelegations[activeAccounts[0]]?.conviction),
),
)
.toString()}
asset={chain?.assets[0]}
showSymbol={false}
/>
),
}}
/>
</FootnoteText>
</DetailRow>
{activeAccounts.length === 1 && (
<DetailRow label={t('governance.addDelegation.votesLabel')}>
<FootnoteText>
<Trans
t={t}
i18nKey="governance.addDelegation.votesValue"
components={{
votes: (
<AssetBalance
value={activeDelegations[activeAccounts[0]]?.balance
.mul(
new BN(
votingService.getConvictionMultiplier(activeDelegations[activeAccounts[0]]?.conviction),
),
)
.toString()}
asset={chain?.assets[0]}
showSymbol={false}
/>
),
}}
/>
</FootnoteText>
</DetailRow>
)}
</div>
)}

Expand Down
85 changes: 49 additions & 36 deletions src/renderer/widgets/DelegateModal/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,93 @@
export const adminTracks = [
{ id: '0', value: 'governance.referendums.mainAgenda', description: 'governance.referendums.mainAgendaDescription' },
{
id: '1',
value: 'governance.referendums.fellowshipWhitelist',
description: 'governance.referendums.fellowshipWhitelistDescription',
id: '0',
value: 'governance.addDelegation.tracks.mainAgenda',
description: 'governance.referendums.mainAgendaDescription',
},
{
id: '2',
value: 'governance.referendums.wishForChange',
description: 'governance.referendums.wishForChangeDescription',
value: 'governance.addDelegation.tracks.wishForChange',
description: 'governance.addDelegation.tracks.wishForChangeDescription',
},
{
id: '20',
value: 'governance.addDelegation.tracks.governanceCanceller',
description: 'governance.addDelegation.tracks.governanceCancellerDescription',
},

{
id: '15',
value: 'governance.addDelegation.tracks.crowdloans',
description: 'governance.addDelegation.tracks.crowdloansDescription',
},
{ id: '15', value: 'governance.referendums.crowdloans', description: 'governance.referendums.crowdloansDescription' },
];

export const governanceTracks = [
{
id: '12',
value: 'governance.referendums.governanceLease',
description: 'governance.referendums.governanceLeaseDescription',
value: 'governance.addDelegation.tracks.governanceLease',
description: 'governance.addDelegation.tracks.governanceLeaseDescription',
},
{
id: '14',
value: 'governance.referendums.governanceRegistrar',
description: 'governance.referendums.governanceRegistrarDescription',
id: '21',
value: 'governance.addDelegation.tracks.governanceKiller',
description: 'governance.addDelegation.tracks.governanceKillerDescription',
},
{
id: '20',
value: 'governance.referendums.governanceCanceller',
description: 'governance.referendums.governanceCancellerDescription',
id: '11',
value: 'governance.addDelegation.tracks.treasuryAny',
description: 'governance.addDelegation.tracks.treasuryAnySpendDescription',
},
{
id: '21',
value: 'governance.referendums.governanceKiller',
description: 'governance.referendums.governanceKillerDescription',
id: '14',
value: 'governance.addDelegation.tracks.governanceRegistrar',
description: 'governance.addDelegation.tracks.governanceRegistrarDescription',
},
{
id: '10',
value: 'governance.addDelegation.tracks.staking',
description: 'governance.referendums.stakingDescription',
},
{ id: '10', value: 'governance.referendums.staking', description: 'governance.referendums.stakingDescription' },
];

export const treasuryTracks = [
{
id: '30',
value: 'governance.referendums.treasurySmallTips',
description: 'governance.referendums.treasurySmallTipsDescription',
value: 'governance.addDelegation.tracks.treasurySmallTips',
description: 'governance.addDelegation.tracks.treasurySmallTipsDescription',
},
{
id: '31',
value: 'governance.referendums.treasuryBigTips',
description: 'governance.referendums.treasuryBigTipsDescription',
value: 'governance.addDelegation.tracks.treasuryBigTips',
description: 'governance.addDelegation.tracks.treasuryBigTipsDescription',
},
{
id: '32',
value: 'governance.referendums.treasurySmallSpend',
description: 'governance.referendums.treasurySmallSpendDescription',
value: 'governance.addDelegation.tracks.treasurySmallSpend',
description: 'governance.addDelegation.tracks.treasurySmallSpendDescription',
},
{
id: '33',
value: 'governance.referendums.treasuryMediumSpend',
description: 'governance.referendums.treasuryMediumSpendDescription',
value: 'governance.addDelegation.tracks.treasuryMediumSpend',
description: 'governance.addDelegation.tracks.treasuryMediumSpendDescription',
},
{
id: '34',
value: 'governance.referendums.treasuryBigSpend',
description: 'governance.referendums.treasuryBigSpendDescription',
},
{
id: '11',
value: 'governance.referendums.treasuryAny',
description: 'governance.referendums.treasuryAnySpendDescription',
value: 'governance.addDelegation.tracks.treasuryBigSpend',
description: 'governance.addDelegation.tracks.treasuryBigSpendDescription',
},
];

export const fellowshipTracks = [
{
id: '1',
value: 'governance.addDelegation.tracks.fellowshipWhitelist',
description: 'governance.addDelegation.tracks.fellowshipWhitelistDescription',
},
{
id: '13',
value: 'governance.referendums.fellowshipAdmin',
description: 'governance.referendums.fellowshipAdminDescription',
value: 'governance.addDelegation.tracks.fellowshipAdmin',
description: 'governance.addDelegation.tracks.fellowshipAdminDescription',
},
];

Expand Down
Loading

0 comments on commit b3dfe1e

Please sign in to comment.