Skip to content

Commit

Permalink
feat: redirect the user to the wallet of coice after successfull VP d…
Browse files Browse the repository at this point in the history
…elegation
  • Loading branch information
Szymon Masłowski committed Nov 21, 2024
1 parent 5a9b705 commit d2233a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type VotingPowerDelegationConfirmationDialogProps = {
onSubmit: (
passphrase?: string
) => Promise<{ success: true } | { success: false; error: string }>;
redirectToWallet: (walletId: string) => void;
selectedWallet: Wallet;
};

Expand All @@ -42,6 +43,7 @@ export function VotingPowerDelegationConfirmationDialog({
onClose,
onExternalLinkClick,
onSubmit,
redirectToWallet,
selectedWallet,
}: VotingPowerDelegationConfirmationDialogProps) {
const [state, setState] = useState<
Expand All @@ -63,15 +65,18 @@ export function VotingPowerDelegationConfirmationDialog({

const result = await onSubmit(passphrase);

if (result.success === false) {
setState({
...state,
error: result.error,
status: 'awaiting',
});
if (result.success === true) {
redirectToWallet(selectedWallet.id);
return;
}

setState({
...state,
error: result.error,
status: 'awaiting',
});
})();
}, [onSubmit, state]);
}, [onSubmit, redirectToWallet, state]);

return (
<Dialog
Expand Down Expand Up @@ -114,6 +119,7 @@ export function VotingPowerDelegationConfirmationDialog({
/>
) : (
<Input
autoFocus
value={state.status === 'awaiting' ? state.passphrase : ''}
onChange={(passphrase) => {
if (state.status !== 'awaiting') return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { inject, observer } from 'mobx-react';
import type { InjectedProps } from '../../types/injectedPropsType';
import VotingPowerDelegation from '../../components/voting/voting-governance/VotingPowerDelegation';
import { VotingPowerDelegationConfirmationDialog } from '../../components/voting/voting-governance/VotingPowerDelegationConfirmationDialog';
import { ROUTES } from '../../routes-config';

type Props = InjectedProps;

Expand Down Expand Up @@ -52,6 +53,14 @@ class VotingGovernancePage extends Component<Props> {
wallet: selectedWallet,
})
}
redirectToWallet={(id) => {
this.props.actions.router.goToRoute.trigger({
route: ROUTES.WALLETS.SUMMARY,
params: {
id,
},
});
}}
selectedWallet={selectedWallet}
/>
)}
Expand Down
3 changes: 0 additions & 3 deletions source/renderer/app/stores/VotingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,6 @@ export default class VotingStore extends Store {
passphrase,
walletId: wallet.id,
}).promise;
await this.actions.router.goToRoute.trigger({
route: ROUTES.WALLETS.SUMMARY,
});

return {
success: true,
Expand Down

0 comments on commit d2233a2

Please sign in to comment.