-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathBalance.native.tsx
More file actions
112 lines (104 loc) · 3.37 KB
/
Copy pathBalance.native.tsx
File metadata and controls
112 lines (104 loc) · 3.37 KB
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
import { ScrollView } from "react-native";
import { Box, Button, Divider, IconButton, Text } from "@ledgerhq/lumen-ui-rnative";
import { Refresh } from "@ledgerhq/lumen-ui-rnative/symbols";
import type { PayCardBalanceProps, PayCardBalanceWallet } from "../../types";
export interface BalanceScreenProps extends PayCardBalanceProps {
readonly onBack: () => void;
}
const CONTAINER_LX = { gap: "s16", padding: "s16" } as const;
const HEADER_LX = {
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
} as const;
const BLOCK_LX = { gap: "s4" } as const;
const FIELD_LX = { flexDirection: "row", gap: "s8" } as const;
function Field({ label, value }: { readonly label: string; readonly value: string }) {
return (
<Box lx={FIELD_LX}>
<Text typography="body3" lx={{ color: "muted" }}>
{label}
</Text>
<Text typography="body3" lx={{ color: "base" }}>
{value}
</Text>
</Box>
);
}
function Wallet({ wallet }: { readonly wallet: PayCardBalanceWallet }) {
return (
<Box lx={BLOCK_LX}>
<Text typography="body2">{`${wallet.priority}. ${wallet.currency} / ${wallet.network}`}</Text>
{/* The provider's own ids, unmapped: what a currency mapping would have to be keyed on. */}
<Field label="currency" value={wallet.currency} />
<Field label="network" value={wallet.network} />
<Field label="balance" value={wallet.balance ?? "null — no internal wallet matched"} />
<Field
label="counterValue"
value={
wallet.counterValue === null
? "null — no currency matched this ticker, or no rate for it"
: String(wallet.counterValue)
}
/>
<Field label="id" value={wallet.id} />
<Field label="address" value={wallet.address} />
</Box>
);
}
export function BalanceScreen({
total,
isPartialTotal,
wallets,
isFetching,
errors,
onBack,
refresh,
}: BalanceScreenProps) {
return (
<ScrollView>
<Box lx={CONTAINER_LX}>
<Box lx={HEADER_LX}>
<Button appearance="gray" size="sm" onPress={onBack}>
Back
</Button>
<IconButton
icon={Refresh}
appearance="no-background"
size="sm"
loading={isFetching}
onPress={refresh}
accessibilityLabel="Refresh"
/>
</Box>
<Box lx={BLOCK_LX}>
<Text typography="body3" lx={{ color: "muted" }}>
Total amount
</Text>
{/* Always stringified: an absent total has to read as `undefined`, not as a blank. */}
<Text typography="heading4SemiBold" lx={{ color: "base" }}>
{String(total)}
</Text>
<Field label="isPartialTotal" value={String(isPartialTotal)} />
<Field label="wallets" value={String(wallets.length)} />
</Box>
{errors.map(({ endpoint, detail }) => (
<Box key={endpoint} lx={BLOCK_LX}>
<Text typography="body2" lx={{ color: "error" }}>
{endpoint}
</Text>
<Text typography="body3" lx={{ color: "error" }}>
{detail}
</Text>
</Box>
))}
{wallets.map(wallet => (
<Box key={wallet.id} lx={BLOCK_LX}>
<Divider />
<Wallet wallet={wallet} />
</Box>
))}
</Box>
</ScrollView>
);
}