Skip to content

Commit

Permalink
Merge pull request #1444 from ecency/feat/restrict-hbd-to-exchange-ac…
Browse files Browse the repository at this point in the history
…count

Feat/restrict hbd to exchange account
  • Loading branch information
feruzm authored Oct 12, 2023
2 parents f2a617b + 6f60efb commit 0700af0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
3 changes: 0 additions & 3 deletions src/common/components/suggestion-list/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@

&:hover,
&:focus {
background: $metallic-blue;
color: $white;
}
}
Expand Down Expand Up @@ -143,7 +142,6 @@
display: flex;
align-items: center;
white-space: nowrap;
width: 20px;

&:last-child {
border-bottom-left-radius: $border-radius;
Expand All @@ -165,7 +163,6 @@

&:hover,
&:focus {
background: $metallic-blue;
color: $white;
}
}
Expand Down
55 changes: 28 additions & 27 deletions src/common/components/transfer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ interface State {
to: string;
toData: Account | null;
toError: string;
toExchangeError: string;
exchangeWarning: string;
memoError: string;
toWarning: string;
amount: string;
Expand Down Expand Up @@ -189,7 +189,7 @@ const pureState = (props: Props): State => {
to: props.to || _to,
toData: props.to ? { name: props.to } : _toData,
toError: "",
toExchangeError: "",
exchangeWarning: "",
memoError: "",
toWarning: "",
amount: props.amount || "0.001",
Expand Down Expand Up @@ -221,30 +221,38 @@ export class Transfer extends BaseComponent<Props, State> {
}

assetChanged = (asset: TransferAsset) => {
const { to, memo } = this.state;
this.stateSet({ asset }, () => {
this.checkAmount();
this.exchangeHandler(to, memo);
});
};

exchangeHandler = (to: string, memo: string) => {
const { asset } = this.state;

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<typeof FormControl & HTMLInputElement>) => {
const { value: to } = e.target;
const { memo } = 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, memo);
};

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: "" });
}
const { memo } = this.state;
this.exchangeHandler(to, memo);
};

amountChanged = (e: React.ChangeEvent<typeof FormControl & HTMLInputElement>): void => {
Expand All @@ -256,18 +264,11 @@ export class Transfer extends BaseComponent<Props, State> {

memoChanged = (e: React.ChangeEvent<typeof FormControl & HTMLInputElement>): 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, memo);
};

handleTo = () => {
Expand Down Expand Up @@ -431,15 +432,15 @@ export class Transfer extends BaseComponent<Props, State> {
};

canSubmit = () => {
const { toData, toError, amountError, memoError, inProgress, amount, toExchangeError } =
const { toData, toError, amountError, memoError, inProgress, amount, exchangeWarning } =
this.state;
return (
toData &&
!toExchangeError &&
!toError &&
!amountError &&
!memoError &&
!inProgress &&
!exchangeWarning &&
parseFloat(amount) > 0
);
};
Expand Down Expand Up @@ -677,7 +678,7 @@ export class Transfer extends BaseComponent<Props, State> {
asset,
to,
toError,
toExchangeError,
exchangeWarning,
toWarning,
amount,
amountError,
Expand Down Expand Up @@ -900,7 +901,7 @@ export class Transfer extends BaseComponent<Props, State> {
</Form.Group>
{toWarning && <FormText msg={toWarning} type="danger" />}
{toError && <FormText msg={toError} type="danger" />}
{toExchangeError && <FormText msg={toExchangeError} type="danger" />}
{exchangeWarning && <FormText msg={exchangeWarning} type="danger" />}
</>
)}

Expand Down
1 change: 1 addition & 0 deletions src/common/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,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}}.",
Expand Down

0 comments on commit 0700af0

Please sign in to comment.