Skip to content

Commit 27dfca9

Browse files
committed
Introduce DataSheetModal for exchange details
1 parent 813152c commit 27dfca9

File tree

4 files changed

+163
-32
lines changed

4 files changed

+163
-32
lines changed

src/components/cards/SwapDetailsCard.tsx

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { useSelector } from '../../types/reactRedux'
1919
import { getWalletName } from '../../util/CurrencyWalletHelpers'
2020
import { convertNativeToDisplay, unixToLocaleDateTime } from '../../util/utils'
21-
import { RawTextModal } from '../modals/RawTextModal'
21+
import { DataSheetModal, DataSheetSection } from '../modals/DataSheetModal'
2222
import { EdgeRow } from '../rows/EdgeRow'
2323
import { Airship, showError } from '../services/AirshipInstance'
2424
import { EdgeText } from '../themed/EdgeText'
@@ -61,16 +61,26 @@ export function SwapDetailsCard(props: Props) {
6161

6262
const handleExchangeDetails = useHandler(async () => {
6363
await Airship.show(bridge => (
64-
<RawTextModal
64+
<DataSheetModal
6565
bridge={bridge}
66-
body={createExchangeDataString()}
66+
sections={createExchangeDataSheetSections()}
6767
title={lstrings.transaction_details_exchange_details}
6868
/>
6969
))
7070
})
7171

7272
const handleEmail = useHandler(() => {
73-
const body = createExchangeDataString('<br />')
73+
// Serialize the data sheet sections to a string:
74+
const sections = createExchangeDataSheetSections()
75+
const body = sections
76+
.map(section =>
77+
// Separate rows with a newline
78+
section.rows.map(row => row.title + ': ' + row.body).join('\n')
79+
)
80+
// Separate sections with two newlines
81+
.join('\n\n')
82+
// Replace newlines with <br/> tags
83+
.replaceAll('\n', '<br/>')
7484

7585
Mailer.mail(
7686
{
@@ -156,48 +166,98 @@ export function SwapDetailsCard(props: Props) {
156166
getExchangeDenom(destinationWallet.currencyConfig, null).name
157167
})`
158168

159-
const createExchangeDataString = (newline: string = '\n') => {
169+
const createExchangeDataSheetSections = (): DataSheetSection[] => {
160170
const uniqueIdentifier = memos
161171
.map(
162172
(memo, index) =>
163-
`${memo.value}${index + 1 !== memos.length ? newline : ''}`
173+
`${memo.value}${index + 1 !== memos.length ? '\n' : ''}`
164174
)
165175
.toString()
166176
const exchangeAddresses = spendTargets
167177
.map(
168178
(target, index) =>
169179
`${target.publicAddress}${
170-
index + 1 !== spendTargets.length ? newline : ''
180+
index + 1 !== spendTargets.length ? '\n' : ''
171181
}`
172182
)
173183
.toString()
174184
const { dateTime } = unixToLocaleDateTime(transaction.date)
175185

176-
return `${lstrings.fio_date_label}: ${dateTime}${newline}${
177-
lstrings.transaction_details_exchange_service
178-
}: ${plugin.displayName}${newline}${
179-
lstrings.transaction_details_exchange_order_id
180-
}: ${orderId || ''}${newline}${
181-
lstrings.transaction_details_exchange_source_wallet
182-
}: ${walletName}${newline}${
183-
lstrings.fragment_send_from_label
184-
}: ${sourceAmount} ${sourceAssetName}${newline}${
185-
lstrings.string_to_capitalize
186-
}: ${destinationAmount} ${destinationAssetName}${newline}${
187-
lstrings.transaction_details_exchange_destination_wallet
188-
}: ${destinationWalletName}${newline}${
189-
isEstimate ? lstrings.estimated_quote : lstrings.fixed_quote
190-
}${newline}${newline}${lstrings.transaction_details_tx_id_modal_title}: ${
191-
transaction.txid
192-
}${newline}${newline}${
193-
lstrings.transaction_details_exchange_exchange_address
194-
}:${newline}${exchangeAddresses}${newline}${newline}${
195-
lstrings.transaction_details_exchange_exchange_unique_id
196-
}:${newline}${uniqueIdentifier}${newline}${newline}${
197-
lstrings.transaction_details_exchange_payout_address
198-
}:${newline}${payoutAddress}${newline}${newline}${
199-
lstrings.transaction_details_exchange_refund_address
200-
}:${newline}${refundAddress || ''}${newline}`
186+
return [
187+
{
188+
rows: [
189+
{
190+
title: lstrings.fio_date_label,
191+
body: dateTime
192+
},
193+
{
194+
title: lstrings.transaction_details_exchange_service,
195+
body: plugin.displayName
196+
},
197+
{
198+
title: lstrings.transaction_details_exchange_order_id,
199+
body: orderId || ''
200+
},
201+
{
202+
title: lstrings.quote_type,
203+
body: isEstimate ? lstrings.estimated_quote : lstrings.fixed_quote
204+
}
205+
]
206+
},
207+
{
208+
rows: [
209+
{
210+
title: lstrings.transaction_details_exchange_source_wallet,
211+
body: walletName
212+
},
213+
{
214+
title: lstrings.string_send_amount,
215+
body: `${sourceAmount} ${sourceAssetName}`
216+
}
217+
]
218+
},
219+
{
220+
rows: [
221+
{
222+
title: lstrings.transaction_details_exchange_destination_wallet,
223+
body: destinationWalletName
224+
},
225+
{
226+
title: lstrings.string_receive_amount,
227+
body: `${destinationAmount} ${destinationAssetName}`
228+
}
229+
]
230+
},
231+
{
232+
rows: [
233+
{
234+
title: lstrings.transaction_details_tx_id_modal_title,
235+
body: transaction.txid
236+
},
237+
{
238+
title: lstrings.transaction_details_exchange_exchange_address,
239+
body: exchangeAddresses
240+
},
241+
...(uniqueIdentifier !== ''
242+
? [
243+
{
244+
title:
245+
lstrings.transaction_details_exchange_exchange_unique_id,
246+
body: uniqueIdentifier
247+
}
248+
]
249+
: []),
250+
{
251+
title: lstrings.transaction_details_exchange_payout_address,
252+
body: payoutAddress
253+
},
254+
{
255+
title: lstrings.transaction_details_exchange_refund_address,
256+
body: refundAddress || ''
257+
}
258+
]
259+
}
260+
]
201261
}
202262

203263
return (
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import * as React from 'react'
2+
import { Fragment } from 'react'
3+
import { ScrollView } from 'react-native'
4+
import { AirshipBridge } from 'react-native-airship'
5+
6+
import { SCROLL_INDICATOR_INSET_FIX } from '../../constants/constantSettings'
7+
import { EdgeCard } from '../cards/EdgeCard'
8+
import { SectionHeader } from '../common/SectionHeader'
9+
import { EdgeRow } from '../rows/EdgeRow'
10+
import { EdgeModal } from './EdgeModal'
11+
12+
interface Props {
13+
bridge: AirshipBridge<void>
14+
15+
/** The sections data to display in the modal. */
16+
sections: DataSheetSection[]
17+
18+
/** The title of the modal. */
19+
title?: string
20+
}
21+
22+
export interface DataSheetSection {
23+
/** The title of the section. */
24+
title?: string
25+
26+
/** The rows of the section. */
27+
rows: DataSheetRow[]
28+
}
29+
30+
export interface DataSheetRow {
31+
/** The title or label of the row. */
32+
title: string
33+
34+
/** The body text of the row. */
35+
body: string
36+
}
37+
38+
export function DataSheetModal(props: Props) {
39+
const { bridge, sections, title } = props
40+
41+
const handleCancel = () => bridge.resolve(undefined)
42+
43+
return (
44+
<EdgeModal bridge={bridge} title={title} onCancel={handleCancel}>
45+
<ScrollView scrollIndicatorInsets={SCROLL_INDICATOR_INSET_FIX}>
46+
{sections.map((section, index) => (
47+
<Fragment key={index + (section.title ?? '')}>
48+
{section.title == null ? null : (
49+
<SectionHeader leftTitle={section.title} />
50+
)}
51+
<EdgeCard>
52+
{section.rows.map((row, index) => (
53+
<EdgeRow
54+
key={index + row.title}
55+
title={row.title}
56+
body={row.body}
57+
/>
58+
))}
59+
</EdgeCard>
60+
</Fragment>
61+
))}
62+
</ScrollView>
63+
</EdgeModal>
64+
)
65+
}

src/locales/en_US.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ const strings = {
731731
string_save: 'Save',
732732
string_share: 'Share',
733733
string_to_capitalize: 'To',
734+
string_send_amount: 'Send Amount',
735+
string_receive_amount: 'Receive Amount',
734736
string_show_balance: 'Show Balance',
735737
string_amount: 'Amount',
736738
string_tap_next_for_quote: 'Tap "Next" for Quote',
@@ -1114,6 +1116,7 @@ const strings = {
11141116
'This swap will create an order to exchange funds at the quoted rate but might only fulfill a portion of your order.\n\nFunds that fail to swap will remain in your source wallet or be returned.',
11151117
fixed_quote: 'Fixed Quote',
11161118
estimated_quote: 'Estimated Quote',
1119+
quote_type: 'Quote Type',
11171120
estimated_exchange_rate: 'Estimated Exchange Rate',
11181121
estimated_exchange_rate_body:
11191122
'No exchange providers are able to provide a fixed quote for the exchange requested. This exchange may result in less funds received than quoted.',

src/locales/strings/enUS.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@
565565
"string_save": "Save",
566566
"string_share": "Share",
567567
"string_to_capitalize": "To",
568+
"string_send_amount": "Send Amount",
569+
"string_receive_amount": "Receive Amount",
568570
"string_show_balance": "Show Balance",
569571
"string_amount": "Amount",
570572
"string_tap_next_for_quote": "Tap \"Next\" for Quote",
@@ -882,6 +884,7 @@
882884
"can_be_partial_quote_body": "This swap will create an order to exchange funds at the quoted rate but might only fulfill a portion of your order.\n\nFunds that fail to swap will remain in your source wallet or be returned.",
883885
"fixed_quote": "Fixed Quote",
884886
"estimated_quote": "Estimated Quote",
887+
"quote_type": "Quote Type",
885888
"estimated_exchange_rate": "Estimated Exchange Rate",
886889
"estimated_exchange_rate_body": "No exchange providers are able to provide a fixed quote for the exchange requested. This exchange may result in less funds received than quoted.",
887890
"estimated_exchange_message": "The amount above is an estimate. This exchange may result in less funds received than quoted.",

0 commit comments

Comments
 (0)