@toruslabs/base-controllers
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -42,2 +42,6 @@ import { BaseConfig, BaseState, IController } from "../interfaces"; | ||
displayName: string; | ||
/** | ||
* Whether the network is testnet or not | ||
*/ | ||
isTestnet?: boolean; | ||
} | ||
@@ -44,0 +48,0 @@ /** |
@@ -90,46 +90,3 @@ import BaseController from "../BaseController"; | ||
getDappList(): Promise<DiscoverDapp[]>; | ||
fetchEtherscanTx<T>(parameters: { | ||
selectedAddress: string; | ||
selectedNetwork: string; | ||
}): Promise<T[]>; | ||
getCovalentTokenBalances<T>(address: string, chainId: string): Promise<T>; | ||
getEthereumAssetData(parameters: { | ||
contract: string; | ||
tokenId: string; | ||
}): Promise<{ | ||
symbol: string; | ||
logo: string; | ||
name: string; | ||
description: string; | ||
}>; | ||
getCovalentAssetData(parameters: { | ||
contract: string; | ||
chainId: string; | ||
tokenId: string; | ||
}): Promise<{ | ||
name: string; | ||
logo: string; | ||
symbol: string; | ||
description: string; | ||
}>; | ||
getEthereumAssetContractData(parameters: { | ||
contract: string; | ||
}): Promise<{ | ||
symbol: string; | ||
logo: string; | ||
name: string; | ||
description: string; | ||
schema_name: string; | ||
}>; | ||
getCovalentAssetContractData(parameters: { | ||
contract: string; | ||
chainId: string; | ||
}): Promise<{ | ||
name: string; | ||
logo: string; | ||
symbol: string; | ||
description: string; | ||
schema_name: string; | ||
}>; | ||
protected init(address: string, userInfo: UserInfo, jwtToken?: string, pubKey?: string, type?: ACCOUNT_TYPE): Promise<void>; | ||
protected init(address: string, userInfo: UserInfo, jwtToken?: string, metadata?: Record<string, unknown>, type?: ACCOUNT_TYPE): Promise<void>; | ||
protected updateState(preferences?: Partial<P>, address?: string): P; | ||
@@ -136,0 +93,0 @@ protected headers(address?: string): { |
{ | ||
"name": "@toruslabs/base-controllers", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"homepage": "https://github.com/torusresearch/controllers#readme", | ||
@@ -65,3 +65,3 @@ "license": "ISC", | ||
}, | ||
"gitHead": "13b57afe21257c71e11d4e019fca62d517bfdc54" | ||
"gitHead": "bb9d5f2612ba55375a94815e328954fc8976e07b" | ||
} |
@@ -44,2 +44,6 @@ import { BaseConfig, BaseState, IController } from "../interfaces"; | ||
displayName: string; | ||
/** | ||
* Whether the network is testnet or not | ||
*/ | ||
isTestnet?: boolean; | ||
} | ||
@@ -46,0 +50,0 @@ |
@@ -384,171 +384,9 @@ import { get, patch, post, remove } from "@toruslabs/http-helpers"; | ||
async fetchEtherscanTx<T>(parameters: { selectedAddress: string; selectedNetwork: string }): Promise<T[]> { | ||
try { | ||
const url = new URL(`${this.config.api}/etherscan`); | ||
Object.keys(parameters).forEach((key) => url.searchParams.append(key, parameters[key as keyof typeof parameters])); | ||
const response = await get<{ success: boolean; data: T[] }>(url.href, this.headers(parameters.selectedAddress)); | ||
return response.success ? response.data : []; | ||
} catch (error) { | ||
log.error("unable to fetch etherscan tx", error); | ||
return []; | ||
} | ||
} | ||
async getCovalentTokenBalances<T>(address: string, chainId: string): Promise<T> { | ||
try { | ||
const api = `https://api.covalenthq.com/v1/${chainId}/address/${address}/balances_v2/`; | ||
const res = await get<{ success: boolean; data: T }>(`${this.config.api}/covalent?url=${encodeURIComponent(api)}`, this.headers(address), { | ||
useAPIKey: true, | ||
}); | ||
return res.success ? res.data : ({} as T); | ||
} catch (error) { | ||
log.error("unable to get covalent token balances", error); | ||
return {} as T; | ||
} | ||
} | ||
async getEthereumAssetData(parameters: { contract: string; tokenId: string }) { | ||
const { contract, tokenId } = parameters; | ||
if (!contract || !tokenId) { | ||
throw new Error("Invalid params received while fetching asset data"); | ||
} | ||
const queryApi = `https://api.opensea.io/api/v1/asset/${contract}/${tokenId}`; | ||
const url = new URL(`${this.config.api}/opensea`); | ||
url.searchParams.append("url", queryApi); | ||
const res = await get<{ | ||
success: boolean; | ||
error?: string; | ||
data: { | ||
asset_contract?: { | ||
symbol?: string; | ||
}; | ||
image_url?: string; | ||
name?: string; | ||
}; | ||
}>(url.href, this.headers()); | ||
return { | ||
symbol: res.data?.asset_contract?.symbol ?? "", | ||
logo: res.data?.image_url, | ||
name: res.data?.name, | ||
description: res.data?.name, | ||
}; | ||
} | ||
async getCovalentAssetData(parameters: { contract: string; chainId: string; tokenId: string }) { | ||
const { contract, tokenId, chainId } = parameters; | ||
if (!contract || !tokenId || !chainId) { | ||
throw new Error("Invalid params received while fetching asset data"); | ||
} | ||
// for all other covalent supported chains except mainnet. | ||
const queryApi = `https://api.covalenthq.com/v1/${chainId}/tokens/${contract}/nft_metadata/${tokenId}/`; | ||
const url = new URL(`${this.config.api}/covalent`); | ||
url.searchParams.append("url", queryApi); | ||
const res = await get<{ | ||
success: boolean; | ||
error?: string; | ||
data?: { | ||
data: { | ||
items: { | ||
nft_data: { | ||
external_data: { | ||
name: string; | ||
image: string; | ||
description: string; | ||
}; | ||
}[]; | ||
contract_ticker_symbol: string; | ||
}[]; | ||
}; | ||
}; | ||
}>(url.href, this.headers()); | ||
const contractData = res.data?.data?.items || []; | ||
if (contractData.length > 0) { | ||
const { nft_data: nftData, contract_ticker_symbol: symbol } = contractData[0]; | ||
if (nftData.length > 0 && !!nftData[0].external_data) { | ||
const { name, image, description } = nftData[0].external_data; | ||
return { | ||
name, | ||
logo: image, | ||
symbol: symbol || name, | ||
description, | ||
}; | ||
} | ||
} | ||
} | ||
async getEthereumAssetContractData(parameters: { contract: string }) { | ||
const { contract } = parameters; | ||
if (!contract) { | ||
throw new Error("Invalid params received while fetching asset data"); | ||
} | ||
const queryApi = `https://api.opensea.io/api/v1/asset_contract/${contract}`; | ||
const url = new URL(`${this.config.api}/opensea`); | ||
url.searchParams.append("url", queryApi); | ||
const res = await get<{ | ||
success: boolean; | ||
error?: string; | ||
data?: { | ||
symbol?: string; | ||
image_url?: string; | ||
name?: string; | ||
schema_name?: string; | ||
}; | ||
}>(url.href, this.headers()); | ||
return { | ||
symbol: res.data?.symbol, | ||
logo: res.data?.image_url, | ||
name: res.data?.name, | ||
description: res.data?.name, | ||
schema_name: res.data?.schema_name ? res.data?.schema_name.toLowerCase() : "", | ||
}; | ||
} | ||
async getCovalentAssetContractData(parameters: { contract: string; chainId: string }) { | ||
const { chainId, contract } = parameters; | ||
if (!contract || !chainId) { | ||
throw new Error("Invalid params received while fetching asset data"); | ||
} | ||
// covalent api requires tokenId to be sent. | ||
// since we need only contract data which will be same for all nfts of that contract, | ||
// so here tring to fetch using first potential nft token id. | ||
const tokenId = 1; | ||
// for all other covalent supported chains except mainnnet. | ||
const queryApi = `https://api.covalenthq.com/v1/${chainId}/tokens/${contract}/nft_metadata/${tokenId}/`; | ||
const url = new URL(`${this.config.api}/covalent`); | ||
url.searchParams.append("url", queryApi); | ||
const res = await get<{ | ||
success: boolean; | ||
error?: string; | ||
data?: { | ||
data?: { | ||
items?: { | ||
contract_ticker_symbol: string; | ||
contract_name: string; | ||
logo_url: string; | ||
supports_erc: string; | ||
}[]; | ||
}; | ||
}; | ||
}>(url.href, this.headers()); | ||
const contractData = res.data?.data?.items || []; | ||
if (contractData.length > 0) { | ||
const { contract_ticker_symbol: symbol, contract_name: name, logo_url: logo, supports_erc: supportsErc } = contractData[0]; | ||
let schemaName = "erc721"; | ||
if (supportsErc.includes("erc1155")) { | ||
schemaName = "erc1155"; | ||
} | ||
return { | ||
name, | ||
logo, | ||
symbol: symbol || name, | ||
description: "", | ||
schema_name: schemaName, | ||
}; | ||
} | ||
} | ||
protected async init(address: string, userInfo: UserInfo, jwtToken?: string, pubKey?: string, type?: ACCOUNT_TYPE): Promise<void> { | ||
protected async init( | ||
address: string, | ||
userInfo: UserInfo, | ||
jwtToken?: string, | ||
metadata: Record<string, unknown> = {}, | ||
type?: ACCOUNT_TYPE | ||
): Promise<void> { | ||
let response = { token: jwtToken }; | ||
@@ -563,5 +401,5 @@ if (this.getAddressState(address)) return; | ||
{ | ||
public_key: pubKey, | ||
public_address: address, | ||
signed_message: signedMessage, | ||
...metadata, | ||
}, | ||
@@ -568,0 +406,0 @@ {}, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3822107
12065