Skip to content

Commit

Permalink
PR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbo committed Aug 24, 2023
1 parent 8b55aed commit fa757ac
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 78 deletions.
9 changes: 8 additions & 1 deletion composables/useBrowserExtension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PROVIDERS, STORAGE_KEY } from '@/types/enums'
import { profileRoute } from '@/shared/routes'
import { INJECTED_PROVIDER, CONNECTION_EXPIRY_TIME_MS } from '@/shared/config'
import { EoAError } from '@/shared/errors'
import { EoAError, InterfaceError } from '@/shared/errors'

const openStoreLink = () => {
const { currentNetwork } = useAppStore()
Expand Down Expand Up @@ -63,6 +63,13 @@ const connect = async () => {
})
}

if (error instanceof InterfaceError) {
return showModal({
title: formatMessage('web3_connect_error_title'),
message: formatMessage('web3_interface_error_message'),
})
}

// errors that have a code or message
if (error && error.code) {
switch (error.code) {
Expand Down
60 changes: 37 additions & 23 deletions composables/useErc725.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getImageUrlBySize } from '@/utils/getProfileImages'
import LSP8IdentifiableDigitalAsset from '@/shared/schemas/LSP8IdentifiableDigitalAsset.json'
import { PROVIDERS } from '@/types/enums'
import { getDataABI } from '@/shared/abis/getDataABI'
import { IPFS_URL } from '@/shared/config'

export interface LSP3ProfileJSON {
LSP3Profile: LSP3Profile
Expand All @@ -20,7 +21,7 @@ export interface LSP3ProfileJSON {
const getInstance = (address: string, schema: ERC725JSONSchema[]) => {
const { currentNetwork } = useAppStore()
const config = {
ipfsGateway: currentNetwork.ipfsUrl,
ipfsGateway: IPFS_URL,
}
const provider = new Web3.providers.HttpProvider(currentNetwork.rpcHttp)
const erc725 = new ERC725(schema, address, provider, config)
Expand Down Expand Up @@ -64,7 +65,6 @@ const fetchAssets = async (profileAddress: Address, schema: string) => {
const result = await erc725.fetchData(schema)
const assetAddresses = result.value as Address[]
const { profile } = useProfileStore()
console.log(schema, assetAddresses)

const assets = Promise.all(
assetAddresses.map(async address => {
Expand Down Expand Up @@ -174,27 +174,28 @@ const fetchLSP8Metadata = async (
const lsp8DigitalAsset = await erc725.fetchData(['LSP8TokenIdType'])
const tokenIdType = lsp8DigitalAsset[0].value.toString()

//fetch LSP8MetadataJSON depending on tokenIdType
if (tokenIdType === TokenIdType.address) {
return lsp8MetadataGetter(
'address',
// ethers.utils.hexDataSlice(tokenId.toString(), 12)
tokenId.toString()
)
} else if (tokenIdType === TokenIdType.number) {
return lsp8MetadataGetter('uint256', parseInt(tokenId).toString())
} else if (tokenIdType === TokenIdType.bytes32) {
return lsp8MetadataGetter('bytes32', tokenId.toString())
} else {
return {
LSP4Metadata: {
description: '',
links: [],
images: [[]],
icon: [],
assets: [],
},
}
// fetch LSP8MetadataJSON depending on tokenIdType
switch (tokenIdType) {
case TokenIdType.address:
return lsp8MetadataGetter(
'address',
// ethers.utils.hexDataSlice(tokenId.toString(), 12)
tokenId.toString()
)
case TokenIdType.number:
return lsp8MetadataGetter('uint256', parseInt(tokenId).toString())
case TokenIdType.bytes32:
return lsp8MetadataGetter('bytes32', tokenId.toString())
default:
return {
LSP4Metadata: {
description: '',
links: [],
images: [[]],
icon: [],
assets: [],
},
}
}
} catch (error) {
console.log(error)
Expand Down Expand Up @@ -242,13 +243,26 @@ const fetchLSP4Creator = async (
}
}

const supportInterface = async (
address: Address,
interfaceId: string
): Promise<boolean> => {
const { currentNetwork } = useAppStore()

return ERC725.supportsInterface(interfaceId, {
address,
rpcUrl: currentNetwork.rpcHttp,
})
}

const useErc725 = () => {
return {
fetchProfile,
fetchAssets,
fetchLSP4Metadata,
fetchLSP8Metadata,
fetchLSP4Creator,
supportInterface,
}
}

Expand Down
5 changes: 3 additions & 2 deletions shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const NETWORKS: NetworkInfo[] = [
name: 'LUKSO Testnet',
chainId: '0x1069',
rpcHttp: 'https://rpc.testnet.lukso.gateway.fm',
ipfsUrl: 'https://2eff.lukso.dev/ipfs/',
storeUrls: {
chrome:
'https://chrome.google.com/webstore/detail/universal-profiles-testin/abpickdkkbnbcoepogfhkhennhfhehfn',
Expand All @@ -26,7 +25,6 @@ export const NETWORKS: NetworkInfo[] = [
name: 'LUKSO Mainnet',
chainId: '0x2a',
rpcHttp: 'https://rpc.lukso.gateway.fm',
ipfsUrl: 'https://2eff.lukso.dev/ipfs/',
storeUrls: {
chrome: '',
brave: '',
Expand All @@ -52,3 +50,6 @@ export const CONNECTION_EXPIRY_CHECK_INTERVAL_MS = 1000 * 10 // 10 seconds

// placeholder icon if asset icon is not available
export const ASSET_ICON_PLACEHOLDER_URL = '/images/token-default.svg'

// url of the ipfs gateway
export const IPFS_URL = 'https://2eff.lukso.dev/ipfs/'
6 changes: 6 additions & 0 deletions shared/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ export class EoAError extends Error {
super('The profile is an EoA')
}
}

export class InterfaceError extends Error {
constructor(interfaceId: string) {
super(`This profile contract doesn't support ${interfaceId} interface`)
}
}
40 changes: 26 additions & 14 deletions translations/en_US.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
{
"web3_eoa_error_message": "Please use Universal Profile Extension. ",
"button_send": "Send",
"asset_standard_info_LSP8_title": "LSP8 Token Standard",
"header_title": "Wallet",
"token_details_contract_address": "Contract Address",
"web3_connect_no_extension": "You don't have the Universal Profile browser extension installed.",
"asset_standard_info_legacy_details": "Info about the standard goes here....",
"asset_standard_info_LSP7_details": "Info about the standard goes here....",
"web3_connect_error_title": "Can't connect",
"web3_connect_error_rejected_request": "User rejected the request.",
"web3_connect_error_pending_request": "You have pending request. Check your browser extension.",
"web3_connect_error": "There was an error while connecting to the browser extension.",
"tokens_title": "Tokens",
"token_details_send": "Send {token}",
"asset_filter_owned_assets": "Owned assets",
"asset_standard_info_LSP8_details": "Info about the standard goes here....",
"web3_connect_error_rejected_request": "You rejected the request",
"modal_default_title": "Something went wrong...",
"modal_default_confirm": "Ok",
"header_title": "Wallet",
"footer_need_help_text": "NEED HELP?",
"asset_standard_info_LSP7_title": "LSP7 Token Standard",
"asset_filter_created_assets": "Created assets",
"header_send": "Send",
"asset_standard_info_legacy_title": "Legacy Token Standard",
"token_details_description": "Token Description",
"header_my_profile": "My profile",
"header_disconnect": "Disconnect",
"header_connect": "Connect",
"footer_terms_text": "Terms & Conditions",
"footer_privacy_policy_text": "Privacy Policy",
"footer_need_help_url": "mailto:[email protected]",
"footer_need_help_text": "NEED HELP?",
"header_disconnect": "Disconnect",
"tokens_title": "Tokens",
"footer_faq_text": "FAQs",
"asset_created_by": "Created by",
"collectibles_title": "Collectibles",
"button_send": "Send",
"asset_filter_owned_assets": "Owned assets",
"asset_filter_created_assets": "Created assets",
"asset_created_by": "Created by"
"modal_default_confirm": "Ok",
"token_details_own": "You own this token",
"footer_need_help_url": "mailto:[email protected]",
"web3_interface_error_message": "You try to connect to legacy profile that is no longer supported.",
"header_connect": "Connect",
"web3_connect_error": "There was an error while connecting to the browser extension.",
"footer_privacy_policy_text": "Privacy Policy",
"token_details_images": "Token Images"
}
1 change: 0 additions & 1 deletion types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ declare global {
name: string
rpcHttp: string
chainId: ChainIdHex
ipfsUrl: string
storeUrls?: { [key in BrowserName]: string }
}

Expand Down
25 changes: 0 additions & 25 deletions utils/checkInterface.ts

This file was deleted.

12 changes: 8 additions & 4 deletions utils/detect-standard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ import { InterfaceId } from '@/types/assets'
export const detectStandard = async (
contractAddress: Address
): Promise<InterfaceId | undefined> => {
const { supportInterface } = useErc725()

// LSP0
if (await checkInterface(contractAddress, INTERFACE_IDS.LSP0ERC725Account)) {
if (
await supportInterface(contractAddress, INTERFACE_IDS.LSP0ERC725Account)
) {
return 'LSP0ERC725Account'
}

// LSP7
if (await checkInterface(contractAddress, INTERFACE_IDS.LSP7DigitalAsset)) {
if (await supportInterface(contractAddress, INTERFACE_IDS.LSP7DigitalAsset)) {
return 'LSP7DigitalAsset'
}

// LSP8
if (
await checkInterface(
await supportInterface(
contractAddress,
INTERFACE_IDS.LSP8IdentifiableDigitalAsset
)
Expand All @@ -26,7 +30,7 @@ export const detectStandard = async (
}

// LSP9
if (await checkInterface(contractAddress, INTERFACE_IDS.LSP9Vault)) {
if (await supportInterface(contractAddress, INTERFACE_IDS.LSP9Vault)) {
return 'LSP9Vault'
}

Expand Down
11 changes: 6 additions & 5 deletions utils/fetchProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ import { INTERFACE_IDS, SupportedStandards } from '@lukso/lsp-smart-contracts'

import { PROVIDERS } from '@/types/enums'
import { getDataABI } from '@/shared/abis/getDataABI'
import { checkInterface } from '@/utils/checkInterface'
import { InterfaceError } from '@/shared/errors'

export const fetchProfile = async (profileAddress: Address) => {
const { contract, isEoA } = useWeb3(PROVIDERS.RPC)
const { supportInterface } = useErc725()

// EoA check
if (await isEoA(profileAddress)) {
throw new Error('The profile is an EoA')
}

// interface check
if (!checkInterface(profileAddress, INTERFACE_IDS.LSP0ERC725Account)) {
throw new Error(
`This profile contract doesn't support LSP0ERC725Account interface`
)
if (
!(await supportInterface(profileAddress, INTERFACE_IDS.LSP0ERC725Account))
) {
throw new InterfaceError('LSP0ERC725Account')
}

// standard check
Expand Down
6 changes: 3 additions & 3 deletions utils/formatUrl.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IPFS_URL } from '@/shared/config'

/**
* Replaces protocol in the given URL with their respective gateway URLs.
* If the URL does not contain either protocol, returns the original URL.
Expand All @@ -6,11 +8,9 @@
* @returns {string} The formatted URL.
*/
export function formatUrl(url: string): string {
const network = useAppStore().getNetwork(useAppStore().selectedNetwork)

// IPFS
if (url && url.includes('ipfs://')) {
return url.replace('ipfs://', network.ipfsUrl)
return url.replace('ipfs://', IPFS_URL)
}

return url
Expand Down

0 comments on commit fa757ac

Please sign in to comment.