From c9b9a75c1404251de9c68eef84e2b1caf8897207 Mon Sep 17 00:00:00 2001
From: konoart <91595347+konoart@users.noreply.github.com>
Date: Mon, 9 May 2022 16:59:04 +0200
Subject: [PATCH] Solana: fixes after initial staking (#4964)
* solana invert validator commision and total stake
* solana conditionaly hide ledger by figment TC when staking
* solana add use all amount stake warning
* solana refactor delegation CTA
* solana disable hover on non choosable validators
* solana fix renamed useValidators in LLC
* solana fix lint issues
---
.../families/solana/Delegation/index.js | 132 ++++++++++--------
.../steps/StepValidator.js | 2 +-
.../steps/StepValidator.js | 5 +-
.../steps/StepValidator.js | 2 +-
.../steps/StepValidator.js | 5 +-
.../components/LedgerByFigmentTCLink.js | 24 +++-
.../solana/shared/components/ValidatorRow.js | 43 +++---
.../solana/shared/fields/ValidatorsField.js | 7 +-
static/i18n/en/app.json | 5 +-
9 files changed, 136 insertions(+), 89 deletions(-)
diff --git a/src/renderer/families/solana/Delegation/index.js b/src/renderer/families/solana/Delegation/index.js
index 7f59653a6d..a12a34b06c 100644
--- a/src/renderer/families/solana/Delegation/index.js
+++ b/src/renderer/families/solana/Delegation/index.js
@@ -43,7 +43,7 @@ const Delegation = ({ account }: Props) => {
const onEarnRewards = useCallback(() => {
dispatch(
- openModal("MODAL_SOLANA_DELEGATE", {
+ openModal("MODAL_SOLANA_REWARDS_INFO", {
account,
}),
);
@@ -90,69 +90,83 @@ const Delegation = ({ account }: Props) => {
return (
<>
-
- }>
-
-
- {hasStakes ? (
- <>
-
- {stakesWithMeta.map(stakeWithMeta => (
-
- ))}
- >
- ) : (
-
-
-
-
-
-
- }
- onClick={() => openURL(urls.solana.staking)}
- />
-
-
-
-
- )}
-
+
+
+
+
+
+ {stakesWithMeta.map(stakeWithMeta => (
+
+ ))}
+
+ ) : null}
+
+ {!hasStakes && account.spendableBalance.gt(0) ? (
+
+
+
+ ) : null}
>
);
};
+type EarnRewardsCTAProps = {
+ account: Account,
+ onEarnRewards: () => void,
+};
+
+function EarnRewardsCTA({ account, onEarnRewards }: EarnRewardsCTAProps) {
+ return (
+
+
+
+
+
+
+ }
+ onClick={() => openURL(urls.solana.staking)}
+ />
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+}
+
const Delegations = ({ account }: Props) => {
if (!account.solanaResources) return null;
diff --git a/src/renderer/families/solana/DelegationActivateFlowModal/steps/StepValidator.js b/src/renderer/families/solana/DelegationActivateFlowModal/steps/StepValidator.js
index f6f90f8bee..7efb5565be 100644
--- a/src/renderer/families/solana/DelegationActivateFlowModal/steps/StepValidator.js
+++ b/src/renderer/families/solana/DelegationActivateFlowModal/steps/StepValidator.js
@@ -79,7 +79,7 @@ export function StepValidatorFooter({
return (
<>
-
+
diff --git a/src/renderer/families/solana/DelegationDeactivateFlowModal/steps/StepValidator.js b/src/renderer/families/solana/DelegationDeactivateFlowModal/steps/StepValidator.js
index b8167f4fe4..50f184c655 100644
--- a/src/renderer/families/solana/DelegationDeactivateFlowModal/steps/StepValidator.js
+++ b/src/renderer/families/solana/DelegationDeactivateFlowModal/steps/StepValidator.js
@@ -1,7 +1,7 @@
// @flow
import { getAccountUnit } from "@ledgerhq/live-common/lib/account";
import {
- useLedgerFirstShuffledValidators,
+ useValidators,
useSolanaStakesWithMeta,
} from "@ledgerhq/live-common/lib/families/solana/react";
import invariant from "invariant";
@@ -49,7 +49,7 @@ export default function StepValidator({
const unit = getAccountUnit(account);
- const validators = useLedgerFirstShuffledValidators(account.currency);
+ const validators = useValidators(account.currency);
const validator = validators.find(v => v.voteAccount === stake.delegation?.voteAccAddr);
if (validator === undefined) {
@@ -61,6 +61,7 @@ export default function StepValidator({
{error && }
-
+
diff --git a/src/renderer/families/solana/DelegationReactivateFlowModal/steps/StepValidator.js b/src/renderer/families/solana/DelegationReactivateFlowModal/steps/StepValidator.js
index 4164810637..1e09b7a278 100644
--- a/src/renderer/families/solana/DelegationReactivateFlowModal/steps/StepValidator.js
+++ b/src/renderer/families/solana/DelegationReactivateFlowModal/steps/StepValidator.js
@@ -2,7 +2,7 @@
import { getAccountUnit } from "@ledgerhq/live-common/lib/account";
import {
useSolanaStakesWithMeta,
- useLedgerFirstShuffledValidators,
+ useValidators,
} from "@ledgerhq/live-common/lib/families/solana/react";
import invariant from "invariant";
import React from "react";
@@ -49,7 +49,7 @@ export default function StepValidator({
const unit = getAccountUnit(account);
- const validators = useLedgerFirstShuffledValidators(account.currency);
+ const validators = useValidators(account.currency);
const validator = validators.find(v => v.voteAccount === stake.delegation?.voteAccAddr);
if (validator === undefined) {
@@ -61,6 +61,7 @@ export default function StepValidator({
{error && }
openURL(urls.solana.ledgerByFigmentTC);
return (
@@ -16,3 +26,15 @@ export default function LedgerByFigmentTC() {
/>
);
}
+
+const shouldShowTC = ({ model }: Transaction) => {
+ switch (model.kind) {
+ case "stake.createAccount":
+ return model.uiState.delegate.voteAccAddress === LEDGER_VALIDATOR_ADDRESS;
+ case "stake.delegate":
+ return model.uiState.voteAccAddr === LEDGER_VALIDATOR_ADDRESS;
+ default:
+ break;
+ }
+ return false;
+};
diff --git a/src/renderer/families/solana/shared/components/ValidatorRow.js b/src/renderer/families/solana/shared/components/ValidatorRow.js
index 5034da36fa..c485e2707a 100644
--- a/src/renderer/families/solana/shared/components/ValidatorRow.js
+++ b/src/renderer/families/solana/shared/components/ValidatorRow.js
@@ -21,12 +21,12 @@ type Props = {
currency: CryptoCurrency,
validator: ValidatorAppValidator,
active?: boolean,
- showStake?: boolean,
onClick?: (v: ValidatorAppValidator) => void,
+ disableHover?: boolean,
unit: Unit,
};
-function SolanaValidatorRow({ validator, active, showStake, onClick, unit, currency }: Props) {
+function SolanaValidatorRow({ validator, active, onClick, unit, currency, disableHover }: Props) {
const explorerView = getDefaultExplorerView(currency);
const onExternalLink = useCallback(() => {
@@ -39,6 +39,7 @@ function SolanaValidatorRow({ validator, active, showStake, onClick, unit, curre
return (
-
-
- {formatCurrencyUnit(unit, new BigNumber(validator.activeStake), {
- showCode: true,
- })}
-
- >
- ) : null
+ <>
+
+ {`${validator.commission} %`}
+ >
}
sideInfo={
-
- {`${validator.commission} %`}
-
-
-
+
+ {formatCurrencyUnit(unit, new BigNumber(validator.activeStake), {
+ showCode: true,
+ })}
+
+
+
@@ -84,9 +81,12 @@ function SolanaValidatorRow({ validator, active, showStake, onClick, unit, curre
);
}
-const StyledValidatorRow: ThemedComponent = styled(ValidatorRow)`
+const StyledValidatorRow: ThemedComponent = styled(
+ ValidatorRow,
+)`
border-color: transparent;
margin-bottom: 0;
+ ${p => (p.disableHover ? "&:hover { border-color: transparent; }" : "")}
`;
const ChosenMark: ThemedComponent<{ active: boolean }> = styled(Check).attrs(p => ({
@@ -94,4 +94,11 @@ const ChosenMark: ThemedComponent<{ active: boolean }> = styled(Check).attrs(p =
size: 14,
}))``;
+const TotalStakeTitle = styled(Text)`
+ font-size: 11px;
+ font-weight: 500;
+ text-align: right;
+ color: ${p => p.theme.colors.palette.text.shade60};
+`;
+
export default SolanaValidatorRow;
diff --git a/src/renderer/families/solana/shared/fields/ValidatorsField.js b/src/renderer/families/solana/shared/fields/ValidatorsField.js
index 74af514041..4579198369 100644
--- a/src/renderer/families/solana/shared/fields/ValidatorsField.js
+++ b/src/renderer/families/solana/shared/fields/ValidatorsField.js
@@ -1,6 +1,6 @@
// @flow
import { getAccountUnit } from "@ledgerhq/live-common/lib/account";
-import { useLedgerFirstShuffledValidators } from "@ledgerhq/live-common/lib/families/solana/react";
+import { useValidators } from "@ledgerhq/live-common/lib/families/solana/react";
import type { ValidatorAppValidator } from "@ledgerhq/live-common/lib/families/solana/validator-app";
import type { Account, TransactionStatus } from "@ledgerhq/live-common/lib/types";
import invariant from "invariant";
@@ -32,7 +32,7 @@ const ValidatorField = ({ t, account, onChangeValidator, chosenVoteAccAddr, stat
const unit = getAccountUnit(account);
- const validators = useLedgerFirstShuffledValidators(account.currency);
+ const validators = useValidators(account.currency);
const chosenValidator = useMemo(() => {
if (chosenVoteAccAddr !== null) {
@@ -64,7 +64,6 @@ const ValidatorField = ({ t, account, onChangeValidator, chosenVoteAccAddr, stat