Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: add option to add all events from a given node #5967

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ab7dca
chore: fix breaking changes
maxwellmattryan Feb 23, 2023
8258b30
chore: handle changes for auth object
maxwellmattryan Feb 23, 2023
0ee8944
chore: add migration functionality
maxwellmattryan Feb 23, 2023
aa48793
Merge branch 'develop' into chore/update-wallet.rs
maxwellmattryan Feb 23, 2023
49ca0ac
fix: adjust types and tests
maxwellmattryan Feb 23, 2023
2f5b737
Merge branch 'develop' into chore/update-wallet.rs
maxwellmattryan Feb 23, 2023
886f8f6
Merge branch 'develop' into enhancement/add-option-to-add-all-events-…
maxwellmattryan Feb 23, 2023
4d7b741
Merge branch 'chore/update-wallet.rs' into enhancement/add-option-to-…
maxwellmattryan Feb 23, 2023
c048b8a
enhancement: change form UI
maxwellmattryan Feb 23, 2023
2050d9b
enhancement: register proposals for all nodes
maxwellmattryan Feb 23, 2023
65069dd
enhancement: register all proposals when node added or url edited
maxwellmattryan Feb 23, 2023
f1b03be
chore: optimize registrations
maxwellmattryan Feb 23, 2023
41a90e0
chore: update branches
maxwellmattryan Feb 23, 2023
5e779d8
fix: adjust logic
maxwellmattryan Feb 23, 2023
63824d4
Merge branch `develop` into `enhancement/register-event-for-all-clien…
maxwellmattryan Feb 24, 2023
6dfe6fb
chore: move data migration upwards in app onMount
maxwellmattryan Feb 24, 2023
6badcd2
chore: add usage of `deepCopy` util
maxwellmattryan Feb 24, 2023
233319c
chore: cleanup imports
maxwellmattryan Feb 24, 2023
e6237d8
chore: merge branch
maxwellmattryan Feb 24, 2023
14d897f
fix: optional validation
maxwellmattryan Feb 24, 2023
0a119d2
fix: adjust locale to work with different scenarios
maxwellmattryan Feb 24, 2023
38fe31f
Merge branch 'develop' into enhancement/register-event-for-all-client…
maxwellmattryan Feb 27, 2023
0ecd253
chore: add logic adding proposals to all accounts for all nodes
maxwellmattryan Feb 27, 2023
49d0f71
Merge branch 'develop' into enhancement/register-event-for-all-client…
maxwellmattryan Feb 28, 2023
2f41a1d
chore: refactor code into actions
maxwellmattryan Feb 28, 2023
169d5f3
Merge branch 'develop' into enhancement/register-event-for-all-client…
nicole-obrien Mar 1, 2023
cc1ac16
Merge remote-tracking branch 'origin/enhancement/register-event-for-a…
nicole-obrien Mar 1, 2023
49bcf42
Merge remote-tracking branch 'origin/develop' into enhancement/add-op…
nicole-obrien Mar 1, 2023
fedfd4d
chore: refactor successmessage
MarkNerdi996 Mar 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 26 additions & 13 deletions packages/desktop/components/popups/AddProposalPopup.svelte
Expand Up @@ -21,10 +21,11 @@
let nodeInput: NodeInput
let nodeInputError: string
let isBusy = false
let toAllAccounts = false
let isRegisteringAllProposals = false
let isAddingForAllAccounts = false

$: isEditMode = !!initialEventId && !!initialNodeUrl
$: disabled = !eventId || !nodeUrl || isBusy
$: disabled = isBusy || !nodeUrl || (!isRegisteringAllProposals && !eventId)
$: eventId = inputtedEventId?.trim()

function onCancelClick(): void {
Expand All @@ -34,7 +35,10 @@
async function onSubmit(): Promise<void> {
try {
isBusy = true
await Promise.all([validateEventId(!toAllAccounts && !isEditMode), nodeInput?.validate()])
await Promise.all([
!isRegisteringAllProposals && validateEventId(!isAddingForAllAccounts && !isEditMode),
nodeInput?.validate(),
])
await registerParticipationWrapper()
isBusy = false
} catch (err) {
Expand Down Expand Up @@ -74,28 +78,34 @@
async function registerParticipationWrapper(auth?: Auth): Promise<void> {
const options = {
node: { url: nodeUrl, auth },
eventsToRegister: [eventId],
eventsToRegister: isRegisteringAllProposals ? [] : [eventId],
}
const accounts = toAllAccounts ? $activeAccounts : [$selectedAccount]
const accounts = isAddingForAllAccounts ? $activeAccounts : [$selectedAccount]
await registerProposalsForAccounts(options, accounts)
const successMessage = isEditMode
? localize('views.governance.proposals.successEdit')
: localize('views.governance.proposals.' + (toAllAccounts ? 'successAddAll' : 'successAdd'))
showAppNotification({
type: 'success',
message: successMessage,
message: generateSuccessMessage(),
alert: true,
})
closePopup()
}

function generateSuccessMessage(): string {
if (isEditMode) {
return localize('views.governance.proposals.successEdit')
} else {
return localize(`views.governance.proposals.${isAddingForAllAccounts ? 'successAddAll' : 'successAdd'}`, {
values: { numberOfProposals: isRegisteringAllProposals ? 'other' : 'one' },
})
}
}

async function validateEventId(checkIfAlreadyRegistered: boolean): Promise<void> {
const startsWith0x = eventId?.substring(0, 2) === '0x'
if (!startsWith0x) {
eventIdError = localize('error.eventId.doesNotStartWith0x')
return Promise.reject(eventIdError)
}

const hexLength = eventId?.substring(2)?.length
const has64Length = hexLength === 64
if (!has64Length) {
Expand All @@ -115,16 +125,19 @@
>
<Text fontSize="15">{localize(`popups.${isEditMode ? 'editProposal' : 'addProposal'}.body`)}</Text>
<div class="flex flex-col w-full space-y-4 mt-4">
<NodeInput bind:this={nodeInput} bind:nodeUrl bind:error={nodeInputError} />
{#if !isEditMode}
<Checkbox label="Add all proposals on this node" bind:checked={isRegisteringAllProposals} />
{/if}
<TextInput
bind:value={inputtedEventId}
bind:error={eventIdError}
disabled={isRegisteringAllProposals || isEditMode}
placeholder={localize('views.governance.details.proposalInformation.eventId')}
label={localize('views.governance.details.proposalInformation.eventId')}
disabled={isEditMode}
/>
<NodeInput bind:this={nodeInput} bind:nodeUrl bind:error={nodeInputError} />
{#if !isEditMode}
<Checkbox label={localize('popups.addProposal.addToAllAccounts')} bind:checked={toAllAccounts} />
<Checkbox label={localize('popups.addProposal.addToAllAccounts')} bind:checked={isAddingForAllAccounts} />
nicole-obrien marked this conversation as resolved.
Show resolved Hide resolved
{/if}
</div>
<div class="flex w-full space-x-4 mt-6">
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/locales/en.json
Expand Up @@ -586,8 +586,8 @@
"title": "Proposals",
"voted": "Voted",
"successEdit": "Proposal successfully edited",
"successAdd": "Proposal successfully added",
"successAddAll": "Proposal successfully added to all accounts",
"successAdd": "{numberOfProposals, select, one {Proposal} other {Proposals}} successfully added",
"successAddAll": "{numberOfProposals, select, one {Proposal} other {Proposals}} successfully added to all accounts",
"successRemove": "Proposal successfully removed",
"emptyTitle": "No proposals"
},
Expand Down