Skip to content

Commit

Permalink
WIP: create a delegation tx to be later used for VP delegation with s…
Browse files Browse the repository at this point in the history
…wapped certificate
  • Loading branch information
szymonmaslowski committed Nov 22, 2024
1 parent 25cf89e commit 28ef4bd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,13 @@ class WalletSettings extends Component<Props, State> {
undelegateWalletDialogContainer,
} = this.props;

console.log(
'!DEBUG IS_WALLET_UNDELEGATION_ENABLED',
IS_WALLET_UNDELEGATION_ENABLED
);

/// @TODO: Once undelegation for rewarded wallet works fine with api, remove reward checking and config
if (!IS_WALLET_UNDELEGATION_ENABLED || isLegacy) {
if (IS_WALLET_UNDELEGATION_ENABLED || isLegacy) {
return null;
}

Expand Down
53 changes: 52 additions & 1 deletion source/renderer/app/stores/VotingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import type { CatalystFund } from '../api/voting/types';
import { EventCategories } from '../analytics';
import type { DelegationCalculateFeeResponse } from '../api/staking/types';
import Wallet from '../domains/Wallet';
import { logger } from '../utils/logging';
import ApiError from '../domains/ApiError';
import type { DelegationAction } from '../types/stakingTypes';

export type VotingRegistrationKeyType = {
bytes: (...args: Array<any>) => any;
Expand Down Expand Up @@ -277,6 +277,57 @@ export default class VotingStore extends Store {
wallet: Wallet;
}) => {
this.constructTxRequest.reset();

if (wallet.isHardwareWallet) {
const [{ id: stakePoolId }] = this.stores.staking.stakePools;
let dlegationData: {
delegationAction: DelegationAction;
poolId: string;
} = {
delegationAction: 'join',
poolId: stakePoolId,
};

if (wallet.isDelegating) {
const { lastDelegatedStakePoolId, delegatedStakePoolId } = wallet;
const poolId = lastDelegatedStakePoolId || delegatedStakePoolId || '';
dlegationData = {
delegationAction: 'quit',
poolId,
};
}

const initialCoinSelection = await this.stores.hardwareWallets.selectDelegationCoins(
{
walletId: wallet.id,
...dlegationData,
}
);

const coinSelection = {
...initialCoinSelection,
certificates: [
{
certificate_type: 'cast_vote',
reward_account_path: ['1852H', '1815H', '0H', '2', '0'],
vote: chosenOption,
},
],
};

console.log('!DEBUG certificates', coinSelection.certificates);

this.stores.hardwareWallets.updateTxSignRequest(coinSelection);
this.stores.hardwareWallets.initiateTransaction({
walletId: wallet.id,
});

return {
success: true,
fees: coinSelection.fee,
};
}

try {
const {
coinSelection,
Expand Down

0 comments on commit 28ef4bd

Please sign in to comment.