Skip to content

Commit

Permalink
refactor: address minor code issues
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarkhanzadian committed Dec 4, 2024
1 parent 65311ee commit 8f594ca
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,9 @@ import { useBtcMarketDataQuery } from '@/queries/market-data/btc-market-data.que
import { t } from '@lingui/macro';

import { Money } from '@leather.io/models';
import { AddressDisplayer, Avatar, Flag, Text, UsersTwoIcon } from '@leather.io/ui/native';
import { Text } from '@leather.io/ui/native';
import { baseCurrencyAmountInQuote, createMoney } from '@leather.io/utils';

function BitcoinAddress({ address }: { address: string }) {
return (
<Flag
py="3"
img={
<Avatar bg="ink.background-secondary">
<UsersTwoIcon />
</Avatar>
}
>
<AddressDisplayer address={address} />
</Flag>
);
}

export function BitcoinOutcome({ amount }: { amount: Money }) {
const { data: btcMarketData } = useBtcMarketDataQuery();

Expand All @@ -40,19 +25,3 @@ export function BitcoinOutcome({ amount }: { amount: Money }) {
</>
);
}

export function OutcomeAddressesCard({ addresses }: { addresses: string[] }) {
return (
<>
<Text variant="label01">
{t({
id: 'approver.outcomes.title2',
message: 'To address',
})}
</Text>
{addresses.map(address => (
<BitcoinAddress key={address} address={address} />
))}
</>
);
}
7 changes: 6 additions & 1 deletion apps/mobile/src/features/approver/components/fee-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import {
} from '@leather.io/ui/native';
import { baseCurrencyAmountInQuote, createMoney, match } from '@leather.io/utils';

export function FeeCard({ feeType, amount }: { feeType: FeeTypes; amount: Money }) {
interface FeeCardProps {
feeType: FeeTypes;
amount: Money;
}

export function FeeCard({ feeType, amount }: FeeCardProps) {
const matchFeeType = match<FeeTypes>();
const feeIcon = matchFeeType<ReactNode>(feeType, {
[FeeTypes.Low]: <AnimalSnailIcon />,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { t } from '@lingui/macro';

import { AddressDisplayer, Avatar, Flag, Text, UsersTwoIcon } from '@leather.io/ui/native';

function BitcoinAddress({ address }: { address: string }) {
return (
<Flag
py="3"
img={
<Avatar bg="ink.background-secondary">
<UsersTwoIcon />
</Avatar>
}
>
<AddressDisplayer address={address} />
</Flag>
);
}
export function OutcomeAddressesCard({ addresses }: { addresses: string[] }) {
return (
<>
<Text variant="label01">
{t({
id: 'approver.outcomes.title2',
message: 'To address',
})}
</Text>
{addresses.map(address => (
<BitcoinAddress key={address} address={address} />
))}
</>
);
}
9 changes: 5 additions & 4 deletions apps/mobile/src/features/psbt-signer/psbt-signer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { useMemo, useState } from 'react';

import { formatBalance } from '@/components/balance/balance';
import { ApproverAccountCard } from '@/features/approver/components/approver-account-card';
import { BitcoinOutcome } from '@/features/approver/components/bitcoin-outcome';
import { FeeCard } from '@/features/approver/components/fee-card';
import { InputsAndOutputsCard } from '@/features/approver/components/inputs-outputs-card';
import { BitcoinOutcome, OutcomeAddressesCard } from '@/features/approver/components/outcomes-card';
import { OutcomeAddressesCard } from '@/features/approver/components/outcome-addresses-card';
import { useBtcMarketDataQuery } from '@/queries/market-data/btc-market-data.query';
import { t } from '@lingui/macro';

Expand All @@ -27,7 +28,7 @@ interface PsbtSignerProps {
}

export function PsbtSigner({ psbtHex, onEdit, onSuccess }: PsbtSignerProps) {
const net = useCurrentNetworkState();
const network = useCurrentNetworkState();
const psbtAccounts = usePsbtAccounts({ psbtHex });
const psbtPayers = usePsbtPayers({ psbtHex });
const psbtAddresses = psbtPayers.map(payer => payer.address);
Expand All @@ -41,9 +42,9 @@ export function PsbtSigner({ psbtHex, onEdit, onSuccess }: PsbtSignerProps) {
getPsbtDetails({
psbtHex,
psbtAddresses,
networkMode: net.chain.bitcoin.mode,
networkMode: network.chain.bitcoin.mode,
}),
[psbtHex, net, psbtAddresses]
[psbtHex, network, psbtAddresses]
);
const totalBtc = sumMoney([
psbtDetails.addressNativeSegwitTotal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export function SendFormAsset<T extends SendFormBaseContext<T>>({
icon={icon}
ticker={symbol}
tokenName={name}
px="3"
py="3"
/>
</Box>
</Pressable>
Expand Down

0 comments on commit 8f594ca

Please sign in to comment.