Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
Signed-off-by: David Dal Busco <david.dalbusco@dfinity.org>
  • Loading branch information
peterpeterparker committed Sep 20, 2024
2 parents e36b518 + 9439537 commit 746b2c3
Show file tree
Hide file tree
Showing 34 changed files with 283 additions and 490 deletions.
15 changes: 3 additions & 12 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ jobs:
exit 1
}
spelling:
runs-on:
labels: dind-small
container:
image: ghcr.io/dfinity/minimal-runner-image:0.1
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -55,10 +52,7 @@ jobs:
- name: Spellcheck changelog
run: scripts/spellcheck-changelog
cargo-tests:
runs-on:
labels: dind-small
container:
image: ghcr.io/dfinity/minimal-runner-image:0.1
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
Expand Down Expand Up @@ -162,10 +156,7 @@ jobs:
fi
release-templating-works:
name: Release template
runs-on:
labels: dind-small
container:
image: ghcr.io/dfinity/minimal-runner-image:0.1
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG-Nns-Dapp-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ proposal is successful, the changes it released will be moved from this file to
* Move Canisters button from sidebar to account menu.
* Move GitHub button from account menu to sidebar.
* Reduce calls to `sns-governance` canister by getting `nervous_system_parameters` from the aggregator instead.
* Move theme toggle from account menu to sidebar.
* The `Markdown` UI component was migrated to `@dfinity/gix-components`.
* Upgrade frontend dev dependencies (`SvelteKit v2`, `vite`, `vitest`, etc.)

#### Deprecated

#### Removed

* Stop making unnecessary calls to load the SNS proposal every time we load the derived state.

#### Fixed

* Fixed a bug where a performance counter in `init` is wiped during state initialization.
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/lib/components/common/MenuItems.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
IconVote,
IconWallet,
MenuItem,
ThemeToggleButton,
} from "@dfinity/gix-components";
import { layoutMenuOpen, menuCollapsed } from "@dfinity/gix-components";
import type { ComponentType } from "svelte";
Expand Down Expand Up @@ -98,7 +99,10 @@

<div class="menu-footer" class:hidden={$menuCollapsed && !$layoutMenuOpen}>
<MenuMetrics />
<SourceCodeButton />
<div class="menu-footer-buttons">
<div class="grow-item"><SourceCodeButton /></div>
<ThemeToggleButton />
</div>
</div>
</div>

Expand Down Expand Up @@ -131,4 +135,11 @@
display: flex;
}
}
.menu-footer-buttons {
display: flex;
gap: var(--padding);
.grow-item {
flex-grow: 1;
}
}
</style>
4 changes: 1 addition & 3 deletions frontend/src/lib/components/header/AccountMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import LinkToCanisters from "./LinkToCanisters.svelte";
import LoginIconOnly from "./LoginIconOnly.svelte";
import Logout from "./Logout.svelte";
import { IconUser, ThemeToggle, Popover } from "@dfinity/gix-components";
import { IconUser, Popover } from "@dfinity/gix-components";
let visible = false;
let button: HTMLButtonElement | undefined;
Expand All @@ -32,8 +32,6 @@
<div class="info">
<AccountDetails />

<ThemeToggle />

<ManageInternetIdentityButton />

<SettingsButton on:nnsLink={() => (visible = false)} />
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/lib/components/metrics/TotalValueLocked.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@
width: 100%;
padding: var(--padding) var(--padding-2x);
&:hover {
background: var(--sidebar-button-background-hover);
}
&.stacked {
display: flex;
flex-direction: column-reverse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import { i18n } from "$lib/stores/i18n";
import type { SnsSummary } from "$lib/types/sns";
import NnsProposalCard from "../proposals/NnsProposalCard.svelte";
import type { ProposalId } from "@dfinity/nns";
import type { ProposalInfo } from "@dfinity/nns";
import { nonNullish } from "@dfinity/utils";
export let summary: SnsSummary;
let proposalId: ProposalId | undefined;
$: proposalId = getProjectProposal(summary);
let proposalInfo: ProposalInfo | undefined;
$: {
const proposalId = getProjectProposal(summary);
const loadProposalFromId = (proposalId: ProposalId | undefined) => {
if (nonNullish(proposalId)) {
loadProposal({
proposalId,
Expand All @@ -27,7 +30,9 @@
silentUpdateErrorMessages: true,
});
}
}
};
$: loadProposalFromId(proposalId);
</script>

{#if nonNullish(proposalInfo)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Markdown from "$lib/components/ui/Markdown.svelte";
import { Markdown } from "@dfinity/gix-components";
import { nonNullish } from "@dfinity/utils";
export let summary: string | undefined;
Expand Down
26 changes: 0 additions & 26 deletions frontend/src/lib/components/ui/Markdown.svelte

This file was deleted.

18 changes: 18 additions & 0 deletions frontend/src/lib/derived/sns-aggregator.derived.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { snsAggregatorStore } from "$lib/stores/sns-aggregator.store";
import type { CachedSnsDto } from "$lib/types/sns-aggregator";
import { derived, type Readable } from "svelte/store";

/**
* Creates a derived store, which maps root canister IDs to some data derived
* from SNS aggregator data.
*/
export const snsAggregatorDerived = <T>(
mapFn: (sns: CachedSnsDto) => T
): Readable<Record<string, T>> =>
derived(snsAggregatorStore, (aggregatorStore) =>
Object.fromEntries(
aggregatorStore.data?.map((sns) => {
return [sns.canister_ids.root_canister_id, mapFn(sns)];
}) ?? []
)
);
20 changes: 6 additions & 14 deletions frontend/src/lib/derived/sns-functions.derived.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { snsAggregatorStore } from "$lib/stores/sns-aggregator.store";
import { convertNervousFunction } from "$lib/utils/sns-aggregator-converters.utils";
import type { SnsNervousSystemFunction } from "@dfinity/sns";
import { derived, type Readable } from "svelte/store";
import { type Readable } from "svelte/store";
import { snsAggregatorDerived } from "./sns-aggregator.derived";

interface SnsNervousSystemFunctions {
nsFunctions: SnsNervousSystemFunction[];
Expand All @@ -18,15 +18,7 @@ export interface SnsNervousSystemFunctionsStore
/**
* A store that contains the nervous system functions for each sns project.
*/
export const snsFunctionsStore: SnsNervousSystemFunctionsStore = derived(
snsAggregatorStore,
(aggregatorStore) =>
Object.fromEntries(
aggregatorStore.data?.map((sns) => [
sns.canister_ids.root_canister_id,
{
nsFunctions: sns.parameters.functions.map(convertNervousFunction),
},
]) ?? []
)
);
export const snsFunctionsStore: SnsNervousSystemFunctionsStore =
snsAggregatorDerived((sns) => ({
nsFunctions: sns.parameters.functions.map(convertNervousFunction),
}));
24 changes: 6 additions & 18 deletions frontend/src/lib/derived/sns-parameters.derived.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { snsAggregatorStore } from "$lib/stores/sns-aggregator.store";
import { snsAggregatorDerived } from "$lib/derived/sns-aggregator.derived";
import { convertNervousSystemParameters } from "$lib/utils/sns-aggregator-converters.utils";
import type { SnsNervousSystemParameters } from "@dfinity/sns";
import { derived, type Readable } from "svelte/store";
import { type Readable } from "svelte/store";

export interface SnsParameters {
parameters: SnsNervousSystemParameters;
Expand All @@ -15,19 +15,7 @@ export interface SnsParametersStore {
/**
* A store that contains the sns nervous system parameters for each project.
*/
export const snsParametersStore: Readable<SnsParametersStore> = derived(
snsAggregatorStore,
(aggregatorStore) =>
Object.fromEntries(
aggregatorStore.data?.map((sns) => {
return [
sns.canister_ids.root_canister_id,
{
parameters: convertNervousSystemParameters(
sns.nervous_system_parameters
),
},
];
}) ?? []
)
);
export const snsParametersStore: Readable<SnsParametersStore> =
snsAggregatorDerived((sns) => ({
parameters: convertNervousSystemParameters(sns.nervous_system_parameters),
}));
20 changes: 6 additions & 14 deletions frontend/src/lib/derived/sns-total-token-supply.derived.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { snsAggregatorStore } from "$lib/stores/sns-aggregator.store";
import type { RootCanisterIdText } from "$lib/types/sns";
import { derived, type Readable } from "svelte/store";
import { type Readable } from "svelte/store";
import { snsAggregatorDerived } from "./sns-aggregator.derived";

interface ProjectTotalSupplyData {
totalSupply: bigint;
Expand All @@ -17,15 +17,7 @@ export interface SnsTotalTokenSupplyStore
/**
* A store that contains the total token supply of SNS projects.
*/
export const snsTotalTokenSupplyStore: SnsTotalTokenSupplyStore = derived(
snsAggregatorStore,
(aggregatorStore) =>
Object.fromEntries(
aggregatorStore.data?.map((sns) => [
sns.canister_ids.root_canister_id,
{
totalSupply: BigInt(sns.icrc1_total_supply),
},
]) ?? []
)
);
export const snsTotalTokenSupplyStore: SnsTotalTokenSupplyStore =
snsAggregatorDerived((sns) => ({
totalSupply: BigInt(sns.icrc1_total_supply),
}));
16 changes: 16 additions & 0 deletions frontend/src/lib/services/sns-neurons.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "$lib/api/sns.api";
import { FORCE_CALL_STRATEGY } from "$lib/constants/mockable.constants";
import { HOTKEY_PERMISSIONS } from "$lib/constants/sns-neurons.constants";
import { snsParametersStore } from "$lib/derived/sns-parameters.derived";
import { snsTokenSymbolSelectedStore } from "$lib/derived/sns/sns-token-symbol-selected.store";
import { snsTokensByRootCanisterIdStore } from "$lib/derived/sns/sns-tokens.derived";
import { loadActionableProposalsForSns } from "$lib/services/actionable-sns-proposals.services";
Expand Down Expand Up @@ -506,6 +507,21 @@ export const stakeNeuron = async ({
const identity = await getAuthenticatedIdentity();
const stakeE8s = numberToE8s(amount);

// The stakeNeuron function should not be called with an amount smaller than
// the minimum stake. This check is only here to prevent people losing
// tokens if the check is accidentally not done before, but does not provide
// a proper error message.
const paramsStore = get(snsParametersStore);
const minimumStakeE8s = fromDefinedNullable(
paramsStore[rootCanisterId.toText()]?.parameters
?.neuron_minimum_stake_e8s ?? []
);
if (stakeE8s < minimumStakeE8s) {
throw new Error(
"The caller should make sure the amount is at least the minimum stake"
);
}

const fee = get(snsTokensByRootCanisterIdStore)[rootCanisterId.toText()]
?.fee;

Expand Down
Loading

0 comments on commit 746b2c3

Please sign in to comment.