Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not show actions for untrusted regulated assets #194

Merged
merged 2 commits into from
Jun 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 78 additions & 65 deletions src/components/BalanceRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,82 @@ export const BalanceRow = ({
}
};

const renderActionsSelect = () => {
if (onAction) {
// Regulated asset needs to be trusted first
if (isUntrusted && asset.supportedActions?.sep8) {
return null;
}
Comment on lines +60 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the SEPs to be available before adding a trustline to a non-regulated asset?

I'm wondering if this change is desired only for regulated assets or if for all assets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some SEPs that can work without a trustline (it is created during deposit, for example). If SEP-8 is not supported for that asset, we would show everything as it was before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it. Now I can see SEP-6 and SEP-24 actions are supported when there's no trustline: https://stellar-demo-wallet-pr194.previews.kube001.services.stellar-ops.com/account?secretKey=SCIAIFDX7QYORHOWZNNU24DXQXTNP2AABHGNRJ5WPZ6AC6VXXR3VCTHT&untrustedAssets=MULT%3AGDLD3SOLYJTBEAK5IU4LDS44UMBND262IXPJB3LDHXOZ3S2QQRD5FSMM

I think this behaviour should remain the same across SEP-8 and non-SEP-8 assets. There could be an anchor implementing SEP-6, SEP-24 and SEP-8 for the same asset. If that's the case, we should still show the dropdown with SEP-6 and SEP-24 for that asset even if that's a regulated asset (SEP-8), right?

I think the only change we need is to add the !isUntrusted && condition before rendering the SEP-8 send option, i.e. update:

            {asset.supportedActions?.sep8 && (
              <option value={AssetActionId.SEP8_SEND_PAYMENT}>
                SEP-8 Send
              </option>
            )}

to

            {!isUntrusted && asset.supportedActions?.sep8 && (
              <option value={AssetActionId.SEP8_SEND_PAYMENT}>
                SEP-8 Send
              </option>
            )}

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Sure, we can add that for clarity. Line 60 check should prevent it from being an untrusted asset for SEP-8 at that point, I think.


return (
<div className="BalanceCellSelect">
<Select
id={`${assetString}-actions`}
onChange={handleSelectChange}
disabled={disabled}
value={selectValue}
>
<option value="">Select action</option>
{!isUntrusted && !asset.supportedActions?.sep8 && (
<option value={AssetActionId.SEND_PAYMENT}>Send payment</option>
)}

{supportedActions?.sep6 && (
<>
<option value={AssetActionId.SEP6_DEPOSIT}>
SEP-6 Deposit
</option>
{!isUntrusted && (
<option value={AssetActionId.SEP6_WITHDRAW}>
SEP-6 Withdraw
</option>
)}
</>
)}

{asset.supportedActions?.sep8 && (
<option value={AssetActionId.SEP8_SEND_PAYMENT}>
SEP-8 Send
</option>
)}

{supportedActions?.sep24 && (
<>
<option value={AssetActionId.SEP24_DEPOSIT}>
SEP-24 Deposit
</option>
{!isUntrusted && (
<option value={AssetActionId.SEP24_WITHDRAW}>
SEP-24 Withdraw
</option>
)}
</>
)}
{!isUntrusted && supportedActions?.sep31 && (
<option value={AssetActionId.SEP31_SEND}>SEP-31 Send</option>
)}
</Select>

<InfoButtonWithTooltip>
<>
{
"What you can do with an asset (deposit, withdraw, or send) depends on what transactions the anchor supports."
}{" "}
<TextLink
href="https://developers.stellar.org/docs/anchoring-assets"
isExternal
>
Learn more
</TextLink>
</>
</InfoButtonWithTooltip>
</div>
);
}

return null;
};

return (
<div
className={`BalanceRow Inset ${isActive ? "active" : ""} ${
Expand Down Expand Up @@ -102,78 +178,15 @@ export const BalanceRow = ({
>
SEP-8
</TextLink>
"."
.
</InfoButtonWithTooltip>
</div>
)}

<div className="BalanceCell BalanceActions">
{children && <div className="CustomCell">{children}</div>}

{onAction && (
<div className="BalanceCellSelect">
<Select
id={`${assetString}-actions`}
onChange={handleSelectChange}
disabled={disabled}
value={selectValue}
>
<option value="">Select action</option>
{!isUntrusted && !asset.supportedActions?.sep8 && (
<option value={AssetActionId.SEND_PAYMENT}>Send payment</option>
)}

{supportedActions?.sep6 && (
<>
<option value={AssetActionId.SEP6_DEPOSIT}>
SEP-6 Deposit
</option>
{!isUntrusted && (
<option value={AssetActionId.SEP6_WITHDRAW}>
SEP-6 Withdraw
</option>
)}
</>
)}

{asset.supportedActions?.sep8 && (
<option value={AssetActionId.SEP8_SEND_PAYMENT}>
SEP-8 Send
</option>
)}

{supportedActions?.sep24 && (
<>
<option value={AssetActionId.SEP24_DEPOSIT}>
SEP-24 Deposit
</option>
{!isUntrusted && (
<option value={AssetActionId.SEP24_WITHDRAW}>
SEP-24 Withdraw
</option>
)}
</>
)}
{!isUntrusted && supportedActions?.sep31 && (
<option value={AssetActionId.SEP31_SEND}>SEP-31 Send</option>
)}
</Select>

<InfoButtonWithTooltip>
<>
{
"What you can do with an asset (deposit, withdraw, or send) depends on what transactions the anchor supports."
}{" "}
<TextLink
href="https://developers.stellar.org/docs/anchoring-assets"
isExternal
>
Learn more
</TextLink>
</>
</InfoButtonWithTooltip>
</div>
)}
{renderActionsSelect()}
</div>
</div>
);
Expand Down