Skip to content

Commit

Permalink
fix: issues OK-23601 OK-23534 OK-23530 OK-23505 (#3618)
Browse files Browse the repository at this point in the history
* fix: nonce error when claim on chainspot

* fix: recovery phrase form did not reset after clean inputs

* fix: can't sign psbt tx with non-taproot address

* fix: only show btc spendable balance

* fix: lint

* fix: only filter unconfirmed utxos for btc network in coin control
  • Loading branch information
weatherstar authored Oct 9, 2023
1 parent b84308d commit 9c63eee
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ class Provider {
signer,
psbt.data.inputs[input.index],
);
psbt.signInput(input.index, bitcoinSigner, input.sighashTypes);
await psbt.signInputAsync(input.index, bitcoinSigner, input.sighashTypes);
}
return {
txid: '',
Expand Down
9 changes: 9 additions & 0 deletions packages/kit-bg/src/providers/ProviderApiEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ class ProviderApiEthereum extends ProviderApiBase {
if (!isNil(transaction.value)) {
transaction.value = prefixTxValueToHex(transaction.value);
}

const nonceBN = new BigNumber(transaction.nonce ?? 0);

// https://app.chainspot.io/
// some dapp may send tx with incorrect nonce 0
if (nonceBN.isNaN() || nonceBN.isLessThanOrEqualTo(0)) {
delete transaction.nonce;
}

const result = await this.backgroundApi.serviceDapp?.openSignAndSendModal(
request,
{
Expand Down
6 changes: 5 additions & 1 deletion packages/kit-bg/src/services/ServiceUtxos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
backgroundClass,
backgroundMethod,
} from '@onekeyhq/shared/src/background/backgroundDecorators';
import { isBTCNetwork } from '@onekeyhq/shared/src/engine/engineConsts';
import { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils';

import ServiceBase from './ServiceBase';
Expand Down Expand Up @@ -184,7 +185,10 @@ export default class ServiceUtxos extends ServiceBase {

const utxos: ICoinControlListItem[] = btcUtxos
.filter((utxo) =>
new BigNumber(utxo?.confirmations ?? 0).isGreaterThan(0),
// only filter unconfirmed utxos for btc network
isBTCNetwork(networkId)
? new BigNumber(utxo?.confirmations ?? 0).isGreaterThan(0)
: true,
)
.map((utxo) => {
const archivedUtxo = archivedUtxos.find(
Expand Down
39 changes: 35 additions & 4 deletions packages/kit/src/hooks/useOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
} from '@onekeyhq/engine/src/types/token';
import KeleLogoPNG from '@onekeyhq/kit/assets/staking/kele_pool.png';
import { freezedEmptyArray } from '@onekeyhq/shared/src/consts/sharedConsts';
import { isBTCNetwork } from '@onekeyhq/shared/src/engine/engineConsts';

import backgroundApiProxy from '../background/instance/backgroundApiProxy';
import { ModalRoutes, RootRoutes } from '../routes/routesEnum';
Expand Down Expand Up @@ -434,6 +435,13 @@ export const useTokenPositionInfo = ({
},
);

const frozenBalance = useFrozenBalance({
networkId,
accountId,
tokenId: tokenAddress || 'main',
useRecycleBalance: true,
});

return useMemo(() => {
if (!result) {
return {
Expand All @@ -450,6 +458,15 @@ export const useTokenPositionInfo = ({
}
const { totalBalance, keleStakingBalance, items } = result;

let finalTotalBalance = new B(totalBalance);

if (isBTCNetwork(networkId) && !tokenAddress) {
finalTotalBalance = finalTotalBalance.minus(frozenBalance);
finalTotalBalance = finalTotalBalance.isGreaterThan(0)
? finalTotalBalance
: new B(0);
}

if (new B(keleStakingBalance)?.gt(0)) {
items.push({
name: 'Kelepool',
Expand All @@ -465,7 +482,7 @@ export const useTokenPositionInfo = ({

return {
isLoading,
balance: new B(totalBalance),
balance: new B(finalTotalBalance),
detailInfo: result.detailInfo,
items: items.map((item) => {
if (item.poolCode && item.protocol) {
Expand All @@ -478,16 +495,30 @@ export const useTokenPositionInfo = ({
}),
};
}

if (isBTCNetwork(item.networkId) && !item.address) {
let finalBalance = new B(item.balance).minus(frozenBalance);
finalBalance = finalBalance.isGreaterThan(0)
? finalBalance
: new B(0);
return {
...item,
balance: finalBalance.toFixed(),
};
}

return item;
}),
};
}, [
result,
networkId,
tokenAddress,
isLoading,
defaultInfo,
frozenBalance,
intl,
onPressStaking,
onPresDefiProtocol,
networkId,
defaultInfo,
isLoading,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const NineHouseLatticeInputForm: FC<NineHouseLatticeInputFormProps> = ({
trigger,
register,
getValues,
reset,
} = useForm({
mode: 'onBlur',
reValidateMode: 'onBlur',
Expand Down Expand Up @@ -163,6 +164,7 @@ export const NineHouseLatticeInputForm: FC<NineHouseLatticeInputFormProps> = ({
onPress={() => {
onClear();
setFocus(`${inputIndexArray?.[0] ?? 1}`);
reset();
}}
>
<Icon color="icon-subdued" size={16} name="XCircleMini" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export function BaseSendConfirmModal(props: ITxConfirmViewProps) {
if (sourceInfo) {
let nativeBalanceTransferBN = new BigNumber(0);
for (const action of (decodedTx as IDecodedTx)?.actions ?? []) {
if (action.type === IDecodedTxActionType.NATIVE_TRANSFER) {
if (
action.type === IDecodedTxActionType.NATIVE_TRANSFER &&
action.direction === IDecodedTxDirection.OUT
) {
nativeBalanceTransferBN = nativeBalanceTransferBN.plus(
action.nativeTransfer?.amount ?? 0,
);
Expand Down
26 changes: 24 additions & 2 deletions packages/kit/src/views/Wallet/AssetsList/TokenCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@onekeyhq/components';
import { withDebugRenderTracker } from '@onekeyhq/components/src/DebugRenderTracker';
import type { ITokenFiatValuesInfo } from '@onekeyhq/engine/src/types/token';
import { isBTCNetwork } from '@onekeyhq/shared/src/engine/engineConsts';
import { AppUIEventBusNames } from '@onekeyhq/shared/src/eventBus/appUIEventBus';
import { isBRC20Token } from '@onekeyhq/shared/src/utils/tokenUtils';

Expand All @@ -29,6 +30,7 @@ import {
useReduxSingleTokenPriceSimple,
} from '../../../hooks';
import { useOnUIEventBus } from '../../../hooks/useOnUIEventBus';
import { useFrozenBalance } from '../../../hooks/useTokens';
import {
CValueLoading,
type ITokenPriceValue,
Expand Down Expand Up @@ -98,12 +100,32 @@ function TokenCellBalance({
showTokenBalanceDetail?: boolean;
}) {
const intl = useIntl();
const { networkId, accountId, symbol } = token;
const { networkId, accountId, symbol, isNative } = token;
const { network, account } = useActiveSideAccount({ accountId, networkId });
const [recycleBalance, setRecycleBalance] = useState('0');
const tokenId = token?.address || 'main';
const isBRC20 = useMemo(() => isBRC20Token(tokenId), [tokenId]);

const frozenBalance = useFrozenBalance({
networkId,
accountId,
tokenId: 'main',
useRecycleBalance: true,
});

const finalBalance = useMemo(() => {
if (isBTCNetwork(networkId) && isNative) {
const spendableBalanceBN = new BigNumber(balance ?? '0').minus(
frozenBalance,
);

return spendableBalanceBN.isGreaterThanOrEqualTo(0)
? spendableBalanceBN.toFixed()
: '0';
}
return balance;
}, [networkId, isNative, balance, frozenBalance]);

const displayDecimal = useMemo(
() =>
tokenId === 'main'
Expand Down Expand Up @@ -167,7 +189,7 @@ function TokenCellBalance({
return (
<FormatBalance
balance={BigNumber.max(
new BigNumber(balance ?? '0').minus(recycleBalance),
new BigNumber(finalBalance ?? '0').minus(recycleBalance),
'0',
).toFixed()}
suffix={symbol}
Expand Down

0 comments on commit 9c63eee

Please sign in to comment.