Skip to content

Commit

Permalink
lowercase identifier fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hedi-edelbloute committed Feb 22, 2024
1 parent efb09bc commit 884cfd6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilly-ducks-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ledgerhq/cryptoassets": patch
"@ledgerhq/live-common": patch
---

Updated CAL support
5 changes: 3 additions & 2 deletions libs/ledger-live-common/src/families/tron/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { makeLRUCache } from "@ledgerhq/live-network/cache";
import network from "@ledgerhq/live-network/network";
import { log } from "@ledgerhq/logs";
import { Account, SubAccount } from "@ledgerhq/types-live";
import { Account, SubAccount, TokenAccount } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import compact from "lodash/compact";
import drop from "lodash/drop";
Expand Down Expand Up @@ -203,11 +203,12 @@ export const createTronTransaction = async (

// trc20
if (tokenType === "trc20" && tokenId) {
const tokenContractAddress = (subAccount as TokenAccount).token.contractAddress;
const txData: SmartContractTransactionData = {
function_selector: "transfer(address,uint256)",
fee_limit: 50000000,
call_value: 0,
contract_address: decode58Check(tokenId),
contract_address: decode58Check(tokenContractAddress),
parameter: abiEncodeTrc20Transfer(decode58Check(t.recipient), t.amount),
owner_address: decode58Check(a.freshAddress),
};
Expand Down
53 changes: 35 additions & 18 deletions libs/ledger-live-common/src/families/tron/bridge/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import flatMap from "lodash/flatMap";
import compact from "lodash/compact";
import get from "lodash/get";
import sumBy from "lodash/sumBy";
import { findTokenById } from "@ledgerhq/cryptoassets";
import {
findTokenByAddress,
findTokenByAddressInCurrency,
findTokenById,
} from "@ledgerhq/cryptoassets";
import type {
Account,
Operation,
Expand Down Expand Up @@ -423,26 +427,40 @@ const getAccountShape = async (info: AccountShapeInfo, syncConfig) => {
const parentOperations: TronOperation[] = compact(
parentTxs.map(tx => txInfoToOperation(accountId, info.address, tx)),
);
const trc10Tokens = get(acc, "assetV2", []).map(({ key, value }) => ({
type: "trc10",
key,
value,
}));
const trc20Tokens = get(acc, "trc20", []).map(obj => {
const [[key, value]] = Object.entries(obj);
return {
type: "trc20",
key,
value,
};
});

const trc10Tokens = get(acc, "assetV2", []).reduce((accumulator, { key, value }) => {
const tokenInfo = findTokenById(`tron/trc10/${key}`);
if (tokenInfo) {
accumulator.push({
key,
type: "trc10",
tokenId: tokenInfo.id,
balance: value,
});
}
return accumulator;
}, []);

const trc20Tokens = get(acc, "trc20", []).reduce((accumulator, trc20) => {
const [[contractAddress, balance]] = Object.entries(trc20);
const tokenInfo = findTokenByAddressInCurrency(contractAddress, info.currency.id);
if (tokenInfo) {
accumulator.push({
key: contractAddress,
type: "trc20",
tokenId: tokenInfo.id,
balance,
});
}
return accumulator;
}, []);

// TRC10 and TRC20 accounts
// FIXME: this is bad for perf: we should reconciliate with potential existing data
// we need to KEEP REF as much as possible & use minimalOperationsBuilderSync
const subAccounts: SubAccount[] = compact(
trc10Tokens.concat(trc20Tokens).map(({ type, key, value }) => {
trc10Tokens.concat(trc20Tokens).map(({ key, tokenId, balance }) => {
const { blacklistedTokenIds = [] } = syncConfig;
const tokenId = `tron/${type}/${key}`;
const token = findTokenById(tokenId);
if (!token || blacklistedTokenIds.includes(tokenId)) return;
const id = encodeTokenAccountId(accountId, token);
Expand All @@ -452,14 +470,13 @@ const getAccountShape = async (info: AccountShapeInfo, syncConfig) => {
info.initialAccount &&
info.initialAccount.subAccounts &&
info.initialAccount.subAccounts.find(a => a.id === id);
const balance = new BigNumber(value);
const sub: TokenAccount = {
type: "TokenAccount",
id,
starred: false,
parentId: accountId,
token,
balance,
balance: new BigNumber(balance),
spendableBalance: balance,
operationsCount: operations.length,
operations,
Expand Down
4 changes: 2 additions & 2 deletions libs/ledgerjs/packages/cryptoassets/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ function convertStellarTokens([

return {
type: "TokenCurrency",
id: `stellar/asset/${assetCode}:${assetIssuer}`,
contractAddress: assetIssuer,
id: `stellar/asset/${assetCode.toUpperCase()}:${assetIssuer.toUpperCase()}`,
contractAddress: assetIssuer.toUpperCase(),
parentCurrency,
tokenType: assetType,
name,
Expand Down

0 comments on commit 884cfd6

Please sign in to comment.