This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
forked from LedgerHQ/ledger-live-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make use of useAllAmount flag * make use of useAllAmount on signing tx process * refactor signOperation process to use extra field better * add deviceTransactionConfig for filecoin * re org fields for confirm tx * change fields order * add extra field parsers * move extra field parsers to the correct file * fix lint issue
- Loading branch information
1 parent
2c1645a
commit 0ab12b2
Showing
8 changed files
with
192 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import BigNumber from "bignumber.js"; | ||
|
||
export function fromOperationExtraRaw( | ||
extra: Record<string, any> | null | undefined | ||
): Record<string, any> | null | undefined { | ||
if (!extra) return extra; | ||
|
||
const { gasLimit, gasPremium, gasFeeCap } = extra; | ||
|
||
if (gasLimit !== undefined) | ||
extra = { ...extra, gasLimit: new BigNumber(gasLimit) }; | ||
|
||
if (gasPremium !== undefined) | ||
extra = { ...extra, gasPremium: new BigNumber(gasPremium) }; | ||
|
||
if (gasFeeCap !== undefined) | ||
extra = { ...extra, gasFeeCap: new BigNumber(gasFeeCap) }; | ||
|
||
return extra; | ||
} | ||
|
||
export function toOperationExtraRaw( | ||
extra: Record<string, any> | null | undefined | ||
): Record<string, any> | null | undefined { | ||
if (!extra) return extra; | ||
|
||
const { gasLimit, gasPremium, gasFeeCap } = extra; | ||
|
||
if (gasLimit !== undefined) | ||
extra = { ...extra, gasLimit: gasLimit.toNumber() }; | ||
|
||
if (gasPremium !== undefined) | ||
extra = { ...extra, gasPremium: gasPremium.toFixed() }; | ||
|
||
if (gasFeeCap !== undefined) | ||
extra = { ...extra, gasFeeCap: gasFeeCap.toFixed() }; | ||
|
||
return extra; | ||
} | ||
|
||
export default { | ||
fromOperationExtraRaw, | ||
toOperationExtraRaw, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { DeviceTransactionField } from "../../transaction"; | ||
import type { Account, AccountLike, TransactionStatus } from "../../types"; | ||
import type { Transaction } from "./types"; | ||
import { formatCurrencyUnit, getCryptoCurrencyById } from "../../currencies"; | ||
import { methodToString } from "./utils"; | ||
|
||
const currency = getCryptoCurrencyById("filecoin"); | ||
|
||
export type ExtraDeviceTransactionField = | ||
| { | ||
type: "filecoin.gasFeeCap"; | ||
label: string; | ||
value: string; | ||
} | ||
| { | ||
type: "filecoin.gasPremium"; | ||
label: string; | ||
value: string; | ||
} | ||
| { | ||
type: "filecoin.gasLimit"; | ||
label: string; | ||
value: string; | ||
} | ||
| { | ||
type: "filecoin.method"; | ||
label: string; | ||
value: string; | ||
}; | ||
|
||
function getDeviceTransactionConfig(input: { | ||
account: AccountLike; | ||
parentAccount: Account | null | undefined; | ||
transaction: Transaction; | ||
status: TransactionStatus; | ||
}): Array<DeviceTransactionField> { | ||
const fields: Array<DeviceTransactionField> = []; | ||
|
||
fields.push({ | ||
type: "amount", | ||
label: "Value", | ||
}); | ||
fields.push({ | ||
type: "filecoin.gasLimit", | ||
label: "Gas Limit", | ||
value: input.transaction.gasLimit.toFixed(), | ||
}); | ||
fields.push({ | ||
type: "filecoin.gasPremium", | ||
label: "Gas Premium", | ||
value: formatCurrencyUnit(currency.units[0], input.transaction.gasPremium, { | ||
showCode: false, | ||
disableRounding: true, | ||
}), | ||
}); | ||
fields.push({ | ||
type: "filecoin.gasFeeCap", | ||
label: "Gas Fee Cap", | ||
value: formatCurrencyUnit(currency.units[0], input.transaction.gasFeeCap, { | ||
showCode: false, | ||
disableRounding: true, | ||
}), | ||
}); | ||
fields.push({ | ||
type: "filecoin.method", | ||
label: "Method", | ||
value: methodToString(input.transaction.method), | ||
}); | ||
|
||
return fields; | ||
} | ||
|
||
export default getDeviceTransactionConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters