From 7adc78f3cd5ca6a983146a49f7b28cb542650db5 Mon Sep 17 00:00:00 2001 From: samaradel Date: Sun, 19 May 2024 16:10:00 +0300 Subject: [PATCH 1/6] Check balance before updating email --- .../playground/src/dashboard/twin_view.vue | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/playground/src/dashboard/twin_view.vue b/packages/playground/src/dashboard/twin_view.vue index c266c550c9..3fcb4d8aa8 100644 --- a/packages/playground/src/dashboard/twin_view.vue +++ b/packages/playground/src/dashboard/twin_view.vue @@ -189,8 +189,8 @@ import { useGrid, useProfileManager } from "../stores"; import type { FarmInterface } from "../types"; import { createCustomToast, ToastType } from "../utils/custom_toast"; import { getFarms } from "../utils/get_farms"; -import { getGrid, storeEmail } from "../utils/grid"; - +import type { Balance } from "../utils/grid"; +import { loadBalance, storeEmail } from "../utils/grid"; const profileManager = useProfileManager(); const editingTwin = ref(false); @@ -264,13 +264,21 @@ function redirectToDao() { async function saveEmail() { try { - loading.value = true; - savingEmail.value = true; - profileManager.updateEmail(email.value); - await storeEmail(grid!, email.value); - editEmail.value = false; - loading.value = false; - savingEmail.value = false; + const balance: Balance = await loadBalance(grid!); + if (balance.free < 1) { + createCustomToast( + "Invalid Transaction: Inability to pay some fees, e.g. account balance too low", + ToastType.danger, + ); + } else { + loading.value = true; + savingEmail.value = true; + profileManager.updateEmail(email.value); + await storeEmail(grid!, email.value); + editEmail.value = false; + loading.value = false; + savingEmail.value = false; + } } catch (e) { console.log(e); } From fd33ebe3f9c2c7720c38450fc1b9d5791683d41d Mon Sep 17 00:00:00 2001 From: samaradel Date: Sun, 19 May 2024 16:20:25 +0300 Subject: [PATCH 2/6] Disable editing email when save with low balance --- packages/playground/src/dashboard/twin_view.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/playground/src/dashboard/twin_view.vue b/packages/playground/src/dashboard/twin_view.vue index 3fcb4d8aa8..2b81ab9469 100644 --- a/packages/playground/src/dashboard/twin_view.vue +++ b/packages/playground/src/dashboard/twin_view.vue @@ -266,6 +266,7 @@ async function saveEmail() { try { const balance: Balance = await loadBalance(grid!); if (balance.free < 1) { + editEmail.value = false; createCustomToast( "Invalid Transaction: Inability to pay some fees, e.g. account balance too low", ToastType.danger, From e053788bd3be7bbe2cbc3e1f6fe7a40449ec3765 Mon Sep 17 00:00:00 2001 From: samaradel Date: Mon, 20 May 2024 12:27:03 +0300 Subject: [PATCH 3/6] - Enhance updating email in low balance message - Combine imports --- packages/playground/src/dashboard/twin_view.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/playground/src/dashboard/twin_view.vue b/packages/playground/src/dashboard/twin_view.vue index 2b81ab9469..c22eb8601d 100644 --- a/packages/playground/src/dashboard/twin_view.vue +++ b/packages/playground/src/dashboard/twin_view.vue @@ -189,8 +189,7 @@ import { useGrid, useProfileManager } from "../stores"; import type { FarmInterface } from "../types"; import { createCustomToast, ToastType } from "../utils/custom_toast"; import { getFarms } from "../utils/get_farms"; -import type { Balance } from "../utils/grid"; -import { loadBalance, storeEmail } from "../utils/grid"; +import { type Balance, loadBalance, storeEmail } from "../utils/grid"; const profileManager = useProfileManager(); const editingTwin = ref(false); @@ -268,7 +267,7 @@ async function saveEmail() { if (balance.free < 1) { editEmail.value = false; createCustomToast( - "Invalid Transaction: Inability to pay some fees, e.g. account balance too low", + "Transaction Error: Unable to Process Payment - Insufficient Account Balance.", ToastType.danger, ); } else { From ebe1198ee8b79cc481850948e5c5856208cea5a6 Mon Sep 17 00:00:00 2001 From: samaradel Date: Tue, 21 May 2024 13:52:48 +0300 Subject: [PATCH 4/6] Add cancel editing function --- packages/playground/src/dashboard/twin_view.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/playground/src/dashboard/twin_view.vue b/packages/playground/src/dashboard/twin_view.vue index c22eb8601d..922663cdb9 100644 --- a/packages/playground/src/dashboard/twin_view.vue +++ b/packages/playground/src/dashboard/twin_view.vue @@ -98,6 +98,7 @@ :disabled="!isValid || savingEmail" > + @@ -261,6 +262,11 @@ function redirectToDao() { router.push({ path: "/tf-chain/dao" }); } +function cancelEditing() { + email.value = ""; + editEmail.value = false; +} + async function saveEmail() { try { const balance: Balance = await loadBalance(grid!); From 626cccebee506cf789c291b4d8cd9efb07723d21 Mon Sep 17 00:00:00 2001 From: samaradel Date: Tue, 21 May 2024 14:22:39 +0300 Subject: [PATCH 5/6] Reset input on cancel --- packages/playground/src/dashboard/twin_view.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/playground/src/dashboard/twin_view.vue b/packages/playground/src/dashboard/twin_view.vue index 922663cdb9..eb05f7b76d 100644 --- a/packages/playground/src/dashboard/twin_view.vue +++ b/packages/playground/src/dashboard/twin_view.vue @@ -272,6 +272,7 @@ async function saveEmail() { const balance: Balance = await loadBalance(grid!); if (balance.free < 1) { editEmail.value = false; + email.value = ""; createCustomToast( "Transaction Error: Unable to Process Payment - Insufficient Account Balance.", ToastType.danger, From 6115f6bdd6ae83e29cb70a685c199860aaaafd5d Mon Sep 17 00:00:00 2001 From: samaradel Date: Wed, 22 May 2024 17:09:09 +0300 Subject: [PATCH 6/6] keep the old email when edit --- packages/playground/src/dashboard/twin_view.vue | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/playground/src/dashboard/twin_view.vue b/packages/playground/src/dashboard/twin_view.vue index eb05f7b76d..3e7c905b2b 100644 --- a/packages/playground/src/dashboard/twin_view.vue +++ b/packages/playground/src/dashboard/twin_view.vue @@ -98,7 +98,7 @@ :disabled="!isValid || savingEmail" > - + @@ -202,7 +202,7 @@ const numberOfProposalsToVoteOn = ref(0); const userFarms = ref(); const activeProposalsUserHasVotedOn = ref(0); const bridge = (window as any).env.BRIDGE_TFT_ADDRESS; -const email = ref(""); +const email = ref(profileManager.profile?.email || ""); const loading = ref(false); const editEmail = ref(false); const isValid = ref(false); @@ -262,17 +262,11 @@ function redirectToDao() { router.push({ path: "/tf-chain/dao" }); } -function cancelEditing() { - email.value = ""; - editEmail.value = false; -} - async function saveEmail() { try { const balance: Balance = await loadBalance(grid!); if (balance.free < 1) { editEmail.value = false; - email.value = ""; createCustomToast( "Transaction Error: Unable to Process Payment - Insufficient Account Balance.", ToastType.danger,