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

web-wallet: Update default gas settings values #3202

Merged
merged 1 commit into from
Dec 17, 2024
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
6 changes: 6 additions & 0 deletions web-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add notice for stake maturity [#2981]
- Add capability to maintain cache consistency in case of rejected blocks [#3156]
- Add button to reset gas settings to their defaults [#3178]

### Changed

- Update Transactions list design [#1922]
- Reword "Staking" header to "Stake" [#3113]
- Upgrade Migration Feature to Use Reown AppKit [#3129]
- Update default gas settings values [#3178]

### Removed

- Remove "Network" section from Settings [#3160]

### Fixed

- Fix dark mode button not being in sync with the stored value [#3178]
- Fix `BigIntInput` properties not being reactive [#3178]

## [0.9.0] - 2024-12-03

### Added
Expand Down Expand Up @@ -434,6 +439,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#3129]: https://github.com/dusk-network/rusk/issues/3129
[#3156]: https://github.com/dusk-network/rusk/issues/3156
[#3160]: https://github.com/dusk-network/rusk/issues/3160
[#3178]: https://github.com/dusk-network/rusk/issues/3178

<!-- VERSIONS -->

Expand Down
2 changes: 1 addition & 1 deletion web-wallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ VITE_FEATURE_MOONLIGHT_TRANSACTIONS=true
VITE_FEATURE_STAKE=true
VITE_FEATURE_TRANSFER=true
VITE_FEATURE_TRANSACTION_HISTORY=true
VITE_GAS_LIMIT_DEFAULT=2900000000
VITE_GAS_LIMIT_DEFAULT=100000000
VITE_GAS_LIMIT_LOWER=10000000
VITE_GAS_LIMIT_UPPER=1000000000
VITE_GAS_PRICE_DEFAULT=1
Expand Down
20 changes: 12 additions & 8 deletions web-wallet/src/lib/components/BigIntInput/BigIntInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
/** @type {bigint} */
export let value = 0n;

let isInvalidInput = false;
let internalValue = value.toString();

/** @type {(v: bigint, min: bigint, max: bigint) => boolean} */
const isInvalidInput = (v, min, max) => !!(min > v || v > max);

const checkValidity = () => {
isInvalidInput = !!(minValue > value || value > maxValue);
if (isInvalidInput) {
if (isInvalidInput(value, minValue, maxValue)) {
dispatch("error", "Value exceeds limits");
}
};
Expand All @@ -40,14 +41,17 @@
}
}

$: inputClass = makeClassName({
"invalid-input": isInvalidInput,
[`${className}`]: true,
});

onMount(() => {
checkValidity();
});

$: inputClass = makeClassName({
"invalid-input": isInvalidInput(value, minValue, maxValue),
[`${className}`]: true,
});
$: {
internalValue = value.toString();
}
ascartabelli marked this conversation as resolved.
Show resolved Hide resolved
</script>

<Textbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports[`GasFee > renders the GasFee component 1`] = `
<span
class="svelte-1c6b481"
>
0.020000000
0.100000000
</span>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports[`GasSettings > renders the GasSettings component closed 1`] = `
<span
class="svelte-1c6b481"
>
0.020000000
0.100000000
</span>
</div>

Expand Down Expand Up @@ -93,7 +93,7 @@ exports[`GasSettings > renders the GasSettings component opened 1`] = `
<span
class="svelte-1c6b481"
>
0.020000000
0.100000000
</span>
</div>

Expand Down
39 changes: 39 additions & 0 deletions web-wallet/src/lib/stores/__tests__/settingsStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,45 @@ describe("Settings store", () => {

expect(get(settingsStore)).toBe(settingsStoreContent);
});

it("should expose a method to reset the gas settings to their defaults", () => {
const newStateWithoutGas = {
currency: "FAKE CURRENCY",
darkMode: !settingsStoreContent.darkMode,
dashboardTransactionLimit:
settingsStoreContent.dashboardTransactionLimit + 1,
hideStakingNotice: !settingsStoreContent.hideStakingNotice,
language: "FAKE LANGUAGE",
userId: "FAKE USER ID",
};
const newState = {
...newStateWithoutGas,
gasLimit: settingsStoreContent.gasLimit * 2n,
gasPrice: settingsStoreContent.gasPrice * 15n,
};
const expectedState = {
...settingsStoreContent,
...newStateWithoutGas,
};

settingsStore.set(newState);

expect(get(settingsStore)).toBe(newState);

settingsStore.resetGasSettings();

expect(get(settingsStore)).toStrictEqual(expectedState);
expect(
JSON.parse(
// @ts-ignore
localStorage.getItem(`${CONFIG.LOCAL_STORAGE_APP_KEY}-preferences`)
)
).toStrictEqual({
...expectedState,
gasLimit: `${expectedState.gasLimit}n`,
gasPrice: `${expectedState.gasPrice}n`,
});
});
});

describe("In a non browser environment", () => {
Expand Down
4 changes: 2 additions & 2 deletions web-wallet/src/lib/stores/gasStore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { readable } from "svelte/store";

const gasLimits = {
gasLimitLower: BigInt(import.meta.env.VITE_GAS_LIMIT_LOWER ?? 10000000),
gasLimitUpper: BigInt(import.meta.env.VITE_GAS_LIMIT_UPPER ?? 1000000000),
gasLimitLower: BigInt(import.meta.env.VITE_GAS_LIMIT_LOWER ?? 10_000_000),
gasLimitUpper: BigInt(import.meta.env.VITE_GAS_LIMIT_UPPER ?? 1_000_000_000),
gasPriceLower: BigInt(import.meta.env.VITE_GAS_PRICE_LOWER ?? 1),
};

Expand Down
11 changes: 10 additions & 1 deletion web-wallet/src/lib/stores/settingsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const initialState = {
...browserDefaults,
currency: "USD",
dashboardTransactionLimit: 5,
gasLimit: BigInt(import.meta.env.VITE_GAS_LIMIT_DEFAULT ?? 20000000),
gasLimit: BigInt(import.meta.env.VITE_GAS_LIMIT_DEFAULT ?? 100_000_000),
gasPrice: BigInt(import.meta.env.VITE_GAS_PRICE_DEFAULT ?? 1),
hideStakingNotice: false,
userId: "",
Expand Down Expand Up @@ -71,9 +71,18 @@ const { set, subscribe, update } = settingsStore;
// Reset store to initial state
const reset = () => set(initialState);

// Resets only gas settings to their defaults.
const resetGasSettings = () =>
update((current) => ({
...current,
gasLimit: initialState.gasLimit,
gasPrice: initialState.gasPrice,
}));

/** @type {SettingsStore} */
export default {
reset,
resetGasSettings,
set,
subscribe,
update,
Expand Down
5 changes: 4 additions & 1 deletion web-wallet/src/lib/stores/stores.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ type SettingsStoreContent = {
userId: string;
};

type SettingsStore = Writable<SettingsStoreContent> & { reset: () => void };
type SettingsStore = Writable<SettingsStoreContent> & {
reset: () => void;
resetGasSettings: () => void;
};

type TransactionInfo =
| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ exports[`Allocate > should render the allocation page 1`] = `
<span
class="svelte-1c6b481"
>
0.020000000
0.100000000
</span>
</div>

Expand Down
44 changes: 27 additions & 17 deletions web-wallet/src/routes/(app)/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import { logout } from "$lib/navigation";
import loginInfoStorage from "$lib/services/loginInfoStorage";

const confirmResetMessage =
const confirmResetGasMessage =
"Are you sure you want to reset the gas settings to their defaults?";
const confirmResetWalletMessage =
"Confirm you've saved your recovery phrase before resetting the wallet. Proceed?";

const resetWallet = () =>
Expand All @@ -39,9 +41,16 @@
resetError = err;
});

function handleResetGasSettingsClick() {
// eslint-disable-next-line no-alert
if (confirm(confirmResetGasMessage)) {
settingsStore.resetGasSettings();
}
}

function handleResetWalletClick() {
// eslint-disable-next-line no-alert
if (confirm(confirmResetMessage)) {
if (confirm(confirmResetWalletMessage)) {
resetError = null;
resetWallet();
}
Expand All @@ -50,16 +59,15 @@
/** @type {(currency: { code: string, currency: string }) => SelectOption} */
const currencyToOption = rename({ code: "value", currency: "label" });
const currenciesToOptions = mapWith(currencyToOption);
const { currency, darkMode, gasLimit, gasPrice } = $settingsStore;
const { gasLimitLower, gasLimitUpper, gasPriceLower } = $gasStore;

let isDarkMode = darkMode;
let isGasValid = false;

/** @type {Error | null} */
let resetError = null;

$: ({ syncStatus } = $walletStore);
$: ({ currency, darkMode, gasLimit, gasPrice } = $settingsStore);
</script>

<section class="settings">
Expand All @@ -76,18 +84,16 @@
<div class="settings-group__multi-control-content">
<GasControls
on:gasSettings={(event) => {
isGasValid = areValidGasSettings(
event.detail.price,
event.detail.limit
);
const { limit, price } = event.detail;

if (isGasValid) {
settingsStore.update((store) => {
store.gasLimit = event.detail.limit;
store.gasPrice = event.detail.price;
isGasValid = areValidGasSettings(price, limit);

return store;
});
if (isGasValid) {
settingsStore.update((store) => ({
...store,
gasLimit: limit,
gasPrice: price,
}));
}
}}
limit={gasLimit}
Expand All @@ -96,6 +102,10 @@
price={gasPrice}
priceLower={gasPriceLower}
/>
<Button
on:click={handleResetGasSettingsClick}
text="Reset to defaults"
/>
</div>
</article>
<hr />
Expand Down Expand Up @@ -132,14 +142,14 @@
>
<span>Dark mode</span>
<Switch
bind:value={isDarkMode}
on:change={() => {
on:change={(event) => {
settingsStore.update((store) => {
store.darkMode = isDarkMode;
store.darkMode = event.detail;

return store;
});
}}
value={darkMode}
/>
</label>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ exports[`Settings > Resetting the wallet > should show an error if clearing loca
/>

</label>

<button
class="dusk-button dusk-button--type--button dusk-button--variant--primary dusk-button--size--default"
type="button"
>
<span
class="dusk-button__text"
>
Reset to defaults
</span>
</button>
</div>
</article>

Expand Down Expand Up @@ -631,6 +642,17 @@ exports[`Settings > should render the settings page displaying the status of the
/>

</label>

<button
class="dusk-button dusk-button--type--button dusk-button--variant--primary dusk-button--size--default"
type="button"
>
<span
class="dusk-button__text"
>
Reset to defaults
</span>
</button>
</div>
</article>

Expand Down Expand Up @@ -1165,6 +1187,17 @@ exports[`Settings > should render the settings page displaying the status of the
/>

</label>

<button
class="dusk-button dusk-button--type--button dusk-button--variant--primary dusk-button--size--default"
type="button"
>
<span
class="dusk-button__text"
>
Reset to defaults
</span>
</button>
</div>
</article>

Expand Down
Loading
Loading