Skip to content

Commit

Permalink
Feat/live 9560 polkadot reorg (#5882)
Browse files Browse the repository at this point in the history
* feat: move type into specific folder

Signed-off-by: Stéphane Prohaszka <[email protected]>

* feat: move js files to bridge dir

Signed-off-by: Stéphane Prohaszka <[email protected]>

* feat: create dedicated dir for e2e and integ tests

Signed-off-by: Stéphane Prohaszka <[email protected]>

* feat: move last files to dedicated dir

Signed-off-by: Stéphane Prohaszka <[email protected]>

* feat: choose export function from polkadot

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: error in import

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: restore import for polkadot

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: missing generated import

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: lighten polkadot test import

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: missing correct test import

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: unimported

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: still missing correct test import

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: remove extra path for errors access

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: rename api directory to network

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: separate logic from bridge specific WIP

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: separate formatting from serialization file

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: missing export

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: return early in serialization OperationExtra

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: remove platform-sdk file from polkadot module

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: some clean

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: format code

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: unecessary import

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: remove unused types in mobile

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: unimported

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: unimported

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: remove unused dependency

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: cosmos type error

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: review feedbacks

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: rename bridge.integration.test.ts

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: undo wrongly updated snapshot

Signed-off-by: Stéphane Prohaszka <[email protected]>

* chore: feedbacks

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: revert use of inferFamilyFromAccountId

Signed-off-by: Stéphane Prohaszka <[email protected]>

* fix: add missing export asked by ui

Signed-off-by: Stéphane Prohaszka <[email protected]>

---------

Signed-off-by: Stéphane Prohaszka <[email protected]>
  • Loading branch information
sprohaszka-ledger authored and jdabbech-ledger committed Feb 19, 2024
1 parent 94d5bd0 commit ad7f8f4
Show file tree
Hide file tree
Showing 99 changed files with 1,152 additions and 1,749 deletions.
4 changes: 2 additions & 2 deletions apps/ledger-live-mobile/src/components/Nft/NftViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import NftViewerBackground from "./NftViewerBackground";
import NftViewerScreenHeader from "./NftViewerScreenHeader";
import invariant from "invariant";
import DiscreetModeContext, { withDiscreetMode } from "~/context/DiscreetModeContext";
import { EvmNftTransaction, Transaction } from "@ledgerhq/coin-evm/types/index";
import { EvmNftTransaction } from "@ledgerhq/coin-evm/types/index";

type Props = CompositeScreenProps<
| StackNavigatorProps<NftNavigatorParamList, ScreenName.NftViewer>
Expand Down Expand Up @@ -207,7 +207,7 @@ const NftViewer = ({ route }: Props) => {
};

const goToRecipientSelection = useCallback(() => {
const bridge = getAccountBridge<Transaction>(account);
const bridge = getAccountBridge(account);

const defaultTransaction = bridge.createTransaction(account);
const transaction = bridge.updateTransaction(defaultTransaction, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Evm1559CustomFees = ({

// Creating a new transaction to simulate the bridge status response before updating
// the original transaction
const bridge = getAccountBridge<EvmTransactionEIP1559>(account);
const bridge = getAccountBridge(account);

const { transaction, setTransaction, status } = useBridgeTransaction<EvmTransactionEIP1559>(
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default function EvmFeesStrategy({

const onFeesSelected = useCallback(
({ feesStrategy }: { feesStrategy: StrategyWithCustom }) => {
const bridge = getAccountBridge<Transaction>(account, parentAccount);
const bridge = getAccountBridge(account, parentAccount);

const patch: Partial<Transaction> =
feesStrategy === "custom" && customStrategyTransactionPatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const NftRow = memo(({ account, nft }: { account: Account; nft: ProtoNFT }) => {
// Only evm family handles nft as of today. If later we have other family,
// we will need to rework the NFT send flow by implementing family specific
// logic under their "src/families" respective folder.
const bridge = getAccountBridge<EvmTransaction>(account);
const bridge = getAccountBridge(account);

const defaultTransaction = bridge.createTransaction(account);

Expand Down
1 change: 1 addition & 0 deletions libs/coin-algorand/.unimportedrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"src/cli-transaction.ts",
"src/deviceTransactionConfig.ts",
"src/errors.ts",
"src/formatters.ts",
"src/hw-getAddress.ts",
"src/initAccount.ts",
"src/mock.ts",
Expand Down
9 changes: 8 additions & 1 deletion libs/coin-algorand/src/bridge/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import { getTransactionStatus } from "../js-getTransactionStatus";
import prepareTransaction from "../js-prepareTransaction";
import { buildSignOperation } from "../js-signOperation";
import { makeGetAccountShape } from "../js-synchronization";
import { assignFromAccountRaw, assignToAccountRaw } from "../serialization";
import {
assignFromAccountRaw,
assignToAccountRaw,
fromOperationExtraRaw,
toOperationExtraRaw,
} from "../serialization";
import type { Transaction } from "../types";
import { AlgorandAddress, AlgorandSignature, AlgorandSigner } from "../signer";

Expand Down Expand Up @@ -68,6 +73,8 @@ export function buildAccountBridge(
signOperation,
broadcast: broadcast(algorandAPI),
estimateMaxSpendable: estimateMaxSpendable(algorandAPI),
fromOperationExtraRaw,
toOperationExtraRaw,
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { getAccountUnit } from "@ledgerhq/coin-framework/account/index";
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
import type { Unit } from "@ledgerhq/types-cryptoassets";
import { BigNumber } from "bignumber.js";
import invariant from "invariant";
import type {
AlgorandAccount,
AlgorandOperation,
AlgorandOperationExtra,
AlgorandOperationExtraRaw,
} from "./types";
import type { AlgorandAccount, AlgorandOperation } from "./types";

function formatOperationSpecifics(op: AlgorandOperation, unit: Unit | null | undefined): string {
const { rewards } = op.extra;
Expand Down Expand Up @@ -43,43 +37,7 @@ function formatAccountSpecifics(account: AlgorandAccount): string {
return str;
}

export function fromOperationExtraRaw(extraRaw: AlgorandOperationExtraRaw) {
const extra: AlgorandOperationExtra = {};
if (extraRaw.rewards) {
extra.rewards = new BigNumber(extraRaw.rewards);
}

if (extraRaw.memo) {
extra.memo = extraRaw.memo;
}

if (extraRaw.assetId) {
extra.assetId = extraRaw.assetId;
}

return extra;
}

export function toOperationExtraRaw(extra: AlgorandOperationExtra) {
const extraRaw: AlgorandOperationExtraRaw = {};
if (extra.rewards) {
extraRaw.rewards = extra.rewards.toString();
}

if (extra.memo) {
extraRaw.memo = extra.memo;
}

if (extra.assetId) {
extraRaw.assetId = extra.assetId;
}

return extraRaw;
}

export default {
formatAccountSpecifics,
formatOperationSpecifics,
fromOperationExtraRaw,
toOperationExtraRaw,
};
58 changes: 52 additions & 6 deletions libs/coin-algorand/src/serialization.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type { Account, AccountRaw } from "@ledgerhq/types-live";
import type { Account, AccountRaw, OperationExtra, OperationExtraRaw } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import type {
AlgorandAccount,
AlgorandAccountRaw,
AlgorandResources,
AlgorandResourcesRaw,
import {
isAlgorandOperationExtra,
isAlgorandOperationExtraRaw,
type AlgorandAccount,
type AlgorandAccountRaw,
type AlgorandOperationExtra,
type AlgorandOperationExtraRaw,
type AlgorandResources,
type AlgorandResourcesRaw,
} from "./types";

function toResourcesRaw(r: AlgorandResources): AlgorandResourcesRaw {
Expand Down Expand Up @@ -37,3 +41,45 @@ export function assignFromAccountRaw(accountRaw: AccountRaw, account: Account):
algorandAccount.algorandResources = fromResourcesRaw(algorandResourcesRaw);
}
}

export function fromOperationExtraRaw(extraRaw: OperationExtraRaw) {
const extra: AlgorandOperationExtra = {};
if (!isAlgorandOperationExtraRaw(extraRaw)) {
return extra;
}

if (extraRaw.rewards) {
extra.rewards = new BigNumber(extraRaw.rewards);
}

if (extraRaw.memo) {
extra.memo = extraRaw.memo;
}

if (extraRaw.assetId) {
extra.assetId = extraRaw.assetId;
}

return extra;
}

export function toOperationExtraRaw(extra: OperationExtra) {
const extraRaw: AlgorandOperationExtraRaw = {};
if (!isAlgorandOperationExtra(extra)) {
return extraRaw;
}

if (extra.rewards) {
extraRaw.rewards = extra.rewards.toString();
}

if (extra.memo) {
extraRaw.memo = extra.memo;
}

if (extra.assetId) {
extraRaw.assetId = extra.assetId;
}

return extraRaw;
}
15 changes: 15 additions & 0 deletions libs/coin-algorand/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type {
Account,
AccountRaw,
Operation,
OperationExtra,
OperationExtraRaw,
OperationRaw,
TransactionCommon,
TransactionCommonRaw,
Expand Down Expand Up @@ -55,11 +57,24 @@ export type AlgorandOperationExtra = {
memo?: string;
assetId?: string;
};
export function isAlgorandOperationExtra(op: OperationExtra): op is AlgorandOperationExtra {
return (
op !== null && typeof op === "object" && ("rewards" in op || "memo" in op || "assetId" in op)
);
}

export type AlgorandOperationExtraRaw = {
rewards?: string;
memo?: string;
assetId?: string;
};
export function isAlgorandOperationExtraRaw(
op: OperationExtraRaw,
): op is AlgorandOperationExtraRaw {
return (
op !== null && typeof op === "object" && ("rewards" in op || "memo" in op || "assetId" in op)
);
}

export type AlgorandAccount = Account & {
algorandResources: AlgorandResources;
Expand Down
22 changes: 9 additions & 13 deletions libs/coin-polkadot/.unimportedrc.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{
"entry": [
"src/account.ts",
"src/bridge/js.ts",
"src/cli-transaction.ts",
"src/deviceTransactionConfig.ts",
"src/errors.ts",
"src/hw-getAddress.ts",
"src/logic.ts",
"src/platformAdapter.ts",
"src/preload.ts",
"src/serialization.ts",
"src/specs.ts",
"src/transaction.ts"
"src/bridge/index.ts",
"src/bridge/deviceTransactionConfig.ts",
"src/bridge/formatters.ts",
"src/signer/index.ts",
"src/test/cli.ts",
"src/test/index.ts",
"src/test/specs.ts",
"src/types/errors.ts",
"src/index.ts"
],
"ignoreUnimported": ["src/api/subscan.ts", "src/api/websocket.ts"],
"ignoreUnresolved": []
}
46 changes: 44 additions & 2 deletions libs/coin-polkadot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,57 @@
"lib-es/*": [
"lib-es/*"
],
"logic": [
"lib/logic/index"
],
"specs": [
"lib/test/bot-specs"
],
"*": [
"lib/*"
"lib/*",
"lib/bridge/*",
"lib/logic/*",
"lib/signer/*",
"lib/test/*",
"lib/types/*"
]
}
},
"exports": {
"./lib/*": "./lib/*.js",
"./lib-es/*": "./lib-es/*.js",
"./deviceTransactionConfig": {
"require": "./lib/bridge/deviceTransactionConfig.js",
"default": "./lib-es/bridge/deviceTransactionConfig.js"
},
"./errors": {
"require": "./lib/types/errors.js",
"default": "./lib-es/types/errors.js"
},
"./formatters": {
"require": "./lib/bridge/formatters.js",
"default": "./lib-es/bridge/formatters.js"
},
"./logic": {
"require": "./lib/logic/index.js",
"default": "./lib-es/logic/index.js"
},
"./preload": {
"require": "./lib/bridge/preload.js",
"default": "./lib-es/bridge/preload.js"
},
"./serialization": {
"require": "./lib/bridge/serialization.js",
"default": "./lib-es/bridge/serialization.js"
},
"./specs": {
"require": "./lib/test/bot-specs.js",
"default": "./lib-es/test/bot-specs.js"
},
"./transaction": {
"require": "./lib/bridge/transaction.js",
"default": "./lib-es/bridge/transaction.js"
},
"./*": {
"require": "./lib/*.js",
"default": "./lib-es/*.js"
Expand All @@ -48,7 +91,6 @@
"@ledgerhq/cryptoassets": "workspace:^",
"@ledgerhq/devices": "workspace:^",
"@ledgerhq/errors": "workspace:^",
"@ledgerhq/live-app-sdk": "^0.8.1",
"@ledgerhq/live-env": "workspace:^",
"@ledgerhq/logs": "workspace:^",
"@ledgerhq/types-cryptoassets": "workspace:^",
Expand Down
Loading

0 comments on commit ad7f8f4

Please sign in to comment.