From 034e96d87bc24c8f4de0cd42f1a8fcc3701cd6b7 Mon Sep 17 00:00:00 2001 From: Adesojisouljay Date: Tue, 15 Aug 2023 11:59:39 +0100 Subject: [PATCH 1/5] exchange handlers --- src/common/components/transfer/index.tsx | 76 ++++++++++++++++-------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/src/common/components/transfer/index.tsx b/src/common/components/transfer/index.tsx index 88556d2d370..276d5ea11b3 100644 --- a/src/common/components/transfer/index.tsx +++ b/src/common/components/transfer/index.tsx @@ -155,7 +155,8 @@ interface State { to: string; toData: Account | null; toError: string; - toExchangeError: string; + toExchangeWarning: string; + exchangeWarning: string; memoError: string; toWarning: string; amount: string; @@ -189,7 +190,8 @@ const pureState = (props: Props): State => { to: props.to || _to, toData: props.to ? { name: props.to } : _toData, toError: "", - toExchangeError: "", + toExchangeWarning: "", + exchangeWarning: "", memoError: "", toWarning: "", amount: props.amount || "0.001", @@ -221,30 +223,49 @@ export class Transfer extends BaseComponent { } assetChanged = (asset: TransferAsset) => { + const { to } = this.state; this.stateSet({ asset }, () => { this.checkAmount(); + this.exchangeHandler(to); }); }; + exchangeHandler = (to: string) => { + const { asset, memo } = this.state; + + if (exchangeAccounts.includes(to) && asset !== "HIVE") { + this.stateSet({ exchangeWarning: "can not send hbd to exchange account", toExchangeWarning: ""}) + console.log("can not send hbd to exchange account"); + } else if (exchangeAccounts.includes(to) && asset === "HIVE" && !memo) { + this.stateSet({ toExchangeWarning: _t("transfer.memo-required"), exchangeWarning: "" }); + console.log("sending assets...With memo...💯💯"); + } else{ + this.stateSet({ toExchangeWarning: "", exchangeWarning: "" }); + } + } + toChanged = (e: React.ChangeEvent) => { const { value: to } = e.target; + const { asset } = this.state; this.stateSet({ to }, this.handleTo); // Check memo if to is an exchange account - if (exchangeAccounts.includes(to)) { - this.stateSet({ toExchangeError: _t("transfer.memo-required") }); - } else { - this.stateSet({ toExchangeError: "" }); - } + this.exchangeHandler(to); + // if (exchangeAccounts.includes(to) && asset === "HIVE") { + // this.stateSet({ toExchangeWarning: _t("transfer.memo-required") }); + // } else { + // this.stateSet({ toExchangeWarning: "" }); + // } }; toSelected = (to: string) => { this.stateSet({ to }, this.handleTo); // Check memo if selected is an exchange account - if (exchangeAccounts.includes(to)) { - this.stateSet({ toExchangeError: _t("transfer.memo-required") }); - } else { - this.stateSet({ toExchangeError: "" }); - } + this.exchangeHandler(to); + // if (exchangeAccounts.includes(to)) { + // this.stateSet({ toExchangeWarning: _t("transfer.memo-required") }); + // } else { + // this.stateSet({ toExchangeWarning: "" }); + // } }; amountChanged = (e: React.ChangeEvent): void => { @@ -256,18 +277,20 @@ export class Transfer extends BaseComponent { memoChanged = (e: React.ChangeEvent): void => { const { value: memo } = e.target; + const { to } = this.state; const mError = cryptoUtils.isWif(memo.trim()); if (mError) this.setState({ memoError: _t("transfer.memo-error").toUpperCase() }); this.stateSet({ memo }); - if (memo) { - { - this.stateSet({ toExchangeError: "" }); - } - } else { - { - this.stateSet({ toExchangeError: _t("transfer.memo-required") }); - } - } + this.exchangeHandler(to); + // if (memo) { + // { + // this.stateSet({ toExchangeWarning: "" }); + // } + // } else { + // { + // this.stateSet({ toExchangeWarning: _t("transfer.memo-required") }); + // } + // } }; handleTo = () => { @@ -431,15 +454,16 @@ export class Transfer extends BaseComponent { }; canSubmit = () => { - const { toData, toError, amountError, memoError, inProgress, amount, toExchangeError } = + const { toData, toError, amountError, memoError, inProgress, amount, toExchangeWarning, exchangeWarning } = this.state; return ( toData && - !toExchangeError && + !toExchangeWarning && !toError && !amountError && !memoError && !inProgress && + !exchangeWarning && parseFloat(amount) > 0 ); }; @@ -677,7 +701,8 @@ export class Transfer extends BaseComponent { asset, to, toError, - toExchangeError, + toExchangeWarning, + exchangeWarning, toWarning, amount, amountError, @@ -900,7 +925,8 @@ export class Transfer extends BaseComponent { {toWarning && } {toError && } - {toExchangeError && } + {toExchangeWarning && } + {exchangeWarning && } )} From 6c608743306874013856b7faaff410ca4559c18f Mon Sep 17 00:00:00 2001 From: Adesojisouljay Date: Tue, 15 Aug 2023 14:36:29 +0100 Subject: [PATCH 2/5] handle memo --- src/common/components/transfer/index.tsx | 43 ++++++------------------ src/common/i18n/locales/en-US.json | 1 + 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/common/components/transfer/index.tsx b/src/common/components/transfer/index.tsx index 276d5ea11b3..7185aef8d4c 100644 --- a/src/common/components/transfer/index.tsx +++ b/src/common/components/transfer/index.tsx @@ -223,49 +223,37 @@ export class Transfer extends BaseComponent { } assetChanged = (asset: TransferAsset) => { - const { to } = this.state; + const { to, memo } = this.state; this.stateSet({ asset }, () => { this.checkAmount(); - this.exchangeHandler(to); + this.exchangeHandler(to, memo); }); }; - exchangeHandler = (to: string) => { - const { asset, memo } = this.state; + exchangeHandler = (to: string, memo: string) => { + const { asset } = this.state; if (exchangeAccounts.includes(to) && asset !== "HIVE") { - this.stateSet({ exchangeWarning: "can not send hbd to exchange account", toExchangeWarning: ""}) - console.log("can not send hbd to exchange account"); + this.stateSet({ exchangeWarning: _t("transfer.invalid-asset"), toExchangeWarning: ""}) } else if (exchangeAccounts.includes(to) && asset === "HIVE" && !memo) { this.stateSet({ toExchangeWarning: _t("transfer.memo-required"), exchangeWarning: "" }); - console.log("sending assets...With memo...💯💯"); } else{ this.stateSet({ toExchangeWarning: "", exchangeWarning: "" }); } + } toChanged = (e: React.ChangeEvent) => { const { value: to } = e.target; - const { asset } = this.state; + const { memo } = this.state; this.stateSet({ to }, this.handleTo); - // Check memo if to is an exchange account - this.exchangeHandler(to); - // if (exchangeAccounts.includes(to) && asset === "HIVE") { - // this.stateSet({ toExchangeWarning: _t("transfer.memo-required") }); - // } else { - // this.stateSet({ toExchangeWarning: "" }); - // } + this.exchangeHandler(to, memo); }; toSelected = (to: string) => { this.stateSet({ to }, this.handleTo); - // Check memo if selected is an exchange account - this.exchangeHandler(to); - // if (exchangeAccounts.includes(to)) { - // this.stateSet({ toExchangeWarning: _t("transfer.memo-required") }); - // } else { - // this.stateSet({ toExchangeWarning: "" }); - // } + const { memo } = this.state; + this.exchangeHandler(to, memo); }; amountChanged = (e: React.ChangeEvent): void => { @@ -281,16 +269,7 @@ export class Transfer extends BaseComponent { const mError = cryptoUtils.isWif(memo.trim()); if (mError) this.setState({ memoError: _t("transfer.memo-error").toUpperCase() }); this.stateSet({ memo }); - this.exchangeHandler(to); - // if (memo) { - // { - // this.stateSet({ toExchangeWarning: "" }); - // } - // } else { - // { - // this.stateSet({ toExchangeWarning: _t("transfer.memo-required") }); - // } - // } + this.exchangeHandler(to, memo); }; handleTo = () => { diff --git a/src/common/i18n/locales/en-US.json b/src/common/i18n/locales/en-US.json index e5eb1495e62..9e4649d7b44 100644 --- a/src/common/i18n/locales/en-US.json +++ b/src/common/i18n/locales/en-US.json @@ -1222,6 +1222,7 @@ "memo-help": "This memo is public", "memo-error": "Never put private keys into a memo field, it is publicly visible to everyone.", "memo-required": "Transfer to an exchange must have a memo.", + "invalid-asset": "You can only send hive to an exchange account.", "available-hp-hint": "* available hive power", "override-warning-1": "The new amount overrides the previous one.", "override-warning-2": "Account ({{account}}) has already been delegated with {{previousAmount}}.", From fb58e1aa390c9519adcc5e7151583b31b52649b4 Mon Sep 17 00:00:00 2001 From: Talha Saeed Date: Wed, 4 Oct 2023 16:32:16 +0500 Subject: [PATCH 3/5] Removed Extra state and minimize function code --- src/common/components/transfer/index.tsx | 26 ++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/common/components/transfer/index.tsx b/src/common/components/transfer/index.tsx index 7185aef8d4c..554857690ce 100644 --- a/src/common/components/transfer/index.tsx +++ b/src/common/components/transfer/index.tsx @@ -155,7 +155,6 @@ interface State { to: string; toData: Account | null; toError: string; - toExchangeWarning: string; exchangeWarning: string; memoError: string; toWarning: string; @@ -190,7 +189,6 @@ const pureState = (props: Props): State => { to: props.to || _to, toData: props.to ? { name: props.to } : _toData, toError: "", - toExchangeWarning: "", exchangeWarning: "", memoError: "", toWarning: "", @@ -232,16 +230,17 @@ export class Transfer extends BaseComponent { exchangeHandler = (to: string, memo: string) => { const { asset } = this.state; - - if (exchangeAccounts.includes(to) && asset !== "HIVE") { - this.stateSet({ exchangeWarning: _t("transfer.invalid-asset"), toExchangeWarning: ""}) - } else if (exchangeAccounts.includes(to) && asset === "HIVE" && !memo) { - this.stateSet({ toExchangeWarning: _t("transfer.memo-required"), exchangeWarning: "" }); - } else{ - this.stateSet({ toExchangeWarning: "", exchangeWarning: "" }); + + if (exchangeAccounts.includes(to)) { + if (asset !== "HIVE") { + this.stateSet({ exchangeWarning: _t("transfer.invalid-asset") }); + } else if (asset === "HIVE" && !memo) { + this.stateSet({ exchangeWarning: _t("transfer.memo-required") }); + } else { + this.stateSet({ exchangeWarning: "" }); + } } - - } + }; toChanged = (e: React.ChangeEvent) => { const { value: to } = e.target; @@ -433,11 +432,10 @@ export class Transfer extends BaseComponent { }; canSubmit = () => { - const { toData, toError, amountError, memoError, inProgress, amount, toExchangeWarning, exchangeWarning } = + const { toData, toError, amountError, memoError, inProgress, amount, exchangeWarning } = this.state; return ( toData && - !toExchangeWarning && !toError && !amountError && !memoError && @@ -680,7 +678,6 @@ export class Transfer extends BaseComponent { asset, to, toError, - toExchangeWarning, exchangeWarning, toWarning, amount, @@ -904,7 +901,6 @@ export class Transfer extends BaseComponent { {toWarning && } {toError && } - {toExchangeWarning && } {exchangeWarning && } )} From 7dfcb413d3ce48ad98b954498734c19640eb4a2f Mon Sep 17 00:00:00 2001 From: Talha Saeed Date: Fri, 6 Oct 2023 11:34:15 +0500 Subject: [PATCH 4/5] Fix styling in modal suggestion and seach suggestion --- src/common/components/suggestion-list/_index.scss | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/common/components/suggestion-list/_index.scss b/src/common/components/suggestion-list/_index.scss index a7dcaa3320f..11003543997 100644 --- a/src/common/components/suggestion-list/_index.scss +++ b/src/common/components/suggestion-list/_index.scss @@ -72,7 +72,6 @@ &:hover, &:focus { - background: $metallic-blue; color: $white; } } @@ -143,7 +142,6 @@ display: flex; align-items: center; white-space: nowrap; - width: 20px; &:last-child { border-bottom-left-radius: $border-radius; @@ -165,7 +163,6 @@ &:hover, &:focus { - background: $metallic-blue; color: $white; } } From 6f60efb83f6434547844a6fd1e5fc9579a394f14 Mon Sep 17 00:00:00 2001 From: Talha Saeed Date: Thu, 12 Oct 2023 16:59:01 +0500 Subject: [PATCH 5/5] Change hive to HIVE in translation file --- src/common/i18n/locales/en-US.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/i18n/locales/en-US.json b/src/common/i18n/locales/en-US.json index 9e4649d7b44..4058949f5de 100644 --- a/src/common/i18n/locales/en-US.json +++ b/src/common/i18n/locales/en-US.json @@ -1222,7 +1222,7 @@ "memo-help": "This memo is public", "memo-error": "Never put private keys into a memo field, it is publicly visible to everyone.", "memo-required": "Transfer to an exchange must have a memo.", - "invalid-asset": "You can only send hive to an exchange account.", + "invalid-asset": "You can only send HIVE to an exchange account.", "available-hp-hint": "* available hive power", "override-warning-1": "The new amount overrides the previous one.", "override-warning-2": "Account ({{account}}) has already been delegated with {{previousAmount}}.",