Skip to content

Commit ff5e067

Browse files
committed
improve vaults
1 parent ccc836b commit ff5e067

4 files changed

Lines changed: 74 additions & 2 deletions

File tree

src/components/VaultSignRequest/VaultSignRequest.tsx

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,35 @@ import Icon from 'react-native-vector-icons/Feather';
1313
import { blockchains } from '../../storage/blockchains';
1414
import type { cryptos } from '../../types';
1515

16+
/**
17+
* Format a base-unit amount (satoshis/wei) to human-readable using chain decimals.
18+
*/
19+
function formatAmount(amount: string, decimals: number): string {
20+
try {
21+
const raw = BigInt(amount);
22+
const divisor = 10n ** BigInt(decimals);
23+
const wholePart = raw / divisor;
24+
const fracPart = raw % divisor;
25+
if (fracPart === 0n) {
26+
return wholePart.toString();
27+
}
28+
const fracStr = fracPart.toString().padStart(decimals, '0');
29+
const trimmed = fracStr.replace(/0+$/, '');
30+
return `${wholePart.toString()}.${trimmed}`;
31+
} catch {
32+
return amount;
33+
}
34+
}
35+
1636
interface VaultSignRequestProps {
1737
activityStatus: boolean;
1838
recipients: Array<{ address: string; amount: string; label?: string }>;
1939
fee: string;
2040
feeLabel: string;
2141
memo?: string;
2242
chain: string;
43+
vaultName?: string;
44+
orgName?: string;
2345
actionStatus: (status: boolean) => void;
2446
}
2547

@@ -30,6 +52,8 @@ const VaultSignRequest: React.FC<VaultSignRequestProps> = ({
3052
feeLabel,
3153
memo,
3254
chain,
55+
vaultName,
56+
orgName,
3357
actionStatus,
3458
}) => {
3559
const { t } = useTranslation(['home', 'common']);
@@ -39,6 +63,8 @@ const VaultSignRequest: React.FC<VaultSignRequestProps> = ({
3963
const chainDisplay = chainConfig
4064
? `${chainConfig.name} (${chainConfig.symbol})`
4165
: chain;
66+
const chainDecimals = chainConfig?.decimals ?? 8;
67+
const chainSymbol = chainConfig?.symbol ?? chain.toUpperCase();
4268

4369
const approve = () => {
4470
console.log('Approve vault signing request');
@@ -98,6 +124,46 @@ const VaultSignRequest: React.FC<VaultSignRequestProps> = ({
98124
{t('home:vault_sign_request_info')}
99125
</Text>
100126

127+
{/* Vault & Org Info */}
128+
{(vaultName || orgName) && (
129+
<View
130+
style={[
131+
Gutters.regularTMargin,
132+
Gutters.regularLMargin,
133+
Gutters.regularRMargin,
134+
{
135+
backgroundColor: Colors.inputBackground,
136+
borderRadius: 8,
137+
padding: 12,
138+
width: '90%',
139+
borderWidth: 1,
140+
borderColor: Colors.textGray200,
141+
},
142+
]}
143+
>
144+
{vaultName && (
145+
<View style={{ marginBottom: orgName ? 4 : 0 }}>
146+
<Text style={[Fonts.textTiny, { color: Colors.textGray400 }]}>
147+
{t('home:vault')}
148+
</Text>
149+
<Text style={[Fonts.textSmall, Fonts.textBold]}>
150+
{vaultName}
151+
</Text>
152+
</View>
153+
)}
154+
{orgName && (
155+
<View>
156+
<Text style={[Fonts.textTiny, { color: Colors.textGray400 }]}>
157+
{t('home:organization')}
158+
</Text>
159+
<Text style={[Fonts.textSmall, Fonts.textBold]}>
160+
{orgName}
161+
</Text>
162+
</View>
163+
)}
164+
</View>
165+
)}
166+
101167
{/* Chain Info */}
102168
<View
103169
style={[
@@ -196,7 +262,7 @@ const VaultSignRequest: React.FC<VaultSignRequestProps> = ({
196262
{ marginTop: 2 },
197263
]}
198264
>
199-
{recipient.amount}
265+
{formatAmount(recipient.amount, chainDecimals)} {chainSymbol}
200266
</Text>
201267
</View>
202268
))}
@@ -211,7 +277,7 @@ const VaultSignRequest: React.FC<VaultSignRequestProps> = ({
211277
{ color: Colors.textGray400 },
212278
]}
213279
>
214-
{t('home:vault_sign_fee')}: {fee} ({feeLabel})
280+
{t('home:vault_sign_fee')}: {formatAmount(fee, chainDecimals)} {chainSymbol}
215281
</Text>
216282
</View>
217283

src/screens/Home/Home.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,8 @@ function Home({ navigation }: Props) {
25062506
feeLabel={vaultSigningData.feeLabel}
25072507
memo={vaultSigningData.memo}
25082508
chain={vaultSigningData.chain}
2509+
vaultName={vaultSigningData.vaultName}
2510+
orgName={vaultSigningData.orgName}
25092511
actionStatus={handleVaultSigningRequestAction}
25102512
/>
25112513
)}

src/translations/resources/en/home.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
"err_vault_xpub_failed": "Failed to share vault public key. Try again.",
138138
"vault_sign_request": "Vault Transaction",
139139
"vault_sign_request_info": "An enterprise vault is requesting your signature on a transaction. Please review the details below.",
140+
"vault": "Vault",
141+
"organization": "Organization",
140142
"vault_sign_recipients": "Recipients",
141143
"vault_sign_fee": "Fee",
142144
"vault_sign_memo": "Memo",

src/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ interface vaultSigningRequest {
606606
chain: string;
607607
orgIndex: number;
608608
vaultIndex: number;
609+
vaultName?: string;
610+
orgName?: string;
609611
recipients: Array<{ address: string; amount: string; label?: string }>;
610612
fee: string;
611613
feeLabel: string;

0 commit comments

Comments
 (0)