Skip to content

Commit

Permalink
feat: solo completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Jan 9, 2025
1 parent 41373da commit 2bfd1b8
Show file tree
Hide file tree
Showing 72 changed files with 2,172 additions and 613 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
"@polkadot/ui-keyring": "^3.6.6",
"@polkadot/util": "^12.6.2",
"chromedriver": "latest",
"clipboard-copy": "^4.0.1",
"lodash": "^4.17.21",
"qrcode": "^1.5.4",
"webdriverio": "latest"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/polkagate/snap.git"
},
"source": {
"shasum": "DZM9Vo1FpTdH2ZubZW8SodQNcf5eM+p7ewHJFkZz2qk=",
"shasum": "KKQiIVyrpROyjcm6MylZG0upji8GjcVzjSuxnnLNsdE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
9 changes: 4 additions & 5 deletions packages/snap/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Chain } from '@polkadot/extension-chains/types';
import { sanitizeChainName } from './util/getChainName';
import { HexString } from '@polkadot/util/types';
import { KUSAMA_PEOPLE_GENESIS_HASH, PASEO_PEOPLE_GENESIS_HASH, POLKADOT_PEOPLE_GENESIS_HASH, WESTEND_PEOPLE_GENESIS_HASH } from './constants';
import { POLKADOT_GENESIS_HASH } from './ui/stake/const';

const testnets: Network[] = [
{
Expand Down Expand Up @@ -37,7 +36,7 @@ const testnets: Network[] = [
isIgnored: false,
isTestnet: true,
network: "paseo",
prefix: 42,
prefix: 0,
slip44: 0,
standardAccount: "*25519",
symbols: ["PAS"],
Expand Down Expand Up @@ -108,7 +107,7 @@ const assetHubs: Network[] = [
isIgnored: false,
isTestnet: false,
network: "paseo-asset-hub",
prefix: 42, // Adjust if necessary
prefix: 0,
slip44: 0, // Update as required
standardAccount: "*25519",
symbols: ["PAS"],
Expand Down Expand Up @@ -171,8 +170,8 @@ const peopleChains = [
"isIgnored": false,
"isTestnet": true,
"network": "paseoPeople",
"prefix": 42,
"slip44": 354,
"prefix": 0,
"slip44": 0,
"symbols": ["PAS"],
"standardAccount": "*25519",
"website": "https://polkadot.network"
Expand Down
1 change: 0 additions & 1 deletion packages/snap/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const PEOPLE_CHAINS = {
[KUSAMA_GENESIS]: KUSAMA_PEOPLE_GENESIS_HASH,
[WESTEND_GENESIS]: WESTEND_PEOPLE_GENESIS_HASH,
[PASEO_GENESIS]: PASEO_PEOPLE_GENESIS_HASH,

}

export enum OUTPUT_TYPE {
Expand Down
101 changes: 83 additions & 18 deletions packages/snap/src/listeners/onUserInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { showMore } from '../ui/more';
import { receive } from '../ui/receive';
import { balanceDetails } from '../ui/home/balanceDetails';
import { send } from '../ui/send';
import { SendFormState } from '../ui/send/types';
import { PayoutSelectionFormState, SendFormState } from '../ui/send/types';
import { formValidation } from '../ui/send/utils';
import { approveSend } from '../ui/send/approveSend';
import { HexString } from '@polkadot/util/types';
Expand All @@ -30,7 +30,7 @@ import { stakeFirstTimeReview } from '../ui/stake/stakeFirstTimeReview';
import { stakeType } from '../ui/stake/stakeType';
import { selectValidators } from '../ui/stake/selectValidators';
import { confirmStake } from '../ui/stake/confirmStake';
import { stakePoolReview } from '../ui/stake/pool/stakePoolReview';
import { stakePoolReview } from '../ui/stake/pool';
import { claim } from '../ui/stake/pool/claim/claim';
import { confirmClaim } from '../ui/stake/pool/claim/confirmClaim';
import { poolStakeMore } from '../ui/stake/pool/stakeMore/poolStakeMore';
Expand All @@ -48,9 +48,9 @@ import { poolRedeemConfirm } from '../ui/stake/pool/redeem/poolRedeemConfirm';
import { exportAccount } from '../ui/more/exportAccount';
import { showJsonContent } from '../ui/more/showJsonContent';
import { stakeSoloReview } from '../ui/stake/solo';
import { soloRedeem } from '../ui/stake/solo/redeem/soloRedeem';
import { soloRedeem } from '../ui/stake/solo/redeem';
import { soloRedeemConfirm } from '../ui/stake/solo/redeem/soloRedeemConfirm';
import { soloStakeMore } from '../ui/stake/solo/stakeMore/soloStakeMore';
import { soloStakeMore } from '../ui/stake/solo/stakeMore';
import { soloStakeMoreReview } from '../ui/stake/solo/stakeMore/soloStakeMoreReview';
import { soloStakeMoreConfirm } from '../ui/stake/solo/stakeMore/soloStakeMoreConfirm';
import { StakeMoreSoloFormState, stakeMoreSoloFormValidation } from '../ui/stake/solo/stakeMore/util/stakeMoreSoloFormValidation';
Expand All @@ -62,6 +62,13 @@ import { rewardsDestination } from '../ui/stake/solo/rewards';
import { rewardsDestinationReview } from '../ui/stake/solo/rewards/rewardsDestinationReview';
import { rewardsDestinationConfirm } from '../ui/stake/solo/rewards/rewardsDestinationConfirm';
import { SoloUnstakeFormState } from '../ui/stake/solo/unstake/types';
import { yourValidators } from '../ui/stake/solo/validators';
import { changeValidators } from '../ui/stake/solo/validators/changeValidators';
import { reviewChangeValidators } from '../ui/stake/solo/validators/reviewChangeValidators';
import { confirmChangeValidators } from '../ui/stake/solo/validators/confirmChangeValidators';
import { pendingRewards } from '../ui/stake/solo/pending_rewards';
import { reviewPayout } from '../ui/stake/solo/pending_rewards/reviewpayout';
import { confirmPayout } from '../ui/stake/solo/pending_rewards/confirmPayout';


export const onUserInput: OnUserInputHandler = async ({ id, event, context }) => {
Expand Down Expand Up @@ -212,20 +219,6 @@ export const onUserInput: OnUserInputHandler = async ({ id, event, context }) =>
await stakeType(id, context, stakeTypeForm);
break;

case 'selectValidators':
await showSpinner(id, 'Loading, please wait ...');
case 'selectedValidator':
const validatorSelectionForm = state.validatorSelectionForm as StakeTypeFormState;
await selectValidators(id, context, validatorSelectionForm);
break;

case 'selectValidatorsShow':
{
const validatorSelectionForm = state.validatorSelectionForm as StakeTypeFormState;
await selectValidators(id, context, validatorSelectionForm, true);
break;
}

case 'stakeFirstTimeReview':
await showSpinner(id, 'Loading, please wait ...');
await stakeFirstTimeReview(id, context);
Expand Down Expand Up @@ -401,6 +394,78 @@ export const onUserInput: OnUserInputHandler = async ({ id, event, context }) =>
await rewardsDestinationConfirm(id, context);
break;

/** ---------------------------- Validators--------------------------------- */
case 'changeValidatorsByMySelf':
case 'selectValidators':
await showSpinner(id, 'Loading, please wait ...');
case 'selectedValidator':
const selectedValidators = eventName === 'changeValidatorsByMySelf'
? context.nominators
: state.validatorSelectionForm && Object.entries(state.validatorSelectionForm).filter(([, value]) => value).map(([key]) => key.split(',')[1])
await selectValidators(id, context, selectedValidators);
break;

case 'selectValidatorsShow':
await selectValidators(id, context, context.selectedValidators, true);
break;

case 'changeValidatorsByRecommended':
await showSpinner(id, 'Loading, please wait ...');
await selectValidators(id, context, context.recommendedValidatorsOnThisChain, true);
break;

case 'yourValidators':
await showSpinner(id, 'Loading, please wait ...');
await yourValidators(id, context);
break;

case 'changeValidators':
await showSpinner(id, 'Loading, please wait ...');
await changeValidators(id, context);
break;

case 'changeValidatorsReview':
await showSpinner(id, 'Loading, please wait ...');
await reviewChangeValidators(id, context);
break;

case 'changeValidatorsConfirm':
await showSpinner(id, 'Loading, please wait ...');
await confirmChangeValidators(id, context);
break;

/** ---------------------------- Rewards Solo--------------------------------- */

case 'pendingRewards':
await showSpinner(id, 'Loading, please wait ...');
case 'selectAllToPayOut':
case 'selectedPendingReward':

let selectedPayouts = [] as string[];
if (['selectAllToPayOut', 'selectedPendingReward'].includes(eventName)) {
const payoutSelectionForm = state.payoutSelectionForm as PayoutSelectionFormState;

selectedPayouts =
eventName === 'selectAllToPayOut'
? (state.selectAllToPayOutForm as PayoutSelectionFormState).selectAllToPayOut
? Object.entries(payoutSelectionForm).map(([key]) => key.substring(key.indexOf(',') + 1)) // select all
: [] // deselect all
: Object.entries(payoutSelectionForm).filter(([, value]) => value).map(([key]) => key.substring(key.indexOf(',') + 1))
}

await pendingRewards(id, context, selectedPayouts);
break;

case 'payoutReview':
await showSpinner(id, 'Loading, please wait ...');
await reviewPayout(id, context);
break;

case 'payoutConfirm':
await showSpinner(id, 'Working, please wait ...');
await confirmPayout(id, context);
break;

//===================================OTHERS===================================//
case 'vote':
await voting(id);
Expand Down
22 changes: 15 additions & 7 deletions packages/snap/src/ui/components/ActionRow.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Box, Button, Icon, SnapComponent, IconName } from "@metamask/snaps-sdk/jsx";
import { Box, Button, Icon, Text, SnapComponent, IconName } from "@metamask/snaps-sdk/jsx";

interface Props {
disabled?: boolean;
icon: `${IconName}`;
label: string;
name: string;
icon: `${IconName}`;
disabled?: boolean;
tag?: number;
}

export const ActionRow: SnapComponent<Props> = ({ label, name, icon, disabled }) => (
export const ActionRow: SnapComponent<Props> = ({ label, name, icon, disabled, tag }) => (
<Box direction="horizontal" alignment="space-between" center>
<Box direction="horizontal" alignment="start" center>
<Button name={name} variant='primary' type='button' disabled={disabled}>
Expand All @@ -17,8 +18,15 @@ export const ActionRow: SnapComponent<Props> = ({ label, name, icon, disabled })
{label}
</Button>
</Box>
<Button name={name} variant='primary' type='button' disabled={disabled}>
<Icon name='arrow-right' color='muted' size='md' />
</Button>
<Box direction="horizontal" alignment="end" center>
{!!tag &&
<Text color="muted">
{String(tag)}
</Text>
}
<Button name={name} variant='primary' type='button' disabled={disabled}>
<Icon name='arrow-right' color='muted' size='md' />
</Button>
</Box>
</Box>
)
16 changes: 9 additions & 7 deletions packages/snap/src/ui/home/partials/TotalBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Props {
export const TotalBalance: SnapComponent<Props> = ({ availableBalance, hideBalance, totalBalance, totalBalanceChanges }) => {

const signOfChanges = totalBalanceChanges > 0 ? '+' : totalBalanceChanges < 0 ? '-' : '';
const colorOfChanges = totalBalanceChanges > 0 ? 'success' : totalBalanceChanges < 0 ? 'error' : 'default';
const colorOfChanges = totalBalanceChanges > 0 ? 'success' : totalBalanceChanges < 0 ? 'error' : 'muted';
const locked = totalBalance - availableBalance;

const decimalToFixForTotal = totalBalance < 100000 ? 2 : 0;
Expand Down Expand Up @@ -53,12 +53,14 @@ export const TotalBalance: SnapComponent<Props> = ({ availableBalance, hideBalan
}
</Button>
</Box>
<Text alignment='start' color={colorOfChanges}>
{hideBalance
? '••••••••'
: `${signOfChanges}$${Math.abs(totalBalanceChanges).toFixed(decimalToFixForBalanceChange)} • 24h`
}
</Text>
{!!totalBalanceChanges &&
<Text alignment='start' color={colorOfChanges}>
{hideBalance
? '••••••••'
: `${signOfChanges}$${Math.abs(totalBalanceChanges).toFixed(decimalToFixForBalanceChange)} • 24h`
}
</Text>
}
</Box>
</Box>
)
Expand Down
33 changes: 33 additions & 0 deletions packages/snap/src/ui/image/icons/calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/snap/src/ui/image/icons/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion packages/snap/src/ui/image/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ export { default as working } from './working.svg'
export { default as ringingBell } from './ringingBell.svg'
export { default as info } from './info.svg'
export { default as account } from './account.svg'
export { default as inActiveIcon } from './inActiveIcon.svg'
export { default as inActiveIcon } from './inActiveIcon.svg'
export { default as copy } from './copy.svg'
export { default as recommended } from './recommended.svg'
export { default as calendar } from './calendar.svg'
15 changes: 15 additions & 0 deletions packages/snap/src/ui/image/icons/recommended.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion packages/snap/src/ui/send/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type SendFormState = {
tokenSelector: string;
};

export type PayoutSelectionFormState = {
[selectAllToPayOut: string]: boolean;
}
export type SelectAllToPayOutFormState = Record<string, boolean>;

/**
* The form errors.
*
Expand All @@ -30,6 +35,6 @@ export type SendFormErrors = {
* @property decimal - The decimal of selected token
*/
export type SendFlowContext = {
decimal:number;
decimal: number;
transferable: string
};
Loading

0 comments on commit 2bfd1b8

Please sign in to comment.