Skip to content

Commit

Permalink
fixup! feat(suite): add staking/unstaking instant amount forecasting
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-pvl committed Oct 21, 2024
1 parent a854667 commit 9e1a100
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getUnstakingPeriodInDays } from 'src/utils/suite/stake';
import UnstakeFees from './Fees';
import { selectValidatorsQueueData } from '@suite-common/wallet-core';
import { getAccountEverstakeStakingPool } from '@suite-common/wallet-utils';
import { ApproximateEthAmount } from 'src/views/wallet/staking/components/EthStakingDashboard/components/ApproximateEthAmount';
import { ApproximateInstantEthAmount } from 'src/views/wallet/staking/components/EthStakingDashboard/components/ApproximateInstantEthAmount';
import { BigNumber } from '@trezor/utils';

const DividerWrapper = styled.div`
Expand Down Expand Up @@ -124,7 +124,7 @@ export const UnstakeEthForm = () => {
</Tooltip>
</Row>

<ApproximateEthAmount
<ApproximateInstantEthAmount
value={approximatedInstantEthAmount}
symbol={symbol.toUpperCase()}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/suite/src/utils/suite/__fixtures__/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ export const simulateUnstakeFixture = [
from: undefined,
symbol: undefined,
},
ethereumCallResult: {},
blockchainEvmRpcCallResult: {},
result: null,
},
{
Expand All @@ -883,7 +883,7 @@ export const simulateUnstakeFixture = [
to: '0xAFA848357154a6a624686b348303EF9a13F63264',
symbol: 'eth',
},
ethereumCallResult: {
blockchainEvmRpcCallResult: {
success: true,
payload: { data: '0x000000000000000000000000000000000000000000000000016345785d8a0000' },
},
Expand Down
6 changes: 3 additions & 3 deletions packages/suite/src/utils/suite/__tests__/stake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ describe('getChangedInternalTx', () => {
});
});

type EthereumCallResult = Unsuccessful | SuccessWithDevice<{ data: string }>;
type BlockchainEvmRpcCallResult = Unsuccessful | SuccessWithDevice<{ data: string }>;
type SimulateUnstakeArgs = StakeTxBaseArgs & { amount: string };

describe('simulateUnstake', () => {
simulateUnstakeFixture.forEach(test => {
it(test.description, async () => {
jest.spyOn(TrezorConnect, 'ethereumCall').mockImplementation(() =>
Promise.resolve(test.ethereumCallResult as EthereumCallResult),
jest.spyOn(TrezorConnect, 'blockchainEvmRpcCall').mockImplementation(() =>
Promise.resolve(test.blockchainEvmRpcCallResult as BlockchainEvmRpcCallResult),
);
const result = await simulateUnstake(test.args as SimulateUnstakeArgs);
expect(result).toEqual(test.result);
Expand Down
5 changes: 2 additions & 3 deletions packages/suite/src/utils/suite/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,14 @@ export const simulateUnstake = async ({

const amountWei = toWei(amount, 'ether');
const interchanges = 0;
const coin = symbol?.toString();

const data = contractPool.methods
.unstake(amountWei, interchanges, WALLET_SDK_SOURCE)
.encodeABI();
if (!data) return null;

const ethereumData = await TrezorConnect.ethereumCall({
coin,
const ethereumData = await TrezorConnect.blockchainEvmRpcCall({
coin: symbol,
from,
to: poolAddress,
data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { FormattedCryptoAmount } from 'src/components/suite';
import { Tooltip } from '@trezor/components';
import { BigNumber } from '@trezor/utils/src/bigNumber';

interface ApproximateEthAmountProps {
interface ApproximateInstantEthAmountProps {
value: string | number;
symbol: string;
}

const DEFAULT_MAX_DECIMAL_PLACES = 2;

export const ApproximateEthAmount = ({ value, symbol }: ApproximateEthAmountProps) => {
export const ApproximateInstantEthAmount = ({
value,
symbol,
}: ApproximateInstantEthAmountProps) => {
const hasDecimals = value.toString().includes('.');

if (!hasDecimals) {
Expand Down

0 comments on commit 9e1a100

Please sign in to comment.