-
Notifications
You must be signed in to change notification settings - Fork 364
/
Copy pathwalletApiAdapter.ts
72 lines (56 loc) · 2.01 KB
/
walletApiAdapter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import createTransaction from "@ledgerhq/coin-polkadot/bridge/createTransaction";
import { Transaction } from "@ledgerhq/coin-polkadot/types/index";
import { PolkadotTransaction as WalletAPIPolkadotTransaction } from "@ledgerhq/wallet-api-core";
import {
AreFeesProvided,
ConvertToLiveTransaction,
GetWalletAPITransactionSignFlowInfos,
} from "../../wallet-api/types";
const CAN_EDIT_FEES = true;
const areFeesProvided: AreFeesProvided<WalletAPIPolkadotTransaction> = tx => !!tx.fee;
const convertToLiveTransaction: ConvertToLiveTransaction<
WalletAPIPolkadotTransaction,
Transaction
> = ({ account, walletApiTransaction }) => {
const hasFeesProvided = areFeesProvided(walletApiTransaction);
const liveTx: Transaction = createTransaction(account);
if (walletApiTransaction.amount) {
liveTx.amount = walletApiTransaction.amount;
}
if (walletApiTransaction.recipient) {
liveTx.recipient = walletApiTransaction.recipient;
}
if (walletApiTransaction.mode) {
liveTx.mode = walletApiTransaction.mode;
}
if (walletApiTransaction.fee) {
liveTx.fees = walletApiTransaction.fee;
}
if (walletApiTransaction.era) {
liveTx.era = `${walletApiTransaction.era}`;
}
if (walletApiTransaction.rewardDestination) {
liveTx.rewardDestination = walletApiTransaction.rewardDestination;
}
if (walletApiTransaction.validators) {
liveTx.validators = walletApiTransaction.validators;
}
if (walletApiTransaction.numOfSlashingSpans) {
liveTx.numSlashingSpans = walletApiTransaction.numOfSlashingSpans;
}
if (hasFeesProvided) {
liveTx.feesStrategy = null;
}
return liveTx;
};
const getWalletAPITransactionSignFlowInfos: GetWalletAPITransactionSignFlowInfos<
WalletAPIPolkadotTransaction,
Transaction
> = ({ walletApiTransaction, account }) => {
return {
canEditFees: CAN_EDIT_FEES,
liveTx: convertToLiveTransaction({ walletApiTransaction, account }),
hasFeesProvided: areFeesProvided(walletApiTransaction),
};
};
export default { getWalletAPITransactionSignFlowInfos };