Skip to content

Commit

Permalink
fix(LIVE-10131): stop throwing new trc20 account error (#6877)
Browse files Browse the repository at this point in the history
* feat(LIVE-10131): support trc20 swaps

* feat(LIVE-10131): ci

* feat(LIVE-10131): don't throw error for ptx swap

* Revert "feat(LIVE-10131): don't throw error for ptx swap"

This reverts commit bd50dd2.

* feat(LIVE-10131): don't delete test case
  • Loading branch information
cng-ledger committed Jun 7, 2024
1 parent 7b006d1 commit 2a2de6d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changeset/rotten-dodos-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ledgerhq/live-common": patch
---

fix(LIVE-10131): ignore TronSendTrc20ToNewAccountForbidden during swap
fix(LIVE-10131): stop throwing new trc20 account error TronSendTrc20ToNewAccountForbidden during sign operation
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getSwapProvider } from "../providers";
import { convertToAppExchangePartnerKey } from "../providers";
import { CompleteExchangeStep, convertTransportError } from "../error";
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";
import { TronSendTrc20ToNewAccountForbidden } from "../../families/tron/errors";

const withDevicePromise = (deviceId, fn) =>
firstValueFrom(withDevice(deviceId)(transport => from(fn(transport))));
Expand Down Expand Up @@ -74,7 +75,10 @@ const completeExchange = (
);
if (unsubscribed) return;

const errorsKeys = Object.keys(errors);
const errorsKeys = Object.keys(errors).filter(item =>
[TronSendTrc20ToNewAccountForbidden.prototype.name].includes(item),
);

if (errorsKeys.length > 0) throw errors[errorsKeys[0]]; // throw the first error

currentStep = "SET_PARTNER_KEY";
Expand Down
6 changes: 5 additions & 1 deletion libs/ledger-live-common/src/exchange/swap/initSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { decodePayloadProtobuf } from "@ledgerhq/hw-app-exchange";
import { getSwapProvider } from "../providers";
import { convertToAppExchangePartnerKey } from "../providers";
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";
import { TronSendTrc20ToNewAccountForbidden } from "../../families/tron/errors";

const withDevicePromise = (deviceId, fn) =>
firstValueFrom(withDevice(deviceId)(transport => from(fn(transport))));
Expand Down Expand Up @@ -160,7 +161,10 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
transaction,
);
if (unsubscribed) return;
const errorsKeys = Object.keys(errors);

const errorsKeys = Object.keys(errors).filter(item =>
[TronSendTrc20ToNewAccountForbidden.prototype.name].includes(item),
);

if (errorsKeys.length > 0) {
throw errors[errorsKeys[0]]; // throw the first error
Expand Down
15 changes: 0 additions & 15 deletions libs/ledger-live-common/src/families/tron/signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { Observable } from "rxjs";
import BigNumber from "bignumber.js";
import { AccountBridge, TokenAccount } from "@ledgerhq/types-live";
import { buildOptimisticOperation } from "./buildOptimisticOperation";
import { TronSendTrc20ToNewAccountForbidden } from "./errors";
import signTransaction from "../../hw/signTransaction";
import { Transaction, TronAccount } from "./types";
import { withDevice } from "../../hw/deviceAccess";
import { getEstimatedFees } from "./logic";
import {
claimRewardTronTransaction,
createTronTransaction,
fetchTronAccount,
fetchTronContract,
freezeTronTransaction,
legacyUnfreezeTronTransaction,
Expand Down Expand Up @@ -43,19 +41,6 @@ export const signOperation: AccountBridge<Transaction, TronAccount>["signOperati
transaction.amount = balance; // force the amount to be the max
}

// send trc20 to a new account is forbidden by us (because it will not activate the account)
if (
transaction.recipient &&
transaction.mode === "send" &&
subAccount &&
subAccount.type === "TokenAccount" &&
subAccount.token.tokenType === "trc20" &&
!isContractAddressRecipient && // send trc20 to a smart contract is allowed
(await fetchTronAccount(transaction.recipient)).length === 0
) {
throw new TronSendTrc20ToNewAccountForbidden();
}

const {
raw_data_hex: rawDataHex,
raw_data: rawData,
Expand Down

0 comments on commit 2a2de6d

Please sign in to comment.