Skip to content

Commit

Permalink
Updating formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 27, 2024
1 parent a3f9ef2 commit d98d0b4
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 264 deletions.
17 changes: 7 additions & 10 deletions packages/nns/src/canisters/governance/request.converters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { Principal } from "@dfinity/principal";
import { arrayBufferToUint8Array, toNullable } from "@dfinity/utils";
import type { ManageNeuron as RawManageNeuron } from "../../../candid/governance";
import { CanisterAction, LogVisibility } from "../../enums/governance.enums";
import {
GovernanceParameters,
InstallMode,
} from "../../types/governance_converters";
import { toMakeProposalRawRequest } from "./request.converters";
import {
CanisterAction,
LogVisibility,
NeuronVisibility,
} from "../../enums/governance.enums";

describe("request.converters", () => {
describe("should convert MakeProposalRequest to RawManageNeuron", () => {
Expand Down Expand Up @@ -639,7 +635,7 @@ describe("request.converters", () => {
computeAllocation: 1n,
wasmMemoryLimit: 123456n,
logVisibility: LogVisibility.Controllers,
}
},
},
},
neuronId,
Expand All @@ -659,9 +655,11 @@ describe("request.converters", () => {
canister_id: [Principal.fromText("miw6j-knlcl-xq")],
settings: [
{
controllers: [{
controllers: [Principal.fromText("miw6j-knlcl-xq")],
}],
controllers: [
{
controllers: [Principal.fromText("miw6j-knlcl-xq")],
},
],
freezing_threshold: [100n],
memory_allocation: [234567n],
compute_allocation: [1n],
Expand All @@ -687,6 +685,5 @@ describe("request.converters", () => {
const result = toMakeProposalRawRequest(mockRequest);
expect(result).toEqual(expectedOutput);
});

});
});
190 changes: 96 additions & 94 deletions packages/nns/src/canisters/governance/request.converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type {
Tokens as RawTokens,
VotingRewardParameters as RawVotingRewardParameters,
} from "../../../candid/governance";
import type { Vote, NeuronVisibility } from "../../enums/governance.enums";
import type { NeuronVisibility, Vote } from "../../enums/governance.enums";
import { UnsupportedValueError } from "../../errors/governance.errors";
import type { E8s, NeuronId, Option } from "../../types/common";
import type {
Expand Down Expand Up @@ -194,10 +194,10 @@ const fromSwapParameters = (
neuron_basket_construction_parameters:
swapParameters.neuronBasketConstructionParameters !== undefined
? [
fromNeuronBasketConstructionParameters(
swapParameters.neuronBasketConstructionParameters,
),
]
fromNeuronBasketConstructionParameters(
swapParameters.neuronBasketConstructionParameters,
),
]
: [],
confirmation_text:
swapParameters.confirmationText !== undefined
Expand Down Expand Up @@ -287,10 +287,10 @@ const fromGovernanceParameters = (
proposal_wait_for_quiet_deadline_increase:
governanceParameters.proposalWaitForQuietDeadlineIncrease !== undefined
? [
fromDuration(
governanceParameters.proposalWaitForQuietDeadlineIncrease,
),
]
fromDuration(
governanceParameters.proposalWaitForQuietDeadlineIncrease,
),
]
: [],
proposal_initial_voting_period:
governanceParameters.proposalInitialVotingPeriod !== undefined
Expand All @@ -303,10 +303,10 @@ const fromGovernanceParameters = (
voting_reward_parameters:
governanceParameters.votingRewardParameters !== undefined
? [
fromVotingRewardParameters(
governanceParameters.votingRewardParameters,
),
]
fromVotingRewardParameters(
governanceParameters.votingRewardParameters,
),
]
: [],
});

Expand All @@ -329,10 +329,10 @@ const fromInitialTokenDistribution = (
developer_distribution:
initialTokenDistribution.developerDistribution !== undefined
? [
fromDeveloperDistribution(
initialTokenDistribution.developerDistribution,
),
]
fromDeveloperDistribution(
initialTokenDistribution.developerDistribution,
),
]
: [],
swap_distribution:
initialTokenDistribution.swapDistribution !== undefined
Expand Down Expand Up @@ -380,10 +380,10 @@ const fromCreateServiceNervousSystem = (
governance_parameters:
createServiceNervousSystem.governanceParameters !== undefined
? [
fromGovernanceParameters(
createServiceNervousSystem.governanceParameters,
),
]
fromGovernanceParameters(
createServiceNervousSystem.governanceParameters,
),
]
: [],
fallback_controller_principal_ids:
createServiceNervousSystem.fallbackControllerPrincipalIds.map((id) =>
Expand Down Expand Up @@ -417,10 +417,10 @@ const fromCreateServiceNervousSystem = (
initial_token_distribution:
createServiceNervousSystem.initialTokenDistribution !== undefined
? [
fromInitialTokenDistribution(
createServiceNervousSystem.initialTokenDistribution,
),
]
fromInitialTokenDistribution(
createServiceNervousSystem.initialTokenDistribution,
),
]
: [],
});

Expand Down Expand Up @@ -462,21 +462,23 @@ const fromCanisterSettings = (
return canisterSettings === undefined
? []
: [
{
freezing_threshold: toNullable(canisterSettings.freezingThreshold),
controllers: canisterSettings.controllers
? [
{
controllers: canisterSettings.controllers.map(controller => Principal.fromText(controller)),
},
]
: [],
log_visibility: toNullable(canisterSettings.logVisibility as number),
wasm_memory_limit: toNullable(canisterSettings.wasmMemoryLimit),
compute_allocation: toNullable(canisterSettings.computeAllocation),
memory_allocation: toNullable(canisterSettings.memoryAllocation),
},
];
{
freezing_threshold: toNullable(canisterSettings.freezingThreshold),
controllers: canisterSettings.controllers
? [
{
controllers: canisterSettings.controllers.map((controller) =>
Principal.fromText(controller),
),
},
]
: [],
log_visibility: toNullable(canisterSettings.logVisibility as number),
wasm_memory_limit: toNullable(canisterSettings.wasmMemoryLimit),
compute_allocation: toNullable(canisterSettings.computeAllocation),
memory_allocation: toNullable(canisterSettings.memoryAllocation),
},
];
};

const fromAction = (action: Action): RawAction => {
Expand Down Expand Up @@ -622,20 +624,20 @@ const fromAction = (action: Action): RawAction => {
request === undefined
? []
: [
{
open_time_window:
request.openTimeWindow === undefined
? []
: [
{
start_timestamp_seconds:
request.openTimeWindow.startTimestampSeconds,
end_timestamp_seconds:
request.openTimeWindow.endTimestampSeconds,
},
],
},
],
{
open_time_window:
request.openTimeWindow === undefined
? []
: [
{
start_timestamp_seconds:
request.openTimeWindow.startTimestampSeconds,
end_timestamp_seconds:
request.openTimeWindow.endTimestampSeconds,
},
],
},
],

swap_canister_id:
swapCanisterId === undefined
Expand All @@ -657,26 +659,26 @@ const fromAction = (action: Action): RawAction => {
params === undefined
? []
: [
{
min_participant_icp_e8s: params.minParticipantIcpE8s,
max_icp_e8s: params.maxIcpE8s,
swap_due_timestamp_seconds: params.swapDueTimestampSeconds,
min_participants: params.minParticipants,
sns_token_e8s: params.snsTokenE8s,
max_participant_icp_e8s: params.maxParticipantIcpE8s,
min_icp_e8s: params.minIcpE8s,
sale_delay_seconds: toNullable(params.saleDelaySeconds),
neuron_basket_construction_parameters: toNullable(
params.neuronBasketConstructionParameters,
),
max_direct_participation_icp_e8s: toNullable(
params.maxDirectParticipationIcpE8s,
),
min_direct_participation_icp_e8s: toNullable(
params.minDirectParticipationIcpE8s,
),
},
],
{
min_participant_icp_e8s: params.minParticipantIcpE8s,
max_icp_e8s: params.maxIcpE8s,
swap_due_timestamp_seconds: params.swapDueTimestampSeconds,
min_participants: params.minParticipants,
sns_token_e8s: params.snsTokenE8s,
max_participant_icp_e8s: params.maxParticipantIcpE8s,
min_icp_e8s: params.minIcpE8s,
sale_delay_seconds: toNullable(params.saleDelaySeconds),
neuron_basket_construction_parameters: toNullable(
params.neuronBasketConstructionParameters,
),
max_direct_participation_icp_e8s: toNullable(
params.maxDirectParticipationIcpE8s,
),
min_direct_participation_icp_e8s: toNullable(
params.minDirectParticipationIcpE8s,
),
},
],
},
};
}
Expand Down Expand Up @@ -987,38 +989,38 @@ const fromNeuronsFundEconomics = (
isNullish(percentage)
? []
: [
{
basis_points: toNullable(percentage.basisPoints),
},
];
{
basis_points: toNullable(percentage.basisPoints),
},
];

const toRawDecimals = (decimal: Option<Decimal>): [] | [RawDecimal] =>
isNullish(decimal)
? []
: [
{
human_readable: toNullable(decimal.humanReadable),
},
];
{
human_readable: toNullable(decimal.humanReadable),
},
];

const toRawNeuronsFundMatchedFundingCurveCoefficients = (
neuronsFundMatchedFundingCurveCoefficients: Option<NeuronsFundMatchedFundingCurveCoefficients>,
): [] | [RawNeuronsFundMatchedFundingCurveCoefficients] =>
isNullish(neuronsFundMatchedFundingCurveCoefficients)
? []
: [
{
contribution_threshold_xdr: toRawDecimals(
neuronsFundMatchedFundingCurveCoefficients.contributionThresholdXdr,
),
full_participation_milestone_xdr: toRawDecimals(
neuronsFundMatchedFundingCurveCoefficients.fullParticipationMilestoneXdr,
),
one_third_participation_milestone_xdr: toRawDecimals(
neuronsFundMatchedFundingCurveCoefficients.oneThirdParticipationMilestoneXdr,
),
},
];
{
contribution_threshold_xdr: toRawDecimals(
neuronsFundMatchedFundingCurveCoefficients.contributionThresholdXdr,
),
full_participation_milestone_xdr: toRawDecimals(
neuronsFundMatchedFundingCurveCoefficients.fullParticipationMilestoneXdr,
),
one_third_participation_milestone_xdr: toRawDecimals(
neuronsFundMatchedFundingCurveCoefficients.oneThirdParticipationMilestoneXdr,
),
},
];

return [
{
Expand Down
Loading

0 comments on commit d98d0b4

Please sign in to comment.