-
Notifications
You must be signed in to change notification settings - Fork 295
/
AssetTransactionConfirmation.tsx
185 lines (174 loc) · 6.16 KB
/
AssetTransactionConfirmation.tsx
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// @flow
import React from 'react';
import classnames from 'classnames';
import BigNumber from 'bignumber.js';
import {
defineMessages,
intlShape,
injectIntl,
FormattedHTMLMessage,
} from 'react-intl';
import { PopOver } from 'react-polymorph/lib/components/PopOver';
import { observer } from 'mobx-react';
import SVGInline from 'react-svg-inline';
import questionMarkIcon from '../../assets/images/question-mark.inline.svg';
import styles from './AssetTransactionConfirmation.scss';
import type { AssetToken } from '../../api/assets/types';
import Asset from './Asset';
import { formattedTokenWalletAmount } from '../../utils/formatters';
const messages = defineMessages({
assetLabel: {
id: 'asset.transactionConfirmation.assetLabel',
defaultMessage: '!!!Token #{assetNumber}',
description: '"assetLabel" item on AssetTransactionConfirmation.',
},
unformattedAmountLabel: {
id: 'asset.transactionConfirmation.unformattedAmountLabel',
defaultMessage: '!!!unformatted amount',
description:
'"unformattedAmountLabel" item on AssetTransactionConfirmation.',
},
unformattedAmountMessageForHardwareWallets: {
id:
'asset.transactionConfirmation.unformattedAmountMessageForHardwareWallets',
defaultMessage:
'!!!Native assets may specify a number of decimal places, as defined in the Cardano token registry. Daedalus uses this information to format the amount that is being sent in the transaction.<br /><br />The native token unformatted amount is the amount without these decimal places. Please ensure that you verify both amounts, as some wallet software may not yet use the Cardano token registry.',
description:
'"unformattedAmountMessageForHardwareWallets" item on AssetTransactionConfirmation.',
},
unformattedAmountMessageForSoftwareWallets: {
id:
'asset.transactionConfirmation.unformattedAmountMessageForSoftwareWallets',
defaultMessage:
'!!!Native assets may specify a number of decimal places, as defined in the Cardano token registry. Daedalus uses this information to format the amount that is being sent in the transaction.<br /><br />The native token unformatted amount is the amount without these decimal places. Please ensure that you verify both amounts, as some wallet software may not yet use the Cardano token registry.<br /><br />The native token unformatted amount will be displayed on the hardware wallet device during transaction confirmation.',
description:
'"unformattedAmountMessageForSoftwareWallets" item on AssetTransactionConfirmation.',
},
missingToken: {
id: 'asset.transactionConfirmation.missingToken',
defaultMessage: '!!!There is no such token in this wallet',
description: '"missingToken" item on AssetTransactionConfirmation.',
},
insufficientBalance: {
id: 'asset.transactionConfirmation.insufficientBalance',
defaultMessage:
'!!!Insufficient funds. The balance of the token in this wallet is {formattedBalance} (Unformatted: {unformattedBalance})',
description: '"insufficientBalance" item on AssetTransactionConfirmation.',
},
});
type Props = {
asset: AssetToken,
assetNumber: number,
intl: intlShape.isRequired,
isHardwareWallet: boolean,
tokenIsMissing?: boolean,
insufficientBalance?: boolean,
amount: BigNumber,
};
const onCopyAssetParam = () => {};
const AssetTransactionConfirmation = observer((props: Props) => {
const {
assetNumber,
asset,
intl,
isHardwareWallet,
tokenIsMissing,
insufficientBalance,
amount,
} = props;
const hasError = tokenIsMissing || insufficientBalance;
const { metadata, decimals } = asset;
const formattedAmount = formattedTokenWalletAmount(
amount,
metadata,
decimals
);
const unformattedAmount = formattedTokenWalletAmount(amount, null, 0);
const formattedBalance = formattedTokenWalletAmount(
asset.quantity,
metadata,
decimals
);
const unformattedBalance = formattedTokenWalletAmount(
asset.quantity,
null,
0
);
const componentStyles = classnames(styles.component, {
[styles.error]: hasError,
});
const content = (
<>
<div className={styles.assetsContainer}>
<h3>
<span className={styles.assetLabel}>
{intl.formatMessage(messages.assetLabel, { assetNumber })}{' '}
</span>
<Asset
asset={asset}
onCopyAssetParam={onCopyAssetParam}
hasError={hasError}
/>
</h3>
<div className={styles.amountFeesWrapper}>
<div className={styles.amount}>{formattedAmount}</div>
</div>
</div>
<div className={styles.assetsContainer}>
<div className={styles.unformattedAmountLine} />
<div className={styles.unformattedAmountLabel}>
{intl.formatMessage(messages.unformattedAmountLabel)}
<PopOver
content={
<FormattedHTMLMessage
{...messages[
isHardwareWallet
? 'unformattedAmountMessageForHardwareWallets'
: 'unformattedAmountMessageForSoftwareWallets'
]}
tagName="div"
/>
}
>
<div className={styles.questionMark}>
<SVGInline svg={questionMarkIcon} />
</div>
</PopOver>
{':'}
</div>
<div className={styles.unformattedAmount}>{unformattedAmount}</div>
</div>
</>
);
if (tokenIsMissing) {
return (
<div className={componentStyles}>
<PopOver
content={intl.formatMessage(messages.missingToken)}
appendTo="parent"
placement="bottom"
>
{content}
</PopOver>
</div>
);
}
if (insufficientBalance) {
return (
<div className={componentStyles}>
<PopOver
content={intl.formatMessage(messages.insufficientBalance, {
formattedBalance,
unformattedBalance,
})}
appendTo="parent"
placement="bottom"
>
{content}
</PopOver>
</div>
);
}
return <div className={componentStyles}>{content}</div>;
});
export default injectIntl(AssetTransactionConfirmation);