@ledgerhq/live-common 27.0.1-next.0 → 27.1.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/lib/account/serialization.d.ts +2 -0
  2. package/lib/account/serialization.d.ts.map +1 -1
  3. package/lib/account/serialization.js +23 -8
  4. package/lib/account/serialization.js.map +1 -1
  5. package/lib/api/explorerConfig/index.js +1 -1
  6. package/lib/api/explorerConfig/index.js.map +1 -1
  7. package/lib/apps/support.d.ts.map +1 -1
  8. package/lib/apps/support.js +1 -0
  9. package/lib/apps/support.js.map +1 -1
  10. package/lib/families/celo/api/hubble.d.ts +6 -1
  11. package/lib/families/celo/api/hubble.d.ts.map +1 -1
  12. package/lib/families/celo/api/hubble.js +135 -13
  13. package/lib/families/celo/api/hubble.js.map +1 -1
  14. package/lib/families/celo/api/index.d.ts +1 -1
  15. package/lib/families/celo/api/index.d.ts.map +1 -1
  16. package/lib/families/celo/api/index.js +2 -1
  17. package/lib/families/celo/api/index.js.map +1 -1
  18. package/lib/families/celo/api/sdk.d.ts +22 -0
  19. package/lib/families/celo/api/sdk.d.ts.map +1 -1
  20. package/lib/families/celo/api/sdk.js +168 -1
  21. package/lib/families/celo/api/sdk.js.map +1 -1
  22. package/lib/families/celo/bridge/js.d.ts.map +1 -1
  23. package/lib/families/celo/bridge/js.js +4 -42
  24. package/lib/families/celo/bridge/js.js.map +1 -1
  25. package/lib/families/celo/cli-transaction.d.ts +12 -2
  26. package/lib/families/celo/cli-transaction.d.ts.map +1 -1
  27. package/lib/families/celo/cli-transaction.js +38 -4
  28. package/lib/families/celo/cli-transaction.js.map +1 -1
  29. package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts +1 -0
  30. package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts.map +1 -1
  31. package/lib/families/celo/datasets/celo.scanAccounts.1.js +298 -2
  32. package/lib/families/celo/datasets/celo.scanAccounts.1.js.map +1 -1
  33. package/lib/families/celo/errors.d.ts +2 -0
  34. package/lib/families/celo/errors.d.ts.map +1 -0
  35. package/lib/families/celo/errors.js +6 -0
  36. package/lib/families/celo/errors.js.map +1 -0
  37. package/lib/families/celo/js-buildTransaction.d.ts +2 -3
  38. package/lib/families/celo/js-buildTransaction.d.ts.map +1 -1
  39. package/lib/families/celo/js-buildTransaction.js +194 -19
  40. package/lib/families/celo/js-buildTransaction.js.map +1 -1
  41. package/lib/families/celo/js-createTransaction.d.ts.map +1 -1
  42. package/lib/families/celo/js-createTransaction.js +3 -1
  43. package/lib/families/celo/js-createTransaction.js.map +1 -1
  44. package/lib/families/celo/js-estimateMaxSpendable.d.ts.map +1 -1
  45. package/lib/families/celo/js-estimateMaxSpendable.js.map +1 -1
  46. package/lib/families/celo/js-getFeesForTransaction.d.ts +2 -3
  47. package/lib/families/celo/js-getFeesForTransaction.d.ts.map +1 -1
  48. package/lib/families/celo/js-getFeesForTransaction.js +137 -10
  49. package/lib/families/celo/js-getFeesForTransaction.js.map +1 -1
  50. package/lib/families/celo/js-getTransactionStatus.d.ts +2 -3
  51. package/lib/families/celo/js-getTransactionStatus.d.ts.map +1 -1
  52. package/lib/families/celo/js-getTransactionStatus.js +97 -41
  53. package/lib/families/celo/js-getTransactionStatus.js.map +1 -1
  54. package/lib/families/celo/js-prepareTransaction.d.ts +2 -3
  55. package/lib/families/celo/js-prepareTransaction.d.ts.map +1 -1
  56. package/lib/families/celo/js-prepareTransaction.js +8 -3
  57. package/lib/families/celo/js-prepareTransaction.js.map +1 -1
  58. package/lib/families/celo/js-signOperation.d.ts.map +1 -1
  59. package/lib/families/celo/js-signOperation.js +17 -3
  60. package/lib/families/celo/js-signOperation.js.map +1 -1
  61. package/lib/families/celo/js-synchronisation.d.ts.map +1 -1
  62. package/lib/families/celo/js-synchronisation.js +51 -6
  63. package/lib/families/celo/js-synchronisation.js.map +1 -1
  64. package/lib/families/celo/logic.d.ts +21 -0
  65. package/lib/families/celo/logic.d.ts.map +1 -0
  66. package/lib/families/celo/logic.js +132 -0
  67. package/lib/families/celo/logic.js.map +1 -0
  68. package/lib/families/celo/preload.d.ts +10 -0
  69. package/lib/families/celo/preload.d.ts.map +1 -0
  70. package/lib/families/celo/preload.js +118 -0
  71. package/lib/families/celo/preload.js.map +1 -0
  72. package/lib/families/celo/react.d.ts +4 -0
  73. package/lib/families/celo/react.d.ts.map +1 -0
  74. package/lib/families/celo/react.js +47 -0
  75. package/lib/families/celo/react.js.map +1 -0
  76. package/lib/families/celo/serialization.d.ts +4 -0
  77. package/lib/families/celo/serialization.d.ts.map +1 -0
  78. package/lib/families/celo/serialization.js +55 -0
  79. package/lib/families/celo/serialization.js.map +1 -0
  80. package/lib/families/celo/specs/createActivateVoteMutation.d.ts +4 -0
  81. package/lib/families/celo/specs/createActivateVoteMutation.d.ts.map +1 -0
  82. package/lib/families/celo/specs/createActivateVoteMutation.js +38 -0
  83. package/lib/families/celo/specs/createActivateVoteMutation.js.map +1 -0
  84. package/lib/families/celo/specs/createLockMutation.d.ts +4 -0
  85. package/lib/families/celo/specs/createLockMutation.d.ts.map +1 -0
  86. package/lib/families/celo/specs/createLockMutation.js +40 -0
  87. package/lib/families/celo/specs/createLockMutation.js.map +1 -0
  88. package/lib/families/celo/specs/createRegisterAccountMutation.d.ts +4 -0
  89. package/lib/families/celo/specs/createRegisterAccountMutation.d.ts.map +1 -0
  90. package/lib/families/celo/specs/createRegisterAccountMutation.js +31 -0
  91. package/lib/families/celo/specs/createRegisterAccountMutation.js.map +1 -0
  92. package/lib/families/celo/specs/createRevokeVoteMutation.d.ts +4 -0
  93. package/lib/families/celo/specs/createRevokeVoteMutation.d.ts.map +1 -0
  94. package/lib/families/celo/specs/createRevokeVoteMutation.js +39 -0
  95. package/lib/families/celo/specs/createRevokeVoteMutation.js.map +1 -0
  96. package/lib/families/celo/specs/createSendMutation.d.ts +5 -0
  97. package/lib/families/celo/specs/createSendMutation.d.ts.map +1 -0
  98. package/lib/families/celo/specs/createSendMutation.js +44 -0
  99. package/lib/families/celo/specs/createSendMutation.js.map +1 -0
  100. package/lib/families/celo/specs/createUnlockMutation.d.ts +4 -0
  101. package/lib/families/celo/specs/createUnlockMutation.d.ts.map +1 -0
  102. package/lib/families/celo/specs/createUnlockMutation.js +37 -0
  103. package/lib/families/celo/specs/createUnlockMutation.js.map +1 -0
  104. package/lib/families/celo/specs/createVoteMutation.d.ts +4 -0
  105. package/lib/families/celo/specs/createVoteMutation.d.ts.map +1 -0
  106. package/lib/families/celo/specs/createVoteMutation.js +51 -0
  107. package/lib/families/celo/specs/createVoteMutation.js.map +1 -0
  108. package/lib/families/celo/specs/createWithdrawMutation.d.ts +4 -0
  109. package/lib/families/celo/specs/createWithdrawMutation.d.ts.map +1 -0
  110. package/lib/families/celo/specs/createWithdrawMutation.js +36 -0
  111. package/lib/families/celo/specs/createWithdrawMutation.js.map +1 -0
  112. package/lib/families/celo/specs/index.d.ts +9 -0
  113. package/lib/families/celo/specs/index.d.ts.map +1 -0
  114. package/lib/families/celo/specs/index.js +25 -0
  115. package/lib/families/celo/specs/index.js.map +1 -0
  116. package/lib/families/celo/specs.d.ts +1 -1
  117. package/lib/families/celo/specs.d.ts.map +1 -1
  118. package/lib/families/celo/specs.js +20 -37
  119. package/lib/families/celo/specs.js.map +1 -1
  120. package/lib/families/celo/speculos-deviceActions.d.ts.map +1 -1
  121. package/lib/families/celo/speculos-deviceActions.js +22 -0
  122. package/lib/families/celo/speculos-deviceActions.js.map +1 -1
  123. package/lib/families/celo/transaction.d.ts.map +1 -1
  124. package/lib/families/celo/transaction.js +8 -6
  125. package/lib/families/celo/transaction.js.map +1 -1
  126. package/lib/families/celo/types.d.ts +102 -1
  127. package/lib/families/celo/types.d.ts.map +1 -1
  128. package/lib/families/celo/validators.d.ts +3 -0
  129. package/lib/families/celo/validators.d.ts.map +1 -0
  130. package/lib/families/celo/validators.js +6 -0
  131. package/lib/families/celo/validators.js.map +1 -0
  132. package/lib/families/cosmos/banner.d.ts +10 -0
  133. package/lib/families/cosmos/banner.d.ts.map +1 -0
  134. package/lib/families/cosmos/banner.js +133 -0
  135. package/lib/families/cosmos/banner.js.map +1 -0
  136. package/lib/families/cosmos/banner.test.d.ts +2 -0
  137. package/lib/families/cosmos/banner.test.d.ts.map +1 -0
  138. package/lib/families/cosmos/banner.test.js +233 -0
  139. package/lib/families/cosmos/banner.test.js.map +1 -0
  140. package/lib/families/solana/api/chain/instruction/token/types.d.ts +2 -2
  141. package/lib/generated/cli-transaction.d.ts +12 -2
  142. package/lib/generated/cli-transaction.d.ts.map +1 -1
  143. package/lib/operation.d.ts.map +1 -1
  144. package/lib/operation.js +6 -0
  145. package/lib/operation.js.map +1 -1
  146. package/lib/reconciliation.d.ts.map +1 -1
  147. package/lib/reconciliation.js +11 -0
  148. package/lib/reconciliation.js.map +1 -1
  149. package/package.json +3 -4
  150. package/src/account/serialization.ts +22 -2
  151. package/src/api/explorerConfig/index.ts +1 -1
  152. package/src/apps/support.ts +1 -0
  153. package/src/families/celo/__snapshots__/bridge.integration.test.ts.snap +134 -857
  154. package/src/families/celo/api/hubble.ts +113 -16
  155. package/src/families/celo/api/index.ts +1 -1
  156. package/src/families/celo/api/sdk.ts +88 -0
  157. package/src/families/celo/bridge/js.ts +2 -3
  158. package/src/families/celo/cli-transaction.ts +46 -2
  159. package/src/families/celo/datasets/celo.scanAccounts.1.ts +365 -5
  160. package/src/families/celo/errors.ts +5 -0
  161. package/src/families/celo/js-buildTransaction.ts +173 -20
  162. package/src/families/celo/js-createTransaction.ts +2 -0
  163. package/src/families/celo/js-estimateMaxSpendable.ts +2 -2
  164. package/src/families/celo/js-getFeesForTransaction.ts +118 -19
  165. package/src/families/celo/js-getTransactionStatus.ts +72 -17
  166. package/src/families/celo/js-prepareTransaction.ts +13 -7
  167. package/src/families/celo/js-signOperation.ts +22 -5
  168. package/src/families/celo/js-synchronisation.ts +32 -0
  169. package/src/families/celo/logic.ts +184 -0
  170. package/src/families/celo/preload.ts +78 -0
  171. package/src/families/celo/react.ts +35 -0
  172. package/src/families/celo/serialization.ts +61 -0
  173. package/src/families/celo/specs/createActivateVoteMutation.ts +44 -0
  174. package/src/families/celo/specs/createLockMutation.ts +46 -0
  175. package/src/families/celo/specs/createRegisterAccountMutation.ts +34 -0
  176. package/src/families/celo/specs/createRevokeVoteMutation.ts +43 -0
  177. package/src/families/celo/specs/createSendMutation.ts +44 -0
  178. package/src/families/celo/specs/createUnlockMutation.ts +44 -0
  179. package/src/families/celo/specs/createVoteMutation.ts +67 -0
  180. package/src/families/celo/specs/createWithdrawMutation.ts +44 -0
  181. package/src/families/celo/specs/index.ts +8 -0
  182. package/src/families/celo/specs.ts +32 -34
  183. package/src/families/celo/speculos-deviceActions.ts +21 -2
  184. package/src/families/celo/transaction.ts +12 -4
  185. package/src/families/celo/types.ts +113 -0
  186. package/src/families/celo/validators.ts +2 -0
  187. package/src/families/cosmos/banner.test.ts +160 -0
  188. package/src/families/cosmos/banner.ts +87 -0
  189. package/src/operation.ts +6 -0
  190. package/src/reconciliation.ts +22 -0
@@ -11,10 +11,14 @@ import { getAccountUnit } from "../../account";
11
11
  import { formatCurrencyUnit } from "../../currencies";
12
12
  import { Account } from "@ledgerhq/types-live";
13
13
  export const formatTransaction = (t: Transaction, account: Account): string => `
14
- SEND ${formatCurrencyUnit(getAccountUnit(account), t.amount, {
15
- showCode: true,
16
- disableRounding: true,
17
- })}
14
+ SEND ${
15
+ t.useAllAmount
16
+ ? "MAX CELO"
17
+ : formatCurrencyUnit(getAccountUnit(account), t.amount, {
18
+ showCode: true,
19
+ disableRounding: true,
20
+ })
21
+ }
18
22
  TO ${t.recipient}`;
19
23
 
20
24
  const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
@@ -23,6 +27,8 @@ const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
23
27
  ...common,
24
28
  family: tr.family,
25
29
  fees: tr.fees ? new BigNumber(tr.fees) : null,
30
+ mode: tr.mode,
31
+ index: tr.index,
26
32
  };
27
33
  };
28
34
 
@@ -32,6 +38,8 @@ export const toTransactionRaw = (t: Transaction): TransactionRaw => {
32
38
  ...common,
33
39
  family: t.family,
34
40
  fees: t.fees?.toString() || null,
41
+ mode: t.mode,
42
+ index: t.index,
35
43
  };
36
44
  };
37
45
 
@@ -1,4 +1,6 @@
1
1
  import type {
2
+ Account,
3
+ AccountRaw,
2
4
  TransactionCommon,
3
5
  TransactionCommonRaw,
4
6
  TransactionStatusCommon,
@@ -6,15 +8,126 @@ import type {
6
8
  } from "@ledgerhq/types-live";
7
9
  import { BigNumber } from "bignumber.js";
8
10
 
11
+ export type CeloOperationMode =
12
+ | "send"
13
+ | "lock"
14
+ | "unlock"
15
+ | "withdraw"
16
+ | "vote"
17
+ | "revoke"
18
+ | "activate"
19
+ | "register";
20
+
21
+ export type CeloVoteType = "pending" | "active";
22
+ export type CeloVoteStatus = CeloVoteType | "awaitingActivation";
23
+
24
+ export type CeloPendingWithdrawal = {
25
+ value: BigNumber;
26
+ time: BigNumber;
27
+ index: number;
28
+ };
29
+ export type CeloPendingWithdrawalRaw = {
30
+ value: string;
31
+ time: string;
32
+ index: string;
33
+ };
34
+ export type CeloResources = {
35
+ registrationStatus: boolean;
36
+ lockedBalance: BigNumber;
37
+ nonvotingLockedBalance: BigNumber;
38
+ pendingWithdrawals: CeloPendingWithdrawal[] | null | undefined;
39
+ votes: CeloVote[] | null | undefined;
40
+ electionAddress: string | null | undefined;
41
+ lockedGoldAddress: string | null | undefined;
42
+ maxNumGroupsVotedFor: BigNumber;
43
+ };
44
+ export type CeloResourcesRaw = {
45
+ registrationStatus: boolean;
46
+ lockedBalance: string;
47
+ nonvotingLockedBalance: string;
48
+ pendingWithdrawals: CeloPendingWithdrawalRaw[] | null | undefined;
49
+ votes: CeloVoteRaw[] | null | undefined;
50
+ electionAddress: string | null | undefined;
51
+ lockedGoldAddress: string | null | undefined;
52
+ maxNumGroupsVotedFor: string;
53
+ };
9
54
  export type Transaction = TransactionCommon & {
10
55
  family: "celo";
11
56
  fees: BigNumber | null | undefined;
57
+ mode: CeloOperationMode;
58
+ index: number | null | undefined;
12
59
  };
13
60
  export type TransactionRaw = TransactionCommonRaw & {
14
61
  family: "celo";
15
62
  fees: string | null | undefined;
63
+ mode: CeloOperationMode;
64
+ index: number | null | undefined;
65
+ };
66
+ export type CeloValidatorGroup = {
67
+ address: string;
68
+ name: string;
69
+ votes: BigNumber;
70
+ };
71
+ export type CeloVote = {
72
+ validatorGroup: string;
73
+ amount: BigNumber;
74
+ activatable: boolean;
75
+ revokable: boolean;
76
+ type: CeloVoteType;
77
+ index: number;
78
+ };
79
+ export type CeloVoteRaw = {
80
+ validatorGroup: string;
81
+ amount: string;
82
+ activatable: boolean;
83
+ revokable: boolean;
84
+ type: CeloVoteType;
85
+ index: number;
86
+ };
87
+ export type FigmentIndexerTransaction = {
88
+ id: number;
89
+ height: number;
90
+ time: string;
91
+ transaction_hash: string;
92
+ address: string;
93
+ amount: number;
94
+ kind: string;
95
+ data?: {
96
+ Raw?: {
97
+ data: string;
98
+ topics: Array<string>;
99
+ address: string;
100
+ removed: boolean;
101
+ logIndex: string;
102
+ blockHash: string;
103
+ blockNumber: string;
104
+ transactionHash: string;
105
+ transactionIndex: string;
106
+ };
107
+ gas: number;
108
+ Account?: string;
109
+ Group?: string;
110
+ success?: boolean;
111
+ from?: string;
112
+ to?: string;
113
+ gas_used: number;
114
+ gas_price: number;
115
+ };
116
+ };
117
+
118
+ export type CeloPreloadData = {
119
+ validatorGroups: CeloValidatorGroup[];
16
120
  };
17
121
 
18
122
  export type TransactionStatus = TransactionStatusCommon;
19
123
 
20
124
  export type TransactionStatusRaw = TransactionStatusCommonRaw;
125
+
126
+ export type CeloAccount = Account & { celoResources: CeloResources };
127
+
128
+ export type CeloAccountRaw = AccountRaw & { celoResources: CeloResourcesRaw };
129
+
130
+ export type PendingStakingOperationAmounts = {
131
+ vote: BigNumber;
132
+ lock: BigNumber;
133
+ };
@@ -0,0 +1,2 @@
1
+ import { getValidatorGroups } from "./api";
2
+ export { getValidatorGroups };
@@ -0,0 +1,160 @@
1
+ import { getAccountBannerState } from "./banner";
2
+ import * as preloadedData from "./preloadedData";
3
+ import * as bridge from "../../bridge";
4
+ import type { CosmosAccount, CosmosValidatorItem } from "./types";
5
+ import data from "./preloadedData.mock";
6
+ import { LEDGER_VALIDATOR_ADDRESS } from "./utils";
7
+ import { BigNumber } from "bignumber.js";
8
+
9
+ const ledgerValidator: CosmosValidatorItem | undefined = data.validators.find(
10
+ (x) => x.validatorAddress === LEDGER_VALIDATOR_ADDRESS
11
+ );
12
+ const expensiveValidator: CosmosValidatorItem | undefined =
13
+ data.validators.find(
14
+ (x) =>
15
+ x.validatorAddress ===
16
+ "cosmosvaloper1qs8tnw2t8l6amtzvdemnnsq9dzk0ag0z52uzay"
17
+ );
18
+ const cheapValidator: CosmosValidatorItem | undefined = data.validators.find(
19
+ (x) =>
20
+ x.validatorAddress ===
21
+ "cosmosvaloper1qaa9zej9a0ge3ugpx3pxyx602lxh3ztqgfnp42"
22
+ );
23
+
24
+ const account: CosmosAccount = {
25
+ type: "Account",
26
+ id: "js:2:cosmos:cosmos1f9y7wdychcdhwvyrhff3zvs3gy3qxcu2th4g8u:",
27
+ starred: false,
28
+ used: false,
29
+ seedIdentifier:
30
+ "02d4c121ce2bb160ebf39aa0be0050b4d553e18872985ac3a4e21904fd1442defe",
31
+ derivationMode: "",
32
+ index: 1,
33
+ freshAddress: "cosmos1f9y7wdychcdhwvyrhff3zvs3gy3qxcu2th4g8u",
34
+ freshAddressPath: "44'/118'/1'/0/0",
35
+ name: "Cosmos 2 - Nano X Static Account",
36
+ freshAddresses: [],
37
+ blockHeight: 5417472,
38
+ creationDate: new Date("2022-08-02T16:09:08.906Z"),
39
+ balance: new BigNumber("200250"),
40
+ spendableBalance: new BigNumber("200250"),
41
+ operations: [],
42
+ operationsCount: 1,
43
+ pendingOperations: [],
44
+ unit: { name: "Atom", code: "ATOM", magnitude: 6 },
45
+ currency: {
46
+ type: "CryptoCurrency",
47
+ id: "cosmos",
48
+ coinType: 118,
49
+ name: "Cosmos",
50
+ managerAppName: "Cosmos",
51
+ ticker: "ATOM",
52
+ scheme: "cosmos",
53
+ color: "#16192f",
54
+ family: "cosmos",
55
+ units: [
56
+ { name: "Atom", code: "ATOM", magnitude: 6 },
57
+ { name: "microAtom", code: "uatom", magnitude: 0 },
58
+ ],
59
+ explorerViews: [
60
+ {
61
+ tx: "https://www.mintscan.io/cosmos/txs/$hash",
62
+ address: "https://www.mintscan.io/cosmos/validators/$address",
63
+ },
64
+ ],
65
+ },
66
+ lastSyncDate: new Date("2022-08-02T16:11:47.343Z"),
67
+ swapHistory: [],
68
+ balanceHistoryCache: {
69
+ HOUR: { balances: [0, 393248, 393248], latestDate: 1661162400000 },
70
+ DAY: { balances: [0, 393248], latestDate: 1661122800000 },
71
+ WEEK: { balances: [0, 393248], latestDate: 1661036400000 },
72
+ },
73
+ xpub: "cosmos1f9y7wdychcdhwvyrhff3zvs3gy3qxcu2th4g8u",
74
+ cosmosResources: {
75
+ delegations: [
76
+ {
77
+ amount: new BigNumber("50000"),
78
+ status: "bonded",
79
+ pendingRewards: new BigNumber("112"),
80
+ validatorAddress:
81
+ "cosmosvaloper1c4k24jzduc365kywrsvf5ujz4ya6mwympnc4en",
82
+ },
83
+ ],
84
+ redelegations: [],
85
+ unbondings: [],
86
+ delegatedBalance: new BigNumber("0"),
87
+ pendingRewardsBalance: new BigNumber("0"),
88
+ unbondingBalance: new BigNumber("0"),
89
+ withdrawAddress: "",
90
+ },
91
+ };
92
+
93
+ const validators = [expensiveValidator, cheapValidator, ledgerValidator];
94
+
95
+ describe("cosmos/banner", () => {
96
+ describe("useCosmosFormattedDelegations", () => {
97
+ afterEach(() => {
98
+ jest.restoreAllMocks();
99
+ });
100
+ it("should not display the banner", async () => {
101
+ jest
102
+ .spyOn(preloadedData, "getCurrentCosmosPreloadData")
103
+ .mockReturnValue({ validators } as {
104
+ validators: CosmosValidatorItem[];
105
+ });
106
+
107
+ jest.spyOn(bridge, "getAccountBridge").mockReturnValue({
108
+ estimateMaxSpendable: () => Promise.resolve(new BigNumber(0)),
109
+ } as any);
110
+ const result = await getAccountBannerState(account);
111
+ expect(1 + 1).toBe(2);
112
+ expect(result).toStrictEqual({
113
+ display: false,
114
+ redelegate: false,
115
+ validatorSrcAddress: "",
116
+ ledgerValidator,
117
+ });
118
+ });
119
+ it("should return display delegate mode", async () => {
120
+ jest
121
+ .spyOn(preloadedData, "getCurrentCosmosPreloadData")
122
+ .mockReturnValue({ validators } as {
123
+ validators: CosmosValidatorItem[];
124
+ });
125
+ jest.spyOn(bridge, "getAccountBridge").mockReturnValue({
126
+ estimateMaxSpendable: () => Promise.resolve(new BigNumber(5000)),
127
+ } as any);
128
+ const result = await getAccountBannerState(account);
129
+ expect(result).toStrictEqual({
130
+ display: true,
131
+ redelegate: false,
132
+ validatorSrcAddress: "",
133
+ ledgerValidator,
134
+ });
135
+ });
136
+ it("should return display redelegate mode", async () => {
137
+ jest
138
+ .spyOn(preloadedData, "getCurrentCosmosPreloadData")
139
+ .mockReturnValue({ validators } as {
140
+ validators: CosmosValidatorItem[];
141
+ });
142
+ jest.spyOn(bridge, "getAccountBridge").mockReturnValue({
143
+ estimateMaxSpendable: () => Promise.resolve(new BigNumber(5000)),
144
+ } as any);
145
+ account.cosmosResources.redelegations.push({
146
+ validatorSrcAddress: "xxxx",
147
+ validatorDstAddress: expensiveValidator?.validatorAddress as string,
148
+ amount: new BigNumber(1000),
149
+ completionDate: new Date(),
150
+ });
151
+ const result = await getAccountBannerState(account);
152
+ expect(result).toStrictEqual({
153
+ display: true,
154
+ redelegate: true,
155
+ validatorSrcAddress: expensiveValidator?.validatorAddress,
156
+ ledgerValidator,
157
+ });
158
+ });
159
+ });
160
+ });
@@ -0,0 +1,87 @@
1
+ import { getCurrentCosmosPreloadData } from "./preloadedData";
2
+ import { getAccountBridge } from "../../bridge";
3
+ import { LEDGER_VALIDATOR_ADDRESS } from "./utils";
4
+ import type { CosmosAccount, CosmosValidatorItem } from "./types";
5
+
6
+ interface AccountBannerState {
7
+ display: boolean;
8
+ redelegate: boolean;
9
+ validatorSrcAddress: string;
10
+ ledgerValidator: CosmosValidatorItem | undefined;
11
+ }
12
+
13
+ export async function getAccountBannerState(
14
+ account: CosmosAccount
15
+ ): Promise<AccountBannerState> {
16
+ // Group current validator
17
+ const cosmosResources = account.cosmosResources
18
+ ? account.cosmosResources
19
+ : { delegations: [], redelegations: [] };
20
+ const delegationAddresses = cosmosResources.delegations.map((delegation) => {
21
+ return delegation.validatorAddress;
22
+ });
23
+ const redelegationAddresses = cosmosResources.redelegations.map(
24
+ (redelegation) => {
25
+ return redelegation.validatorDstAddress;
26
+ }
27
+ );
28
+ const validatorAdresses = [...delegationAddresses, ...redelegationAddresses];
29
+
30
+ // Get ledger validator data
31
+ const { validators } = getCurrentCosmosPreloadData();
32
+ const ledgerValidator = validators.find(
33
+ (validator) => validator.validatorAddress === LEDGER_VALIDATOR_ADDRESS
34
+ );
35
+
36
+ // Find user current worst validator (default validator is ledger)
37
+ let worstValidator = ledgerValidator;
38
+ for (let i = 0; i < validatorAdresses.length; i++) {
39
+ const validatorAdress = validatorAdresses[i];
40
+ const validator = validators.find(
41
+ (validator) => validator.validatorAddress === validatorAdress
42
+ );
43
+ if (
44
+ worstValidator &&
45
+ validator &&
46
+ worstValidator.commission < validator.commission
47
+ ) {
48
+ worstValidator = validator;
49
+ }
50
+ }
51
+
52
+ let redelegate = false;
53
+ let validatorSrcAddress = "";
54
+ let display = false;
55
+
56
+ if (worstValidator) {
57
+ if (
58
+ worstValidator?.validatorAddress === ledgerValidator?.validatorAddress
59
+ ) {
60
+ // Not found worst validator than ledger
61
+ const maxSpendable = await getAccountBridge(
62
+ account,
63
+ undefined
64
+ ).estimateMaxSpendable({
65
+ account,
66
+ parentAccount: undefined,
67
+ transaction: undefined,
68
+ });
69
+ if (maxSpendable.gt(0)) {
70
+ // Delegate remaining ATOM (not staked)
71
+ display = true;
72
+ }
73
+ } else {
74
+ // Redelegate to the worst validator
75
+ display = true;
76
+ redelegate = true;
77
+ validatorSrcAddress = worstValidator.validatorAddress;
78
+ }
79
+ }
80
+
81
+ return {
82
+ display,
83
+ redelegate,
84
+ validatorSrcAddress,
85
+ ledgerValidator,
86
+ };
87
+ }
package/src/operation.ts CHANGED
@@ -178,6 +178,7 @@ export function getOperationAmountNumber(op: Operation): BigNumber {
178
178
  case "REWARD":
179
179
  case "REWARD_PAYOUT":
180
180
  case "SUPPLY":
181
+ case "WITHDRAW":
181
182
  return op.value;
182
183
 
183
184
  case "OUT":
@@ -191,6 +192,7 @@ export function getOperationAmountNumber(op: Operation): BigNumber {
191
192
  case "OPT_OUT":
192
193
  case "REDEEM":
193
194
  case "SLASH":
195
+ case "LOCK":
194
196
  return op.value.negated();
195
197
 
196
198
  case "FREEZE":
@@ -202,6 +204,10 @@ export function getOperationAmountNumber(op: Operation): BigNumber {
202
204
  case "SET_CONTROLLER":
203
205
  case "NOMINATE":
204
206
  case "CHILL":
207
+ case "REVOKE":
208
+ case "APPROVE":
209
+ case "ACTIVATE":
210
+ case "UNLOCK":
205
211
  return op.fee.negated();
206
212
 
207
213
  default:
@@ -26,6 +26,7 @@ import {
26
26
  fromElrondResourcesRaw,
27
27
  fromCryptoOrgResourcesRaw,
28
28
  fromSolanaResourcesRaw,
29
+ fromCeloResourcesRaw,
29
30
  fromNFTRaw,
30
31
  toTronResourcesRaw,
31
32
  toCosmosResourcesRaw,
@@ -36,6 +37,7 @@ import {
36
37
  toElrondResourcesRaw,
37
38
  toCryptoOrgResourcesRaw,
38
39
  toSolanaResourcesRaw,
40
+ toCeloResourcesRaw,
39
41
  } from "./account";
40
42
  import consoleWarnExpectToEqual from "./consoleWarnExpectToEqual";
41
43
  import { AlgorandAccount, AlgorandAccountRaw } from "./families/algorand/types";
@@ -51,6 +53,7 @@ import { PolkadotAccount, PolkadotAccountRaw } from "./families/polkadot/types";
51
53
  import { SolanaAccount, SolanaAccountRaw } from "./families/solana/types";
52
54
  import { TezosAccount, TezosAccountRaw } from "./families/tezos/types";
53
55
  import { TronAccount, TronAccountRaw } from "./families/tron/types";
56
+ import { CeloAccount, CeloAccountRaw } from "./families/celo/types";
54
57
 
55
58
  // aim to build operations with the minimal diff & call to coin implementation possible
56
59
  export async function minimalOperationsBuilder<CO>(
@@ -490,6 +493,25 @@ export function patchAccount(
490
493
  }
491
494
  break;
492
495
  }
496
+ case "celo": {
497
+ const celoAcc = account as CeloAccount;
498
+ const celoUpdatedRaw = updatedRaw as CeloAccountRaw;
499
+
500
+ if (
501
+ celoUpdatedRaw.celoResources &&
502
+ (!celoAcc.celoResources ||
503
+ !areSameResources(
504
+ toCeloResourcesRaw(celoAcc.celoResources),
505
+ celoUpdatedRaw.celoResources
506
+ ))
507
+ ) {
508
+ (next as CeloAccount).celoResources = fromCeloResourcesRaw(
509
+ celoUpdatedRaw.celoResources
510
+ );
511
+ changed = true;
512
+ }
513
+ break;
514
+ }
493
515
  }
494
516
 
495
517
  const nfts = updatedRaw?.nfts?.map(fromNFTRaw);