Skip to content

Commit

Permalink
Ok-6797 hide blockchain browser button when blockchain explore url is…
Browse files Browse the repository at this point in the history
… undefined (OneKeyHQ#644)

* OK-6797: hide blockchain browser button when blockchain explore url is undefined

* OK-8064: increase clickable area for swap Max button
  • Loading branch information
kwoktung committed Apr 28, 2022
1 parent c42958d commit 5927cc7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 59 deletions.
9 changes: 6 additions & 3 deletions packages/kit/src/views/Swap/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ const Setting = () => {
<HStack space="1">
<Pressable
onPress={() => onChange('1')}
width="9"
width="10"
h="7"
bg="surface-neutral-subdued"
_pressed={{ bg: 'surface-selected' }}
borderRadius="full"
alignItems="center"
justifyContent="center"
Expand All @@ -75,9 +76,10 @@ const Setting = () => {
</Pressable>
<Pressable
onPress={() => onChange('2')}
width="9"
width="10"
h="7"
bg="surface-neutral-subdued"
_pressed={{ bg: 'surface-selected' }}
borderRadius="full"
alignItems="center"
justifyContent="center"
Expand All @@ -86,9 +88,10 @@ const Setting = () => {
</Pressable>
<Pressable
onPress={() => onChange('3')}
width="9"
width="10"
h="7"
bg="surface-neutral-subdued"
_pressed={{ bg: 'surface-selected' }}
borderRadius="full"
alignItems="center"
justifyContent="center"
Expand Down
23 changes: 14 additions & 9 deletions packages/kit/src/views/Swap/components/TokenInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,21 @@ const TokenInput: FC<TokenInputProps> = ({
mb="2"
>
<Typography.Body2 color="text-subdued">{label}</Typography.Body2>
<Box flexDirection="row" alignItems="center">
<Typography.Body2 color="text-subdued">
{intl.formatMessage({ id: 'content__balance_str' }, { '0': text })}
</Typography.Body2>
{token && Number(value) > 0 && showMax ? (
<Typography.Body2 color="text-success" ml="2" onPress={onMax}>
Max
<Pressable onPress={onMax}>
<Box flexDirection="row" alignItems="center">
<Typography.Body2 color="text-subdued">
{intl.formatMessage(
{ id: 'content__balance_str' },
{ '0': text },
)}
</Typography.Body2>
) : null}
</Box>
{token && Number(value) > 0 && showMax ? (
<Typography.Body2 color="text-success" ml="2">
Max
</Typography.Body2>
) : null}
</Box>
</Pressable>
</Box>
<Box
display="flex"
Expand Down
2 changes: 0 additions & 2 deletions packages/kit/src/views/Swap/hooks/useSwap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export function useTokenAllowance(token?: Token, spender?: string) {
accountId,
tokenIdOnNetwork: token?.tokenIdOnNetwork,
});
console.log('allowanceData', allowanceData);
if (allowanceData !== undefined) {
const number = new TokenAmount(token, allowanceData).toNumber();
setAllowance(number);
Expand All @@ -279,7 +278,6 @@ export function useApproveState(
target?: string,
) {
const allowance = useTokenAllowance(token, spender);
console.log('allowance', allowance?.toFixed());
const pendingApproval = useHasPendingApproval(
token?.tokenIdOnNetwork,
spender,
Expand Down
63 changes: 18 additions & 45 deletions packages/kit/src/views/Wallet/HistoricalRecords/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
import React, { FC, useCallback, useMemo } from 'react';

import { useNavigation } from '@react-navigation/native';
import { useIntl } from 'react-intl';
Expand All @@ -17,9 +17,7 @@ import {
Typography,
} from '@onekeyhq/components';
import { Tabs } from '@onekeyhq/components/src/CollapsibleTabView';
import { Account } from '@onekeyhq/engine/src/types/account';
import { Transaction, TxStatus } from '@onekeyhq/engine/src/types/covalent';
import { Network } from '@onekeyhq/engine/src/types/network';
import IconHistory from '@onekeyhq/kit/assets/3d_transaction_history.png';
import useOpenBlockBrowser from '@onekeyhq/kit/src/hooks/useOpenBlockBrowser';
import { TransactionDetailRoutesParams } from '@onekeyhq/kit/src/routes';
Expand All @@ -30,7 +28,7 @@ import {
RootRoutes,
} from '@onekeyhq/kit/src/routes/types';

import backgroundApiProxy from '../../../background/instance/backgroundApiProxy';
import { useActiveWalletAccount } from '../../../hooks/redux';
import TransactionRecord from '../../Components/transactionRecord';

import { useHistoricalRecordsData } from './useHistoricalRecordsData';
Expand All @@ -52,17 +50,13 @@ const defaultProps = {
} as const;

const HistoricalRecords: FC<HistoricalRecordProps> = ({
accountId,
networkId,
tokenId,
headerView,
isTab,
}) => {
const intl = useIntl();
const navigation = useNavigation<NavigationProp['navigation']>();

const [account, setAccount] = useState<Account>();
const [network, setNetwork] = useState<Network>();
const { network, account } = useActiveWalletAccount();

const openBlockBrowser = useOpenBlockBrowser(network);
const { transactionRecords, isLoading, loadMore, fetchData } =
Expand All @@ -79,29 +73,6 @@ const HistoricalRecords: FC<HistoricalRecordProps> = ({
[loadMore],
);

useEffect(() => {
async function loadAccount() {
if (!accountId) return;

const accounts = await backgroundApiProxy.engine.getAccounts([accountId]);
if (accounts && accounts.length > 0) {
setAccount(accounts[0]);
}
}
async function loadNetwork() {
if (!networkId) return;

const localNetwork = await backgroundApiProxy.engine.getNetwork(
networkId,
);
if (localNetwork) {
setNetwork(localNetwork);
}
}
loadNetwork();
loadAccount();
}, [accountId, networkId]);

const refreshData = useCallback(() => {
fetchData?.();
}, [fetchData]);
Expand Down Expand Up @@ -129,7 +100,7 @@ const HistoricalRecords: FC<HistoricalRecordProps> = ({
});
}}
>
<TransactionRecord transaction={item} network={network} />
<TransactionRecord transaction={item} network={network ?? undefined} />
</Pressable.Item>
);

Expand Down Expand Up @@ -176,18 +147,19 @@ const HistoricalRecords: FC<HistoricalRecordProps> = ({
type="plain"
circle
/>

<IconButton
onPress={() => {
openBlockBrowser.openAddressDetails(account?.address);
}}
ml={3}
p={2}
size="sm"
name="ExternalLinkSolid"
type="plain"
circle
/>
{network?.blockExplorerURL.address ? (
<IconButton
onPress={() => {
openBlockBrowser.openAddressDetails(account?.address);
}}
ml={3}
p={2}
size="sm"
name="ExternalLinkSolid"
type="plain"
circle
/>
) : null}
</Box>
</Box>
)}
Expand All @@ -200,6 +172,7 @@ const HistoricalRecords: FC<HistoricalRecordProps> = ({
isLoading,
openBlockBrowser,
refreshData,
network,
transactionRecords.length,
],
);
Expand Down

0 comments on commit 5927cc7

Please sign in to comment.