From 3eebddb51b174854227a261ad891bb990b8d15a4 Mon Sep 17 00:00:00 2001 From: Matt Grogan Date: Sat, 14 Oct 2023 00:26:14 +0100 Subject: [PATCH] Support subaccount for transfer_sns_funds proposal (#4581) --- .../components/home/MakeProposalModal.svelte | 44 +++++++++++++------ .../home/ProposalGroupFilters.svelte | 2 +- frontend/app/src/i18n/cn.json | 9 ++-- frontend/app/src/i18n/de.json | 9 ++-- frontend/app/src/i18n/en.json | 7 ++- frontend/app/src/i18n/es.json | 9 ++-- frontend/app/src/i18n/fr.json | 9 ++-- frontend/app/src/i18n/it.json | 9 ++-- frontend/app/src/i18n/iw.json | 9 ++-- frontend/app/src/i18n/jp.json | 9 ++-- frontend/app/src/i18n/ru.json | 9 ++-- frontend/app/src/i18n/vi.json | 9 ++-- frontend/app/src/utils/sns.ts | 5 +++ .../src/services/user/mappers.ts | 6 ++- .../openchat-shared/src/domain/proposals.ts | 7 ++- 15 files changed, 106 insertions(+), 46 deletions(-) diff --git a/frontend/app/src/components/home/MakeProposalModal.svelte b/frontend/app/src/components/home/MakeProposalModal.svelte index f2d068d963..40d24c4183 100644 --- a/frontend/app/src/components/home/MakeProposalModal.svelte +++ b/frontend/app/src/components/home/MakeProposalModal.svelte @@ -16,7 +16,7 @@ import TextArea from "../TextArea.svelte"; import Select from "../Select.svelte"; import Radio from "../Radio.svelte"; - import { isPrincipalValid } from "../../utils/sns"; + import { isPrincipalValid, isSubAccountValid } from "../../utils/sns"; import PencilIcon from "svelte-material-icons/PencilOutline.svelte"; import EyeIcon from "svelte-material-icons/EyeOutline.svelte"; import Markdown from "./Markdown.svelte"; @@ -42,7 +42,8 @@ let summary = ""; let treasury: Treasury = "SNS"; let amountText = ""; - let recipient = ""; + let recipientOwner = ""; + let recipientSubaccount = ""; let step = -1; let actualWidth = 0; let summaryPreview = false; @@ -50,7 +51,6 @@ let selectedProposalType: "motion" | "transfer_sns_funds" = "motion"; let message = ""; let error = true; - let recipientValid = false; let summaryContainerHeight = 0; let summaryHeight = 0; let refreshingBalance = false; @@ -73,13 +73,16 @@ $: summaryValid = summary.length >= MIN_SUMMARY_LENGTH && summary.length <= MAX_SUMMARY_LENGTH; $: amount = Number(amountText) * Number(Math.pow(10, tokenDetails.decimals)); $: amountValid = amount >= transferFee; - $: recipientValid = isPrincipalValid(recipient); + $: recipientOwnerValid = isPrincipalValid(recipientOwner); + $: recipientSubaccountValid = + recipientSubaccount.length === 0 || isSubAccountValid(recipientSubaccount); $: valid = !insufficientFunds && titleValid && urlValid && summaryValid && - (selectedProposalType === "motion" || (amountValid && recipientValid)); + (selectedProposalType === "motion" || + (amountValid && recipientOwnerValid && recipientSubaccountValid)); $: canSubmit = step === 2 || (step === 1 && selectedProposalType === "motion"); $: { @@ -117,7 +120,13 @@ ? { kind: selectedProposalType } : { kind: selectedProposalType, - toPrincipal: recipient, + recipient: { + owner: recipientOwner, + subaccount: + recipientSubaccount.length > 0 + ? recipientSubaccount.padStart(64, "0") + : undefined, + }, amount: BigInt(Math.floor(amount)), treasury, }; @@ -296,15 +305,24 @@ on:change={() => (treasury = "ICP")} />
- + 0 && !recipientValid} - bind:value={recipient} - minlength={MIN_TITLE_LENGTH} - maxlength={MAX_TITLE_LENGTH} - countdown - placeholder={$_("proposal.maker.enterToPrincipal")} /> + invalid={recipientOwner.length > 0 && !recipientOwnerValid} + maxlength={63} + bind:value={recipientOwner} + placeholder={$_("proposal.maker.enterRecipientOwner")} /> +
+
+ +