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

v4 fix: issues OK-25767 OK-26275 #4303

Merged
merged 3 commits into from
Mar 21, 2024
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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@
"@cmdcode/crypto-utils": "1.9.5",
"@cmdcode/tapscript": "1.2.9",
"@legendapp/state": "^1.2.9",
"@onekeyfe/cross-inpage-provider-core": "1.1.55",
"@onekeyfe/cross-inpage-provider-errors": "1.1.55",
"@onekeyfe/cross-inpage-provider-injected": "1.1.55",
"@onekeyfe/cross-inpage-provider-types": "1.1.55",
"@onekeyfe/extension-bridge-hosted": "1.1.55",
"@onekeyfe/cross-inpage-provider-core": "1.1.56",
"@onekeyfe/cross-inpage-provider-errors": "1.1.56",
"@onekeyfe/cross-inpage-provider-injected": "1.1.56",
"@onekeyfe/cross-inpage-provider-types": "1.1.56",
"@onekeyfe/extension-bridge-hosted": "1.1.56",
"@onekeyfe/hd-ble-sdk": "0.3.41",
"@onekeyfe/hd-core": "0.3.41",
"@onekeyfe/hd-shared": "0.3.41",
"@onekeyfe/hd-transport": "0.3.41",
"@onekeyfe/hd-web-sdk": "0.3.41",
"@onekeyfe/onekey-cross-webview": "1.1.55",
"@onekeyfe/onekey-cross-webview": "1.1.56",
"@starcoin/starcoin": "2.1.5",
"@web3-react/core": "8.0.35-beta.0",
"@web3-react/empty": "8.0.20-beta.0",
Expand Down
19 changes: 18 additions & 1 deletion packages/engine/src/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const endpointsMap: Record<
'fiat' | 'wss' | 'covalent' | 'mempool' | 'getblock' | 'algosigner',
| 'fiat'
| 'wss'
| 'covalent'
| 'mempool'
| 'getblock'
| 'algosigner'
| 'tronscan'
| 'solscan',
{ prd: string; test: string }
> = {
fiat: {
Expand Down Expand Up @@ -27,6 +34,14 @@ const endpointsMap: Record<
prd: 'https://node.onekey.so/algosigner/{network}/indexer',
test: 'https://node.onekeytest.com/algosigner/{network}/indexer',
},
tronscan: {
prd: 'https://node.onekey.so/tronscan',
test: 'https://node.onekeytest.com/tronscan',
},
solscan: {
prd: 'https://node.onekey.so/solscan',
test: 'https://node.onekeytest.com/solscan',
},
};

let endpointType: 'prd' | 'test' = 'prd';
Expand All @@ -39,6 +54,8 @@ switchTestEndpoint(false);
export const getFiatEndpoint = () => endpointsMap.fiat[endpointType];
export const getSocketEndpoint = () => endpointsMap.wss[endpointType];
export const getCovalentApiEndpoint = () => endpointsMap.covalent[endpointType];
export const getTronScanEndpoint = () => endpointsMap.tronscan[endpointType];
export const getSolScanEndpoint = () => endpointsMap.solscan[endpointType];

export function getMempoolEndpoint({
network,
Expand Down
25 changes: 25 additions & 0 deletions packages/engine/src/vaults/impl/sol/sdk/ClientSol.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// eslint-disable-next-line @typescript-eslint/naming-convention
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
import axios from 'axios';
import BigNumber from 'bignumber.js';
import { map, max } from 'lodash';

import { BaseClient } from '@onekeyhq/engine/src/client/BaseClient';
import { JsonRPCRequest } from '@onekeyhq/shared/src/request/JsonRPCRequest';

import { getSolScanEndpoint } from '../../../../endpoint';
import { TransactionStatus } from '../../../../types/provider';

import type { CoinInfo } from '../../../../types/chain';
Expand All @@ -15,6 +17,7 @@ import type {
FeePricePerUnit,
PartialTokenInfo,
} from '../../../../types/provider';
import type { ISolScanTokenMeta } from '../types';
import type { AccountInfo, PublicKey } from '@solana/web3.js';

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down Expand Up @@ -307,6 +310,28 @@ export class ClientSol extends BaseClient {
override getTokenInfos = async (
tokenAddresses: Array<string>,
): Promise<Array<PartialTokenInfo | undefined>> => {
const endpoint = getSolScanEndpoint();
try {
const tokensMeta = map(
await Promise.all(
tokenAddresses.map((tokenAddress) =>
axios.get<ISolScanTokenMeta>(`${endpoint}/v1.0/token/meta`, {
params: { tokenAddress },
}),
),
),
'data',
);

return tokensMeta.map((tokenMeta) => ({
...tokenMeta,
logoURI: tokenMeta.icon || '',
}));
} catch {
// pass
}

// fallback to rpc
const calls: any = tokenAddresses.map((address) => [
RPC_METHODS.GET_ACCOUNT_INFO,
[address, { encoding: PARAMS_ENCODINGS.JSON_PARSED }],
Expand Down
11 changes: 11 additions & 0 deletions packages/engine/src/vaults/impl/sol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ export type AssociatedTokenInfo = {
mint: string;
owner: string;
};

export type ISolScanTokenMeta = {
name: string;
symbol: string;
icon: string;
price: number;
decimals: number;
supply: number;
type: string;
address: string;
};
5 changes: 2 additions & 3 deletions packages/engine/src/vaults/impl/tron/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import debugLogger from '@onekeyhq/shared/src/logger/debugLogger';
import { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils';
import { fromBigIntHex } from '@onekeyhq/shared/src/utils/numberUtils';

import { getTronScanEndpoint } from '../../../endpoint';
import {
InsufficientBalance,
InvalidAddress,
Expand Down Expand Up @@ -56,7 +57,6 @@ import type {
IUnsignedTxPro,
} from '../../types';
import type {
IClientApi,
IEncodedTxTron,
IOnChainInternalTxHistory,
IOnChainTransferHistory,
Expand Down Expand Up @@ -114,8 +114,7 @@ export default class Vault extends VaultBase {
);

async getApiExplorer() {
const clientApi = await this.getClientApi<IClientApi>();
return this.getApiExplorerCache(clientApi.tronscan);
return this.getApiExplorerCache(getTronScanEndpoint());
}

public async getClient() {
Expand Down
10 changes: 7 additions & 3 deletions packages/kit-bg/src/providers/ProviderApiBtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ class ProviderApiBtc extends ProviderApiBase {
route: '/tx/decode',
params: { psbtHex: psbt.toHex() },
})
).result;
).data;

const inputsToSign = getInputsToSignFromPsbt({
psbt,
Expand All @@ -548,14 +548,18 @@ class ProviderApiBtc extends ProviderApiBase {
path: '',
value: v.value.toString(),
inscriptions: v.inscriptions.map((i) =>
mapInscriptionToNFTBTCAssetModel(i),
mapInscriptionToNFTBTCAssetModel(
decodedPsbt.inscriptions[i.inscriptionId],
),
),
})),
outputs: decodedPsbt.outputInfos.map((v) => ({
...v,
value: v.value.toString(),
inscriptions: v.inscriptions.map((i) =>
mapInscriptionToNFTBTCAssetModel(i),
mapInscriptionToNFTBTCAssetModel(
decodedPsbt.inscriptions[i.inscriptionId],
),
),
})),
totalFee: decodedPsbt.fee,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export type DecodedPsbt = {
value: number;
inscriptions: Inscription[];
}[];
inscriptions: Record<string, Inscription>;
feeRate: string;
fee: string;
hasScammerAddress: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { NETWORK_TYPES, NetworkTypeEnum } from './ProviderApiBtc.types';

import type { InputToSign, Inscription } from './ProviderApiBtc.types';

export const OPENAPI_URL_MAINNET = 'https://unisat.io/wallet-api-v4';
export const OPENAPI_URL_TESTNET = 'https://unisat.io/testnet/wallet-api-v4';
export const OPENAPI_URL_MAINNET = 'https://wallet-api.unisat.io/v5';
export const OPENAPI_URL_TESTNET = 'https://wallet-api-testnet.unisat.io/v5';

export function toXOnly(pubKey: Buffer) {
return pubKey.length === 32 ? pubKey : pubKey.slice(1, 33);
Expand Down Expand Up @@ -63,7 +63,7 @@ export async function httpPost<T>({
route: string;
params: any;
}) {
const url = isTestnet ? OPENAPI_URL_TESTNET : OPENAPI_URL_MAINNET + route;
const url = (isTestnet ? OPENAPI_URL_TESTNET : OPENAPI_URL_MAINNET) + route;
const headers = new Headers();
headers.append('X-Client', 'UniSat Wallet');
headers.append('X-Version', '1.0.0');
Expand All @@ -80,7 +80,7 @@ export async function httpPost<T>({
const data = (await res.json()) as {
status: string;
message: string;
result: T;
data: T;
};

if (data.status === '0') {
Expand Down
Loading
Loading