-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tokens widget, ref leather-io/issues#221
- Loading branch information
1 parent
714fff0
commit 69e4377
Showing
46 changed files
with
933 additions
and
1,057 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
apps/mobile/src/components/widgets/account/account-balance.tsx
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
apps/mobile/src/components/widgets/account/utils/format-balance.spec.ts
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
apps/mobile/src/components/widgets/account/utils/format-balance.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions
49
apps/mobile/src/components/widgets/components/balance/fiat-balance.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { useMemo } from 'react'; | ||
|
||
import { t } from '@lingui/macro'; | ||
|
||
import { BulletSeparator, Text, TextProps } from '@leather.io/ui/native'; | ||
import { formatBalance } from '@leather.io/utils'; | ||
|
||
interface FiatBalanceProps { | ||
balance: number | string; | ||
lockedBalance?: string; | ||
variant?: TextProps['variant']; | ||
color?: TextProps['color']; | ||
} | ||
|
||
export function FiatBalance({ | ||
balance, | ||
lockedBalance, | ||
variant = 'label01', | ||
color = 'ink.text-primary', | ||
}: FiatBalanceProps) { | ||
// FIXME: currencyLabel should be dynamic based on the user's currency | ||
const currencyLabel = '$'; | ||
const formattedBalance = useMemo( | ||
() => | ||
typeof balance === 'number' | ||
? `${currencyLabel}${formatBalance(balance.toString()).value}` | ||
: balance, | ||
[balance] | ||
); | ||
|
||
if (!lockedBalance) { | ||
return ( | ||
<Text variant={variant} color={color}> | ||
{formattedBalance} | ||
</Text> | ||
); | ||
} | ||
|
||
return ( | ||
<BulletSeparator color={color}> | ||
<Text variant={variant} color={color}> | ||
{formattedBalance} | ||
</Text> | ||
<Text variant={variant} color={color}> | ||
{lockedBalance} {t`locked`} | ||
</Text> | ||
</BulletSeparator> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/mobile/src/components/widgets/components/balance/format-locked-balance.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { Money } from '@leather.io/models'; | ||
|
||
export function formatLockedBalance(balance: Money) { | ||
if (!balance || !balance.amount || !balance.decimals) return undefined; | ||
|
||
const amount = new BigNumber(balance.amount).dividedBy(new BigNumber(10).pow(balance.decimals)); | ||
return amount.toFixed().replace(/\.?0+$/, ''); | ||
} |
25 changes: 25 additions & 0 deletions
25
apps/mobile/src/components/widgets/components/balance/token-balance.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
|
||
import { t } from '@lingui/macro'; | ||
|
||
import { BulletSeparator, Text } from '@leather.io/ui/native'; | ||
|
||
interface TokenBalanceProps { | ||
balance: string; | ||
lockedBalance?: string; | ||
} | ||
|
||
export function TokenBalance({ balance, lockedBalance }: TokenBalanceProps) { | ||
if (!lockedBalance) { | ||
return <Text variant="label01">{balance}</Text>; | ||
} | ||
|
||
return ( | ||
<BulletSeparator> | ||
<Text variant="label01">{balance}</Text> | ||
<Text variant="label01"> | ||
{lockedBalance} {t`locked`} | ||
</Text> | ||
</BulletSeparator> | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
apps/mobile/src/components/widgets/tokens/tokens-header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
|
||
import { t } from '@lingui/macro'; | ||
|
||
import { Box, ChevronRightIcon, Chip, SheetRef, Text } from '@leather.io/ui/native'; | ||
|
||
import { FiatBalance } from '../components/balance/fiat-balance'; | ||
|
||
type Token = Record<string, unknown>; | ||
|
||
interface TokensHeaderProps { | ||
tokens: Token[]; | ||
sheetRef: React.RefObject<SheetRef>; | ||
totalBalance: string; | ||
} | ||
|
||
function TokensHeaderText() { | ||
return <Text variant="heading05">{t`My tokens`}</Text>; | ||
} | ||
|
||
export function TokensHeader({ tokens, totalBalance }: TokensHeaderProps) { | ||
const tokenCount = tokens.length; | ||
const hasTokens = tokenCount > 0; | ||
if (!hasTokens) return <TokensHeaderText />; | ||
return ( | ||
<Box flexDirection="row" gap="1" alignItems="center" marginHorizontal="5"> | ||
<TokensHeaderText /> | ||
<Chip label={tokenCount} /> | ||
<ChevronRightIcon variant="small" /> | ||
<Box flex={1} justifyContent="flex-end" alignItems="flex-end"> | ||
<FiatBalance balance={totalBalance} color="ink.text-subdued" /> | ||
</Box> | ||
</Box> | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
apps/mobile/src/components/widgets/tokens/tokens-widget.layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { ScrollView } from 'react-native-gesture-handler'; | ||
|
||
import { useTheme } from '@shopify/restyle'; | ||
|
||
import { Box, SheetRef, Theme } from '@leather.io/ui/native'; | ||
|
||
import { Widget } from '../widget'; | ||
|
||
interface TokensWidgetLayoutProps { | ||
balance?: React.ReactNode; | ||
children: React.ReactNode; | ||
header?: React.ReactNode; | ||
sheetRef?: React.RefObject<SheetRef>; | ||
} | ||
|
||
export function TokensWidgetLayout({ children, header }: TokensWidgetLayoutProps) { | ||
const theme = useTheme<Theme>(); | ||
return ( | ||
<Widget> | ||
<Box>{header}</Box> | ||
<ScrollView | ||
contentContainerStyle={{ gap: theme.spacing['3'], marginHorizontal: theme.spacing['5'] }} | ||
> | ||
{children} | ||
</ScrollView> | ||
</Widget> | ||
); | ||
} |
Oops, something went wrong.