Skip to content

Commit

Permalink
Feat: Stake more proxy (#1646)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuul-wq authored Apr 9, 2024
1 parent 0c7a23d commit 799d3dd
Show file tree
Hide file tree
Showing 16 changed files with 2,000 additions and 20 deletions.
20 changes: 16 additions & 4 deletions src/renderer/entities/transaction/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Transaction, TransactionType } from '../model/transaction';
import { TransferType } from './common/constants';
import { toAddress, TEST_ACCOUNTS, formatAmount, getAssetId, TEST_ADDRESS } from '@shared/lib/utils';
import { toAddress, TEST_ACCOUNTS, formatAmount, getAssetId } from '@shared/lib/utils';
import { Chain, ChainId, Asset, AccountId, Address } from '@shared/core';

export const transactionBuilder = {
buildTransfer,
buildBondNominate,
buildBondExtra,
buildNominate,
buildRedeem,
buildUnstake,
Expand Down Expand Up @@ -78,16 +79,27 @@ type BondParams = {
amount: string;
};
function buildBond({ chain, asset, accountId, destination, amount }: BondParams): Transaction {
const controller = destination ? toAddress(destination, { prefix: chain.addressPrefix }) : '';
const controller = toAddress(accountId, { prefix: chain.addressPrefix });

return {
chainId: chain.chainId,
address: toAddress(accountId, { prefix: chain.addressPrefix }),
address: controller,
type: TransactionType.BOND,
args: {
value: formatAmount(amount, asset.precision),
controller,
payee: { Account: TEST_ADDRESS },
payee: destination ? { Account: destination } : 'Staked',
},
};
}

function buildBondExtra({ chain, asset, accountId, amount }: Omit<BondParams, 'destination'>): Transaction {
return {
chainId: chain.chainId,
address: toAddress(accountId, { prefix: chain.addressPrefix }),
type: TransactionType.STAKE_MORE,
args: {
maxAdditional: formatAmount(amount, asset.precision),
},
};
}
Expand Down
12 changes: 8 additions & 4 deletions src/renderer/pages/Staking/Overview/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import { useToggle } from '@shared/lib/hooks';
import { AboutStaking, NetworkInfo, NominatorsList, Actions, InactiveChain } from './components';
import { accountUtils, permissionUtils, walletModel, walletUtils } from '@entities/wallet';
import { priceProviderModel } from '@entities/price';
import { NominatorInfo } from './common/types';
import { useNetworkData, networkUtils } from '@entities/network';
import { eraService } from '@entities/staking/api';
import { ChainId, Chain, Address, Account, Stake, Validator, ShardAccount, ChainAccount } from '@shared/core';
import { BondNominate, bondModel } from '@widgets/Staking/BondNominate';
import { BondNominate, bondNominateModel } from '@widgets/Staking/BondNominate';
import { BondExtra, bondExtraModel } from '@widgets/Staking/BondExtra';
import { Unstake, unstakeModel } from '@widgets/Staking/Unstake';
import { Withdraw, withdrawModel } from '@widgets/Withdraw';
import { NominatorInfo } from './common/types';
import {
useStakingData,
StakingMap,
Expand Down Expand Up @@ -227,15 +228,16 @@ export const Overview = () => {
return;
}

if (path === Paths.BOND || path === Paths.UNSTAKE || path === Paths.REDEEM) {
if (path === Paths.BOND || path === Paths.STAKE_MORE || path === Paths.UNSTAKE || path === Paths.REDEEM) {
const shards = accounts.filter((account) => {
const address = toAddress(account.accountId, { prefix: addressPrefix });

return selectedNominators.includes(address);
});

const model = {
[Paths.BOND]: bondModel.events.flowStarted,
[Paths.BOND]: bondNominateModel.events.flowStarted,
[Paths.STAKE_MORE]: bondExtraModel.events.flowStarted,
[Paths.UNSTAKE]: unstakeModel.events.flowStarted,
[Paths.REDEEM]: withdrawModel.events.flowStarted,
};
Expand Down Expand Up @@ -333,8 +335,10 @@ export const Overview = () => {
/>

<BondNominate />
<BondExtra />
<Unstake />
<Withdraw />

<Outlet />
</>
);
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Operations } from './Operations/Operations';
import { Notifications } from './Notifications/Notifications';
import { Contacts, CreateContact, EditContact } from './AddressBook';
import { Overview as Settings, Matrix, Currency, Networks } from './Settings';
import { Overview as Staking, ChangeValidators, Restake, Destination, StakeMore } from './Staking';
import { Overview as Staking, ChangeValidators, Restake, Destination } from './Staking';

// React routes v6 hint:
// https://github.com/remix-run/react-router/blob/main/docs/upgrading/v5.md#use-useroutes-instead-of-react-router-config
Expand Down Expand Up @@ -51,7 +51,6 @@ export const ROUTES_CONFIG: RouteObject[] = [
element: <Staking />,
children: [
{ path: Paths.RESTAKE, element: <Restake /> },
{ path: Paths.STAKE_MORE, element: <StakeMore /> },
{ path: Paths.DESTINATION, element: <Destination /> },
{ path: Paths.VALIDATORS, element: <ChangeValidators /> },
],
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/widgets/Staking/BondExtra/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { BondExtra } from './ui/BondExtra';
export { bondExtraModel } from './model/bond-extra-model';
65 changes: 65 additions & 0 deletions src/renderer/widgets/Staking/BondExtra/lib/bond-extra-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Step } from './types';
import { walletUtils, accountUtils } from '@entities/wallet';
import { dictionary } from '@shared/lib/utils';
import { transactionService } from '@entities/transaction';
import { Wallet, Account, Chain } from '@shared/core';

export const bondExtraUtils = {
isNoneStep,
isInitStep,
isConfirmStep,
isSignStep,
isSubmitStep,

getTxWrappers,
};

function isNoneStep(step: Step): boolean {
return step === Step.NONE;
}

function isInitStep(step: Step): boolean {
return step === Step.INIT;
}

function isConfirmStep(step: Step): boolean {
return step === Step.CONFIRM;
}

function isSignStep(step: Step): boolean {
return step === Step.SIGN;
}

function isSubmitStep(step: Step): boolean {
return step === Step.SUBMIT;
}

type TxWrapperParams = {
chain: Chain;
wallet: Wallet;
wallets: Wallet[];
account: Account;
accounts: Account[];
signatories: Account[];
};
function getTxWrappers({ chain, wallet, wallets, account, accounts, signatories }: TxWrapperParams) {
const walletFiltered = wallets.filter((wallet) => {
return !walletUtils.isProxied(wallet) && !walletUtils.isWatchOnly(wallet);
});
const walletsMap = dictionary(walletFiltered, 'id');
const chainFilteredAccounts = accounts.filter((account) => {
if (accountUtils.isBaseAccount(account) && walletUtils.isPolkadotVault(walletsMap[account.walletId])) {
return false;
}

return accountUtils.isChainAndCryptoMatch(account, chain);
});

return transactionService.getTxWrappers({
wallet,
wallets: walletFiltered,
account,
accounts: chainFilteredAccounts,
signatories,
});
}
28 changes: 28 additions & 0 deletions src/renderer/widgets/Staking/BondExtra/lib/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Account, Chain, Wallet } from '@shared/core';

export const enum Step {
NONE,
INIT,
CONFIRM,
SIGN,
SUBMIT,
}

export type WalletData = {
wallet: Wallet;
shards: Account[];
chain: Chain;
};

export type BondData = {
shards: Account[];
signatory?: Account;
amount: string;
description: string;
};

export type FeeData = {
fee: string;
totalFee: string;
multisigDeposit: string;
};
Loading

0 comments on commit 799d3dd

Please sign in to comment.