Skip to content

Commit

Permalink
Merge branch 'onekey' into fix/generateMnemonic-length
Browse files Browse the repository at this point in the history
  • Loading branch information
sidmorizon authored Oct 11, 2023
2 parents 1b7d121 + 19872aa commit ae769b8
Show file tree
Hide file tree
Showing 14 changed files with 2,818 additions and 2,737 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@
"title__manage_utxos": "UTXOs verwalten",
"title__market": "Markt",
"title__me": "Mich",
"title__menu": "Speisekarte",
"title__menu": "Menü",
"title__migration": "Migration",
"title__migration_desc": "Migrieren Sie zwischen OneKey-Apps",
"title__my_dapps": "Meine Webseiten",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/locale/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@
"form__beginner_guide": "初心者案内",
"form__below_str": "{0}を下回る",
"form__best_rate": "👍 ベストレート",
"form__between_int_and_int_sats": "有効値は{min}と{max}stasの間になる",
"form__between_int_and_int_sats": "有効値は{min}と{max}satsの間になる",
"form__bip44_standard": "BIP44基準",
"form__bip44_standard_cointype_61": "BIP44 基準 (コインタイプ 61')",
"form__bip44_standard_desc": "OneKey, MetaMask, Trezor, imToken",
Expand Down
5,442 changes: 2,721 additions & 2,721 deletions packages/components/src/locale/pt_BR.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/engine/src/vaults/impl/lightning-network/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,15 @@ export default class Vault extends VaultBase {
}> {
const { invoice: payreq, amount, fee } = encodedTx;
const invoice = await this._decodedInvoceCache(payreq);
const network = await this.getNetwork();
let finalAmount = amount;
if (this.isZeroAmountInvoice(invoice)) {
if (new BigNumber(encodedTx.amount).isLessThan(1)) {
return Promise.resolve({
success: false,
key: 'msg__the_invoice_amount_cannot_be_0',
params: {
0: 'stas',
0: network.symbol,
},
});
}
Expand All @@ -661,7 +662,7 @@ export default class Vault extends VaultBase {
success: false,
key: 'form__amount_invalid',
params: {
0: 'stas',
0: network.symbol,
},
});
}
Expand Down
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
7 changes: 6 additions & 1 deletion packages/ext/src/entry/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ if (!platformEnv.isManifestV3) {
if (parsedUrl.pathname.includes('.')) return;
let indexHtml = getExtensionIndexHtml();
indexHtml = 'ui-expand-tab.html';
/*
check chrome.webRequest.onBeforeRequest
/ui-expand-tab.html/#/ not working for Windows Chrome
/ui-expand-tab.html#/ works fine
*/
const newUrl = chrome.runtime.getURL(
`/${indexHtml}/#${parsedUrl.pathname}${parsedUrl.query}`,
`/${indexHtml}#${parsedUrl.pathname}${parsedUrl.query}`,
);

return { redirectUrl: newUrl };
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
1 change: 0 additions & 1 deletion packages/kit/src/components/WebView/NativeWebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type NativeWebViewProps = WebViewProps & InpageProviderWebViewProps;

const styles = StyleSheet.create({
container: {
backgroundColor: 'transparent',
flex: 1,
},
});
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,
]);
};
7 changes: 6 additions & 1 deletion packages/kit/src/routes/linking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,12 @@ const buildLinking = (): LinkingOptions<any> => {
}
// keep manifest v3 url with html file
if (platformEnv.isExtChrome && platformEnv.isManifestV3) {
return `${extHtmlFileUrl}/#${newPath}`;
/*
check chrome.webRequest.onBeforeRequest
/ui-expand-tab.html/#/ not working for Windows Chrome
/ui-expand-tab.html#/ works fine
*/
return `${extHtmlFileUrl}#${newPath}`;
}
return newPath;
},
Expand Down
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 ae769b8

Please sign in to comment.