Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issues OK-23571 OK-23568 OK-23553 OK-23539 #3601

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/engine/src/vaults/impl/tron/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ export default class Vault extends VaultBase {
}
});

const finanlTransferHistory = (
const finalTransferHistory = (
await Promise.all(transferHistoryPromises)
).filter(Boolean);
const finalTxHistory = (await Promise.all(txHistoryPromises)).filter(
Expand All @@ -1380,11 +1380,7 @@ export default class Vault extends VaultBase {
await Promise.all(internalTxHistoryPromises)
).filter(Boolean);

return [
...finanlTransferHistory,
...finalTxHistory,
...finalInterTxHistory,
];
return [...finalTransferHistory, ...finalTxHistory, ...finalInterTxHistory];
}

override async proxyJsonRPCCall<T>(request: IJsonRpcRequest): Promise<T> {
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/src/vaults/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,15 @@ export type IDecodedTxActionInscription = IDecodedTxActionBase & {
send: string;
receive: string;
isInscribeTransfer?: boolean;
assetsInSameUtxo?: NFTBTCAssetModel[];
};

export type IDecodedTxActionBRC20 = IDecodedTxActionBase & {
token: Token;
sender: string;
receiver: string;
asset: NFTBTCAssetModel;
assetsInSameUtxo?: NFTBTCAssetModel[];
amount?: string;
max?: string;
limit?: string;
Expand Down
17 changes: 16 additions & 1 deletion packages/engine/src/vaults/utils/btcForkChain/VaultBtcFork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
import { getAccountNameInfoByTemplate } from '../../../managers/impl';
import {
batchAsset,
getAllAssetsFromLocal,
getBRC20TransactionHistory,
getNFTTransactionHistory,
} from '../../../managers/nft';
Expand Down Expand Up @@ -735,14 +736,15 @@ export default class VaultBtcFork extends VaultBase {
return action;
}

buildNFTAction({
async buildNFTAction({
nftInfo,
dbAccount,
}: {
nftInfo: INFTInfo;
dbAccount: DBUTXOAccount;
}) {
const { from, to } = nftInfo;
const asset = nftInfo.asset as NFTBTCAssetModel;

let direction = IDecodedTxDirection.OTHER;

Expand All @@ -754,13 +756,26 @@ export default class VaultBtcFork extends VaultBase {
direction = IDecodedTxDirection.IN;
}

const localNFTs = (await getAllAssetsFromLocal({
networkId: this.networkId,
accountId: this.accountId,
})) as NFTBTCAssetModel[];
const inscriptionsInSameUtxo = localNFTs.filter(
(nft) =>
nft.inscription_id !== asset.inscription_id &&
nft.owner === asset.owner &&
nft.output === asset.output &&
nft.output_value_sat === asset.output_value_sat,
);

const action: IDecodedTxAction = {
type: IDecodedTxActionType.NFT_TRANSFER_BTC,
direction,
inscriptionInfo: {
send: nftInfo.from,
receive: nftInfo?.to,
asset: nftInfo?.asset as NFTBTCAssetModel,
assetsInSameUtxo: inscriptionsInSameUtxo,
extraInfo: null,
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/components/Format/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export function FormatBalanceTokenOfAccount({
accountId,
token,
fallback: '0',
useRecycleBalance: useRecycleBalance ?? token?.isNative,
useRecycleBalance: useRecycleBalance ?? token?.isNative ?? true,
useCustomAddressesBalance,
});

Expand Down
13 changes: 12 additions & 1 deletion packages/kit/src/hooks/useOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ export const useTokenBalance = ({
accountId,
token,
fallback = '0',
useRecycleBalance,
useCustomAddressesBalance,
}: {
networkId: string;
accountId: string;
token?: Partial<Token> | null;
fallback?: string;
useRecycleBalance?: boolean;
useCustomAddressesBalance?: boolean;
}) => {
const balances = useAppSelector((s) => s.tokens.accountTokensBalance);
Expand All @@ -274,11 +276,18 @@ export const useTokenBalance = ({
networkId,
accountId,
useCustomAddressesBalance,
useRecycleBalance,
})
.then((value) => {
setManuallyAddedAddressBalance(value?.available ?? fallback);
});
}, [networkId, accountId, useCustomAddressesBalance, fallback]);
}, [
networkId,
accountId,
useCustomAddressesBalance,
fallback,
useRecycleBalance,
]);

if (isAllNetworks(networkId)) {
throw new Error(`useTokenBalance: networkId is not valid: ${networkId}`);
Expand Down Expand Up @@ -323,8 +332,10 @@ export const useTokenBalanceWithoutFrozen = ({
accountId,
token,
fallback,
useRecycleBalance,
useCustomAddressesBalance,
});

const frozenBalance = useFrozenBalance({
networkId,
accountId,
Expand Down
61 changes: 38 additions & 23 deletions packages/kit/src/hooks/useTokens.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';

import { pick } from 'lodash';

import type { Token } from '@onekeyhq/engine/src/types/token';
import { useActiveWalletAccount } from '@onekeyhq/kit/src/hooks';
import { AppUIEventBusNames } from '@onekeyhq/shared/src/eventBus/appUIEventBus';
import debugLogger from '@onekeyhq/shared/src/logger/debugLogger';

import backgroundApiProxy from '../background/instance/backgroundApiProxy';
import { appSelector } from '../store';
import { createDeepEqualSelector } from '../utils/reselectUtils';

import { useShouldHideInscriptions } from './crossHooks/useShouldHideInscriptions';
import { useAppSelector } from './useAppSelector';
import { useOnUIEventBus } from './useOnUIEventBus';

import type { IAppState } from '../store';

Expand Down Expand Up @@ -127,31 +130,43 @@ export const useFrozenBalance = ({
number | Record<string, number>
>(0);

useEffect(() => {
(async () => {
let password;
const shouldHideInscriptions = useShouldHideInscriptions({
accountId,
networkId,
});

const vaultSettings = await backgroundApiProxy.engine.getVaultSettings(
const fetchFrozenBalance = useCallback(async () => {
let password;

const vaultSettings = await backgroundApiProxy.engine.getVaultSettings(
networkId,
);
if (vaultSettings.validationRequired) {
password = await backgroundApiProxy.servicePassword.getPassword();
}

backgroundApiProxy.engine
.getFrozenBalance({
accountId,
networkId,
);
if (vaultSettings.validationRequired) {
password = await backgroundApiProxy.servicePassword.getPassword();
}
password,
useRecycleBalance,
useCustomAddressesBalance,
})
.then(setFrozenBalance)
.catch((e) => {
debugLogger.common.error('getFrozenBalance error', e);
});
}, [accountId, networkId, useCustomAddressesBalance, useRecycleBalance]);

backgroundApiProxy.engine
.getFrozenBalance({
accountId,
networkId,
password,
useRecycleBalance,
useCustomAddressesBalance,
})
.then(setFrozenBalance)
.catch((e) => {
debugLogger.common.error('getFrozenBalance error', e);
});
})();
}, [networkId, accountId, useRecycleBalance, useCustomAddressesBalance]);
useOnUIEventBus(
AppUIEventBusNames.InscriptionRecycleChanged,
fetchFrozenBalance,
);

useEffect(() => {
fetchFrozenBalance();
}, [fetchFrozenBalance, shouldHideInscriptions]);

return useMemo(
() =>
Expand Down
14 changes: 7 additions & 7 deletions packages/kit/src/views/BulkSender/OneToMany/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function OneToMany(props: Props) {
const [isBuildingTx, setIsBuildingTx] = useState(false);
const [isUnlimited, setIsUnlimited] = useState(false);
const [isAlreadyUnlimited, setIsAlreadyUnlimited] = useState(false);
const [isfetchingAllowance, setIsFetchingAllowance] = useState(false);
const [isFetchingAllowance, setIsFetchingAllowance] = useState(false);

const [amountType, setAmountType] = useState<AmountTypeEnum>(
amountDefaultTypeMap[bulkType] ?? AmountTypeEnum.Fixed,
Expand All @@ -98,7 +98,7 @@ function OneToMany(props: Props) {
const currentToken = selectedToken || initialToken;
const isNative = currentToken?.isNative;

const tokenBalnace = useTokenBalanceWithoutFrozen({
const tokenBalance = useTokenBalanceWithoutFrozen({
accountId,
networkId,
token: currentToken,
Expand Down Expand Up @@ -176,7 +176,7 @@ function OneToMany(props: Props) {
new BigNumber(0),
);

if (totalAmount.gt(tokenBalnace)) {
if (totalAmount.gt(tokenBalance)) {
ToastManager.show(
{
title: intl.formatMessage(
Expand All @@ -191,7 +191,7 @@ function OneToMany(props: Props) {

return true;
},
[tokenBalnace, intl],
[tokenBalance, intl],
);

const handlePreviewTransfer = useCallback(async () => {
Expand Down Expand Up @@ -414,7 +414,7 @@ function OneToMany(props: Props) {
title={currentToken?.symbol ?? ''}
desc={intl.formatMessage(
{ id: 'content__balance_str' },
{ 0: tokenBalnace },
{ 0: tokenBalance },
)}
icon={<TokenIcon size={10} token={currentToken} />}
onPress={handleOpenTokenSelector}
Expand All @@ -431,7 +431,7 @@ function OneToMany(props: Props) {
/>
{!isNative && network?.settings.batchTransferApprovalRequired && (
<TxSettingTrigger
isLoading={isfetchingAllowance}
isLoading={isFetchingAllowance}
header={intl.formatMessage({ id: 'form__allowance' })}
title={intl.formatMessage({
id: isUnlimited ? 'form__unlimited' : 'form__exact_amount',
Expand Down Expand Up @@ -494,7 +494,7 @@ function OneToMany(props: Props) {
!isValid ||
receiver.length === 0 ||
isBuildingTx ||
isfetchingAllowance
isFetchingAllowance
}
type="primary"
size="xl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const ListRenderToken: FC<ListRenderTokenProps> = ({
networkId,
token,
fallback: '0',
useRecycleBalance: token?.isNative,
useRecycleBalance: token?.isNative ?? true,
});
const intl = useIntl();
const closeModal = useModalClose();
Expand Down
42 changes: 35 additions & 7 deletions packages/kit/src/views/BulkSender/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { useCallback, useLayoutEffect, useMemo } from 'react';
import {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useState,
} from 'react';

import { useNavigation } from '@react-navigation/core';
import { useRoute } from '@react-navigation/native';
Expand All @@ -10,6 +16,7 @@ import {
HStack,
IconButton,
ScrollView,
Spinner,
Text,
useIsVerticalLayout,
} from '@onekeyhq/components';
Expand Down Expand Up @@ -56,6 +63,7 @@ function BulkSender() {
const navigation = useNavigation<NavigationProps>();
const isVertical = useIsVerticalLayout();
const route = useRoute<RouteProps>();
const [initialized, setInitialized] = useState(false);

const routeParams = route.params;
const mode = routeParams?.mode;
Expand Down Expand Up @@ -181,12 +189,27 @@ function BulkSender() {
});
}, [headerLeft, headerRight, intl, isVertical, navigation, title]);

useEffect(() => {
if (accountId && networkId) {
setTimeout(() => setInitialized(true), 800);
} else {
setInitialized(false);
}
}, [accountId, networkId]);

if (!isSupported) return <NotSupported networkId={networkId} />;

if (selectedMode) {
if (!accountId || !networkId)
return (
<Center width="full" height="full">
<IdentityAssertion>
<IdentityAssertion />
</Center>
);

if (initialized) {
if (selectedMode)
return (
<Center width="full" height="full">
<ScrollView
style={{ width: '100%' }}
contentContainerStyle={{
Expand All @@ -202,12 +225,17 @@ function BulkSender() {
{renderBulkSenderPanel()}
</Box>
</ScrollView>
</IdentityAssertion>
</Center>
);
</Center>
);

return <ModelSelector networkId={networkId} />;
}

return <ModelSelector networkId={networkId} />;
return (
<Center width="full" height="full">
<Spinner />
</Center>
);
// const tabsHeader = useMemo(() => <BulkSenderHeader />, []);
// return (
// <Tabs.Container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
RootRoutes,
} from '@onekeyhq/kit/src/routes/routesEnum';
import type { ModalScreenProps } from '@onekeyhq/kit/src/routes/types';
import { OnekeyNetwork } from '@onekeyhq/shared/src/config/networkIds';
import supportedNFC from '@onekeyhq/shared/src/detector/nfc';
import { isBTCNetwork } from '@onekeyhq/shared/src/engine/engineConsts';
import debugLogger from '@onekeyhq/shared/src/logger/debugLogger';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const TokenListCell: FC<ListCellProps> = ({
networkId,
token,
fallback: '0',
useRecycleBalance: token.isNative ?? true,
});
const tokenId = token?.tokenIdOnNetwork || 'main';
const decimal =
Expand Down
Loading