Skip to content

Commit 9956a50

Browse files
committed
Additional changes after rebase
1 parent 5e0b69f commit 9956a50

File tree

5 files changed

+81
-78
lines changed

5 files changed

+81
-78
lines changed

libs/ledger-live-common/src/families/stacks/bridge/utils/utils.ts

+66-63
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import { Account, Address, Operation } from "@ledgerhq/types-live";
55
import {
66
makeUnsignedSTXTokenTransfer,
77
UnsignedTokenTransferOptions,
8-
createMessageSignature
8+
createMessageSignature,
99
} from "@stacks/transactions";
1010

1111
import {
1212
GetAccountShape,
13-
GetAccountShapeArg0
13+
AccountShapeInfo,
1414
} from "../../../../bridge/jsHelpers";
1515
import { decodeAccountId, encodeAccountId } from "../../../../account";
1616
import {
1717
fetchBalances,
1818
fetchBlockHeight,
19-
fetchFullTxs
19+
fetchFullTxs,
2020
} from "../../bridge/utils/api";
2121
import { StacksNetwork, TransactionResponse } from "./types";
2222
import { getCryptoCurrencyById } from "../../../../currencies";
@@ -30,7 +30,7 @@ export const getTxToBroadcast = async (
3030
value,
3131
recipients,
3232
fee,
33-
extra: { xpub, nonce, anchorMode, network, memo }
33+
extra: { xpub, nonce, anchorMode, network, memo },
3434
} = operation;
3535

3636
const options: UnsignedTokenTransferOptions = {
@@ -60,66 +60,69 @@ export const getAddress = (a: Account): Address =>
6060
? a.freshAddresses[0]
6161
: { address: a.freshAddress, derivationPath: a.freshAddressPath };
6262

63-
export const mapTxToOps = (accountID, { address }: GetAccountShapeArg0) => (
64-
tx: TransactionResponse
65-
): Operation[] => {
66-
const { sender, recipient, amount } = tx.stx_transfers[0];
67-
const { tx_id, fee_rate, block_height, burn_block_time, token_transfer } = tx.tx;
68-
const { memo: memoHex } = token_transfer;
69-
70-
const ops: Operation[] = [];
71-
72-
const date = new Date(burn_block_time * 1000);
73-
const value = new BigNumber(amount || "0");
74-
const feeToUse = new BigNumber(fee_rate || "0");
75-
76-
const isSending = address === sender;
77-
const isReceiving = address === recipient;
78-
79-
const memo = Buffer.from(memoHex.substring(2), "hex").toString().replaceAll("\x00", "")
80-
81-
if (isSending) {
82-
ops.push({
83-
id: encodeOperationId(accountID, tx_id, "OUT"),
84-
hash: tx_id,
85-
type: "OUT",
86-
value: value.plus(feeToUse),
87-
fee: feeToUse,
88-
blockHeight: block_height,
89-
blockHash: null,
90-
accountId: accountID,
91-
senders: [sender],
92-
recipients: [recipient],
93-
date,
94-
extra: {
95-
memo
96-
}
97-
});
98-
}
99-
100-
if (isReceiving) {
101-
ops.push({
102-
id: encodeOperationId(accountID, tx_id, "IN"),
103-
hash: tx_id,
104-
type: "IN",
105-
value,
106-
fee: feeToUse,
107-
blockHeight: block_height,
108-
blockHash: null,
109-
accountId: accountID,
110-
senders: [sender],
111-
recipients: [recipient],
112-
date,
113-
extra: {
114-
memo
115-
}
116-
});
117-
}
118-
119-
return ops;
120-
};
63+
export const mapTxToOps =
64+
(accountID, { address }: AccountShapeInfo) =>
65+
(tx: TransactionResponse): Operation[] => {
66+
const { sender, recipient, amount } = tx.stx_transfers[0];
67+
const { tx_id, fee_rate, block_height, burn_block_time, token_transfer } =
68+
tx.tx;
69+
const { memo: memoHex } = token_transfer;
70+
71+
const ops: Operation[] = [];
72+
73+
const date = new Date(burn_block_time * 1000);
74+
const value = new BigNumber(amount || "0");
75+
const feeToUse = new BigNumber(fee_rate || "0");
76+
77+
const isSending = address === sender;
78+
const isReceiving = address === recipient;
79+
80+
const memo = Buffer.from(memoHex.substring(2), "hex")
81+
.toString()
82+
.replaceAll("\x00", "");
83+
84+
if (isSending) {
85+
ops.push({
86+
id: encodeOperationId(accountID, tx_id, "OUT"),
87+
hash: tx_id,
88+
type: "OUT",
89+
value: value.plus(feeToUse),
90+
fee: feeToUse,
91+
blockHeight: block_height,
92+
blockHash: null,
93+
accountId: accountID,
94+
senders: [sender],
95+
recipients: [recipient],
96+
date,
97+
extra: {
98+
memo,
99+
},
100+
});
101+
}
102+
103+
if (isReceiving) {
104+
ops.push({
105+
id: encodeOperationId(accountID, tx_id, "IN"),
106+
hash: tx_id,
107+
type: "IN",
108+
value,
109+
fee: feeToUse,
110+
blockHeight: block_height,
111+
blockHash: null,
112+
accountId: accountID,
113+
senders: [sender],
114+
recipients: [recipient],
115+
date,
116+
extra: {
117+
memo,
118+
},
119+
});
120+
}
121+
122+
return ops;
123+
};
121124

122-
export const getAccountShape: GetAccountShape = async info => {
125+
export const getAccountShape: GetAccountShape = async (info) => {
123126
const { initialAccount, address, currency, rest = {}, derivationMode } = info;
124127

125128
const publicKey = reconciliatePublicKey(rest.publicKey, initialAccount);
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
import type { DeviceAction } from "../../bot/types";
22
import type { Transaction } from "./types";
3-
import { deviceActionFlow } from "../../bot/specs";
3+
import { deviceActionFlow, SpeculosButton } from "../../bot/specs";
44

55
export const acceptTransaction: DeviceAction<Transaction, any> =
66
deviceActionFlow({
77
steps: [
88
{
99
title: "Origin",
10-
button: "Rr",
10+
button: SpeculosButton.RIGHT,
1111
expectedValue: ({ account }) => account.freshAddress,
1212
},
1313
{
1414
title: "Nonce",
15-
button: "Rr",
15+
button: SpeculosButton.RIGHT,
1616
expectedValue: ({ transaction }) =>
1717
transaction.nonce ? transaction.nonce.toFixed() : "0",
1818
},
1919
{
2020
title: "Fee (uSTX)",
21-
button: "Rr",
21+
button: SpeculosButton.RIGHT,
2222
expectedValue: ({ transaction }) =>
2323
transaction.fee ? transaction.fee.toFixed() : "0",
2424
},
2525
{
2626
title: "Amount uSTX",
27-
button: "Rr",
27+
button: SpeculosButton.RIGHT,
2828
expectedValue: ({ status }) => status.amount.toFixed(),
2929
},
3030
{
3131
title: "To",
32-
button: "Rr",
32+
button: SpeculosButton.RIGHT,
3333
expectedValue: ({ transaction }) => transaction.recipient,
3434
},
3535
{
3636
title: "Memo",
37-
button: "Rr",
37+
button: SpeculosButton.RIGHT,
3838
expectedValue: ({ transaction }) => transaction.memo || "",
3939
},
4040
{
4141
title: "APPROVE",
42-
button: "LRlr",
42+
button: SpeculosButton.BOTH,
4343
},
4444
],
4545
});

libs/ledger-live-common/src/families/stacks/transaction.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
fromTransactionStatusRawCommon as fromTransactionStatusRaw,
1010
toTransactionCommonRaw,
1111
toTransactionStatusRawCommon as toTransactionStatusRaw,
12-
} from "../../transaction/common";
12+
} from "@ledgerhq/coin-framework/transaction/common";
1313
import { getAccountUnit } from "../../account";
1414
import { formatCurrencyUnit } from "../../currencies";
1515

@@ -34,7 +34,7 @@ export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
3434
const common = fromTransactionCommonRaw(tr);
3535

3636
// validate if network is valid
37-
if(!StacksNetwork[ tr.network ]){
37+
if (!StacksNetwork[tr.network]) {
3838
throw new Error(`network ${tr.network} not valid`);
3939
}
4040

libs/ledger-live-common/src/generated/account.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import crypto_org from "../families/crypto_org/account";
55
import elrond from "../families/elrond/account";
66
import filecoin from "../families/filecoin/account";
77
import near from "../families/near/account";
8-
import polkadot from "@ledgerhq/coin-polkadot/account";
98
import stacks from "../families/stacks/account";
9+
import polkadot from "@ledgerhq/coin-polkadot/account";
1010

1111
export default {
1212
algorand,
@@ -16,6 +16,6 @@ export default {
1616
elrond,
1717
filecoin,
1818
near,
19-
polkadot,
2019
stacks,
20+
polkadot,
2121
};

libs/ledger-live-common/src/generated/deviceTransactionConfig.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ export default {
4141
};
4242
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_cosmos } from "../families/cosmos/deviceTransactionConfig";
4343
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_filecoin } from "../families/filecoin/deviceTransactionConfig";
44-
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_polkadot } from "@ledgerhq/coin-polkadot/deviceTransactionConfig";
4544
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_stacks } from "../families/stacks/deviceTransactionConfig";
4645
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_stellar } from "../families/stellar/deviceTransactionConfig";
4746
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_tezos } from "../families/tezos/deviceTransactionConfig";
4847
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_tron } from "../families/tron/deviceTransactionConfig";
48+
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_polkadot } from "@ledgerhq/coin-polkadot/deviceTransactionConfig";
4949

5050
export type ExtraDeviceTransactionField =
5151
| ExtraDeviceTransactionField_cosmos
5252
| ExtraDeviceTransactionField_filecoin
53-
| ExtraDeviceTransactionField_polkadot
5453
| ExtraDeviceTransactionField_stacks
5554
| ExtraDeviceTransactionField_stellar
5655
| ExtraDeviceTransactionField_tezos
57-
| ExtraDeviceTransactionField_tron;
56+
| ExtraDeviceTransactionField_tron
57+
| ExtraDeviceTransactionField_polkadot;

0 commit comments

Comments
 (0)