Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet: simulated delegation fees #1357

Merged
merged 21 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions nym-wallet/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
core: {
builder: 'webpack5',
},
typescript: { reactDocgen: false },
// webpackFinal: async (config, { configType }) => {
// // `configType` has a value of 'DEVELOPMENT' or 'PRODUCTION'
// // You can change the configuration based on that.
Expand All @@ -32,15 +33,17 @@ module.exports = {
config.resolve.extensions = ['.tsx', '.ts', '.js'];
config.resolve.plugins = [new TsconfigPathsPlugin()];

config.plugins.push(new ForkTsCheckerWebpackPlugin({
typescript: {
mode: 'write-references',
diagnosticOptions: {
semantic: true,
syntactic: true,
config.plugins.push(
new ForkTsCheckerWebpackPlugin({
typescript: {
mode: 'write-references',
diagnosticOptions: {
semantic: true,
syntactic: true,
},
},
},
}));
}),
);

if (!config.resolve.alias) {
config.resolve.alias = {};
Expand Down
4 changes: 2 additions & 2 deletions nym-wallet/.storybook/mocks/tauri/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
*/

module.exports = {
getVersion: () => undefined
}
getVersion: () => undefined,
};
2 changes: 2 additions & 0 deletions nym-wallet/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ fn main() {
simulate::mixnet::simulate_update_mixnode,
simulate::mixnet::simulate_delegate_to_mixnode,
simulate::mixnet::simulate_undelegate_from_mixnode,
simulate::vesting::simulate_vesting_delegate_to_mixnode,
simulate::vesting::simulate_vesting_undelegate_from_mixnode,
simulate::vesting::simulate_vesting_bond_gateway,
simulate::vesting::simulate_vesting_unbond_gateway,
simulate::vesting::simulate_vesting_bond_mixnode,
Expand Down
1 change: 1 addition & 0 deletions nym-wallet/src-tauri/src/operations/simulate/mixnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub async fn simulate_undelegate_from_mixnode(
identity: &str,
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<FeeDetails, BackendError> {
println!("Called");
let guard = state.read().await;
let client = guard.current_client()?;
let mixnet_contract = client.nymd.mixnet_contract_address();
Expand Down
47 changes: 47 additions & 0 deletions nym-wallet/src-tauri/src/operations/simulate/vesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,53 @@ pub async fn simulate_vesting_update_mixnode(
Ok(detailed_fee(client, result))
}

#[tauri::command]
pub async fn simulate_vesting_delegate_to_mixnode(
identity: &str,
amount: MajorCurrencyAmount,
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<FeeDetails, BackendError> {
let guard = state.read().await;
let amount = amount.into();

let client = guard.current_client()?;
let vesting_contract = client.nymd.vesting_contract_address();

let msg = client.nymd.wrap_contract_execute_message(
vesting_contract,
&ExecuteMsg::DelegateToMixnode {
mix_identity: identity.to_string(),
amount,
},
vec![],
)?;

let result = client.nymd.simulate(vec![msg]).await?;
Ok(detailed_fee(client, result))
}

#[tauri::command]
pub async fn simulate_vesting_undelegate_from_mixnode(
identity: &str,
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<FeeDetails, BackendError> {
let guard = state.read().await;

let client = guard.current_client()?;
let vesting_contract = client.nymd.vesting_contract_address();

let msg = client.nymd.wrap_contract_execute_message(
vesting_contract,
&ExecuteMsg::UndelegateFromMixnode {
mix_identity: identity.to_string(),
},
vec![],
)?;

let result = client.nymd.simulate(vec![msg]).await?;
Ok(detailed_fee(client, result))
}

#[tauri::command]
pub async fn simulate_withdraw_vested_coins(
amount: MajorCurrencyAmount,
Expand Down
28 changes: 28 additions & 0 deletions nym-wallet/src/components/ConfirmTX.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ConfirmTx } from './ConfirmTX';
import { ModalListItem } from './Modals/ModalListItem';

export default {
title: 'Wallet / Confirm Transaction',
component: ConfirmTx,
} as ComponentMeta<typeof ConfirmTx>;

const Template: ComponentStory<typeof ConfirmTx> = (args) => (
<ConfirmTx {...args}>
<ModalListItem label="Transaction type" value="Bond" divider />
<ModalListItem label="Current bond" value="100 NYM" divider />
<ModalListItem label="Additional bond" value="50 NYM" divider />
</ConfirmTx>
);

export const Default = Template.bind({});
Default.args = {
open: true,
header: 'Confirm transaction',
subheader: 'Confirm and proceed or cancel transaction',
fee: { amount: { amount: '0.001', denom: 'NYM' }, fee: { Auto: null } },
onClose: () => {},
onConfirm: async () => {},
onPrev: () => {},
};
34 changes: 34 additions & 0 deletions nym-wallet/src/components/ConfirmTX.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { FeeDetails } from '@nymproject/types';
import { Box, Button } from '@mui/material';
import { SimpleModal } from './Modals/SimpleModal';
import { ModalFee } from './Modals/ModalFee';

export const ConfirmTx: React.FC<{
open: boolean;
header: string;
subheader?: string;
fee: FeeDetails;
onConfirm: () => Promise<void>;
onClose?: () => void;
onPrev: () => void;
}> = ({ open, fee, onConfirm, onClose, header, subheader, onPrev, children }) => (
<SimpleModal
open={open}
header={header}
subHeader={subheader}
okLabel="Confirm"
onOk={onConfirm}
onClose={onClose}
SecondaryAction={
<Button fullWidth sx={{ mt: 1 }} size="large" onClick={onPrev}>
Cancel
</Button>
}
>
<Box sx={{ mt: 3 }}>
{children}
<ModalFee fee={fee} isLoading={false} />
</Box>
</SimpleModal>
);
2 changes: 1 addition & 1 deletion nym-wallet/src/components/Delegation/DelegateBlocker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const OverSaturatedBlockerModal: React.FC<{
hideCloseIcon
displayErrorIcon
onClose={onClose}
onOk={onClose}
onOk={async () => onClose?.()}
header={header || 'Delegate'}
subHeader={subHeader || "This node is over saturated, you can't delegate more stake to it"}
okLabel={buttonText || 'Close'}
Expand Down
Loading