diff --git a/frontend/src/components/nav/Footer.vue b/frontend/src/components/nav/Footer.vue index f0bc819..81df604 100644 --- a/frontend/src/components/nav/Footer.vue +++ b/frontend/src/components/nav/Footer.vue @@ -71,7 +71,7 @@ const links = ref([ }, { name: 'discord', - link: 'https://discord.gg/Bd2RSPcy', + link: 'https://discord.gg/wvvtY8Wk6M', img: 'Discord.svg', }, { diff --git a/frontend/src/store/contracts/bridge.ts b/frontend/src/store/contracts/bridge.ts index fa3c686..51c04b4 100644 --- a/frontend/src/store/contracts/bridge.ts +++ b/frontend/src/store/contracts/bridge.ts @@ -104,27 +104,51 @@ export const useBridge = defineContractStore item.token === token.tokenAddress - )?.bridgeAssist ?? '' - const contract = getContract(chainId) + await Promise.all( + REAL_CHAIN_IDS.map(async (chainId) => { + const bridgeAssistAddress = + factory.assistAndTokenAddresses[chainId].find( + (item) => item.token === token.tokenAddress + )?.bridgeAssist ?? '' + const contract = getContract(chainId) + + if (!bridgeAssistAddress) { + this.feeFulfill[chainId] = BigNumber.from(0) + this.feeSend[chainId] = BigNumber.from(0) + } else { + this.feeFulfill[chainId] = await safeRead( + contract.anyBridgeAssist(bridgeAssistAddress).feeFulfill(), + this.feeFulfill[chainId] + ) + this.feeSend[chainId] = await safeRead( + contract.anyBridgeAssist(bridgeAssistAddress).feeSend(), + this.feeSend[chainId] + ) + } + }) + ) - if (!bridgeAssistAddress) { - this.feeFulfill[chainId] = BigNumber.from(0) - this.feeSend[chainId] = BigNumber.from(0) - } else { - this.feeFulfill[chainId] = await safeRead( - contract.anyBridgeAssist(bridgeAssistAddress).feeFulfill(), - this.feeFulfill[chainId] - ) - this.feeSend[chainId] = await safeRead( - contract.anyBridgeAssist(bridgeAssistAddress).feeSend(), - this.feeSend[chainId] - ) - } - } + // for (const chainId of REAL_CHAIN_IDS as ChainId[]) { + // const bridgeAssistAddress = + // factory.assistAndTokenAddresses[chainId].find( + // (item) => item.token === token.tokenAddress + // )?.bridgeAssist ?? '' + // const contract = getContract(chainId) + + // if (!bridgeAssistAddress) { + // this.feeFulfill[chainId] = BigNumber.from(0) + // this.feeSend[chainId] = BigNumber.from(0) + // } else { + // this.feeFulfill[chainId] = await safeRead( + // contract.anyBridgeAssist(bridgeAssistAddress).feeFulfill(), + // this.feeFulfill[chainId] + // ) + // this.feeSend[chainId] = await safeRead( + // contract.anyBridgeAssist(bridgeAssistAddress).feeSend(), + // this.feeSend[chainId] + // ) + // } + // } // console.log('getFees result', this.feeFulfill, this.feeSend) }, @@ -215,9 +239,9 @@ export const useBridge = defineContractStore { let tokenAddr = token.tokenAddress // const tokenAddr = // token.symbol === 'RWA' && chainId === '42421' @@ -277,7 +300,44 @@ export const useBridge = defineContractStore t.label === token.symbol) + // if (_token) { + // tokenAddr = _token.value + // } + // } + // } + + // const bridgeAddress = assistAndTokenAddresses[chainId].find( + // (item) => item.token === tokenAddr + // )?.bridgeAssist + + // const contract = getContract(chainId) + // if (bridgeAddress) { + // transactions = transactions.concat( + // await safeRead( + // contract.anyBridgeAssist(bridgeAddress).getUserTransactions(web3.wallet), + // [] + // ) + // ) + // } + // } // console.log('dddddddddd', transactions) return transactions }, @@ -292,7 +352,7 @@ export const useBridge = defineContractStore { const hashedTx = hashTx(transaction) // const contract = getContract(fromChain) // if (bridgeAddress) { @@ -309,7 +369,26 @@ export const useBridge = defineContractStore ({ - // bridgeAssist: v.bridgeAssist, - // token: v.token, - // })), - // 'keys' - // ) - - this.assistAndTokenAddresses[chainId] = assists - // this.bridgeAssistAddress[chainId] = assists[0] - } - } + await Promise.all( + REAL_CHAIN_IDS.map(async (chainId) => { + const contract = getContract(chainId) + const assistsLength = await contract.bridgeFactory.getCreatedBridgesLength() + this.bridgesLength[chainId] = assistsLength + if (assistsLength.toNumber()) { + const assists = await contract.bridgeFactory.getCreatedBridgesInfo( + 0, + assistsLength + ) + this.assistAndTokenAddresses[chainId] = assists + } + }) + ) + // for (const chainId of REAL_CHAIN_IDS) { + // const contract = getContract(chainId) + // const assistsLength = await contract.bridgeFactory.getCreatedBridgesLength() + // this.bridgesLength[chainId] = assistsLength + // if (assistsLength.toNumber()) { + // const assists = await contract.bridgeFactory.getCreatedBridgesInfo( + // 0, + // assistsLength + // ) + + // // console.log(assists, 'assists getCreatedBridgesInfo for ', chainId) + // // console.log( + // // Object.values(assists).map((v) => ({ + // // bridgeAssist: v.bridgeAssist, + // // token: v.token, + // // })), + // // 'keys' + // // ) + + // this.assistAndTokenAddresses[chainId] = assists + // // this.bridgeAssistAddress[chainId] = assists[0] + // } + // } }, async getSupportedChains() { @@ -93,12 +107,15 @@ export const useFactory = defineContractStore< const token = useToken() - const chainIds = token.symbol === 'USDC' ? REAL_CHAIN_IDS.filter(c => c !== '421614') : REAL_CHAIN_IDS + const chainIds = + token.symbol === 'USDC' + ? REAL_CHAIN_IDS.filter((c) => c !== '421614') + : REAL_CHAIN_IDS const res = await Promise.all( chainIds.map(async (id) => { - const _token = token.tokens[id].find( t => t.label === token.symbol) - if (!_token) return + const _token = token.tokens[id].find((t) => t.label === token.symbol) + if (!_token) return const bridgeAddress = this.assistAndTokenAddresses[id].find( (item) => item.token === _token.value )?.bridgeAssist diff --git a/frontend/src/store/contracts/token.ts b/frontend/src/store/contracts/token.ts index 65205cf..02a8327 100644 --- a/frontend/src/store/contracts/token.ts +++ b/frontend/src/store/contracts/token.ts @@ -139,47 +139,49 @@ export const useToken = defineContractStore< this.loading = true if (this.tokenAddress) - for (const chainId of REAL_CHAIN_IDS) { - // const { token } = useContracts(undefined, chainId) - const contract = getContract(chainId) - const factory = useFactory() - const tokenAddr = - (this.symbol === 'RWA' && chainId === '42421') || - (this.symbol === 'BTC' && chainId === '200810') - ? DEFAULT_NATIVE_TOKEN_CONTRACT_2 - : this.tokenAddress - const bridgeAssistAddress = - factory.assistAndTokenAddresses[chainId]?.find( - (item) => item.token === tokenAddr - )?.bridgeAssist ?? '' - if ( - (this.symbol === 'RWA' && chainId === '42421') || - (this.symbol === 'BTC' && chainId === '200810') - ) { - const provider = getProvider(chainId) - this.balances[chainId] = await provider.getBalance(web3.wallet) - this.contractBalances[chainId] = await provider.getBalance( - bridgeAssistAddress - ) - } else { - const token = this.tokens[chainId].find((t) => t.label === this.symbol) - if (!token) { - this.balances[chainId] = BigNumber.from(0) - this.contractBalances[chainId] = BigNumber.from(0) - } else { - this.balances[chainId] = await safeRead( - contract.anyToken(token.value).balanceOf(web3.wallet), - '0'.toBigNumber() + await Promise.all( + REAL_CHAIN_IDS.map(async (chainId) => { + const contract = getContract(chainId) + const factory = useFactory() + const tokenAddr = + (this.symbol === 'RWA' && chainId === '42421') || + (this.symbol === 'BTC' && chainId === '200810') + ? DEFAULT_NATIVE_TOKEN_CONTRACT_2 + : this.tokenAddress + const bridgeAssistAddress = + factory.assistAndTokenAddresses[chainId]?.find( + (item) => item.token === tokenAddr + )?.bridgeAssist ?? '' + if ( + (this.symbol === 'RWA' && chainId === '42421') || + (this.symbol === 'BTC' && chainId === '200810') + ) { + const provider = getProvider(chainId) + this.balances[chainId] = await provider.getBalance(web3.wallet) + this.contractBalances[chainId] = await provider.getBalance( + bridgeAssistAddress ) - if (bridgeAssistAddress) { - this.contractBalances[chainId] = await safeRead( - contract.anyToken(token.value).balanceOf(bridgeAssistAddress), + } else { + const token = this.tokens[chainId].find((t) => t.label === this.symbol) + if (!token) { + this.balances[chainId] = BigNumber.from(0) + this.contractBalances[chainId] = BigNumber.from(0) + } else { + this.balances[chainId] = await safeRead( + contract.anyToken(token.value).balanceOf(web3.wallet), '0'.toBigNumber() ) + if (bridgeAssistAddress) { + this.contractBalances[chainId] = await safeRead( + contract.anyToken(token.value).balanceOf(bridgeAssistAddress), + '0'.toBigNumber() + ) + } } } - } - } + }) + ) + // console.log(this.balances, 'lkkj') this.loading = false }, @@ -187,103 +189,66 @@ export const useToken = defineContractStore< async getTokens() { const factory = useFactory() await factory.upload() - for (const chainId of REAL_CHAIN_IDS) { + + const tokenPromises = REAL_CHAIN_IDS.map(async (chainId) => { this.tokens[chainId] = [] const contract = getContract(chainId) const assists = factory.assistAndTokenAddresses[chainId] - for (let item of assists) { - // console.log(item.token, item.bridgeAssist, 'TOKEN', chainId) + + const chainPromises = assists.map(async (item) => { if (item.token) { let symbol = 'RWA' let decimals = 6 + // Handle native tokens if (item.token === DEFAULT_NATIVE_TOKEN_CONTRACT_2) { if (chainId === '42421') { - // console.log(chainId, 'sjkdjkd') symbol = 'RWA' decimals = 18 - } - else{ + } else { symbol = 'BTC' decimals = 18 } } else { - // console.log(item.token, chainId) + // Fetch symbol and decimals for non-native tokens symbol = await safeRead(contract.anyToken(item.token).symbol(), 'RWA') decimals = await safeRead(contract.anyToken(item.token).decimals(), 6) - // console.log(symbol, chainId, decimals, item.token) } + // Update token info (symbol and decimals) this.cSymbol[item.token] = symbol - this.cDecimals[chainId] = { ...this.cDecimals[chainId], - ...{ [symbol]: decimals }, + [symbol]: decimals, } this.cAddresses[chainId] = { ...this.cAddresses[chainId], - ...{ [symbol]: item.token }, + [symbol]: item.token, } - // this.tDecimals[chainId] = decimals + // Add token if it's not already in the list for the current chain const foundToken = this.tokens[chainId].find((t) => t.label === symbol) - - if (!foundToken) + if (!foundToken) { this.tokens[chainId].push({ value: item.token, label: symbol, disabled: false, }) + } } - // factory.assistAndTokenAddresses[chainId]?.map(async (item) => { - // console.log(item.token, item.bridgeAssist, 'TOKEN', chainId) - // if (item.token) { - // let symbol = 'RWA' - // let decimals = 6 - - // if (item.token === DEFAULT_NATIVE_TOKEN_CONTRACT_2) { - // if (chainId === '42421') { - // symbol = 'RWA' - // decimals = 18 - // } - // { - // symbol = 'BTC' - // decimals = 18 - // } - // } else { - // console.log(item.token, chainId, ) - // symbol = await safeRead(contract.anyToken(item.token).symbol(), 'RWA') - // decimals = await safeRead(contract.anyToken(item.token).decimals(), 6) - // console.log(symbol, chainId, decimals, item.token) - // } - - // this.cSymbol[item.token] = symbol - - // this.cDecimals[chainId] = { - // ...this.cDecimals[chainId], - // ...{ [symbol]: decimals }, - // } - // this.cAddresses[chainId] = { - // ...this.cAddresses[chainId], - // ...{ [symbol]: item.token }, - // } - // // this.tDecimals[chainId] = decimals - - // const foundToken = this.tokens[chainId].find((t) => t.label === symbol) - - // if (!foundToken) - // this.tokens[chainId].push({ - // value: item.token, - // label: symbol, - // disabled: false, - // }) - // } - // }) - // console.log('this.tokens', chainId, this.tokens[chainId]) - } - } - // console.log('this.tokens', this.tokens) + }) + + // Wait for all tokens to be processed for the current chain + await Promise.all(chainPromises) + }) + + // Wait for all chains to finish processing + await Promise.all(tokenPromises) + + // Optional: log final tokens structure + // console.log('this.tokens', this.tokens); }, + async setToken(symbol, tokenAddress) { console.log(symbol, tokenAddress, 'dhsjk') const web3 = useWeb3() @@ -332,23 +297,25 @@ export const useToken = defineContractStore< // } // }, async setDecimals(symbol: string) { - for (const chainID of REAL_CHAIN_IDS) { - const _contract = getContract(chainID as ChainId) - const token = this.tokens[chainID].find((t) => t.label === symbol) - if (!token) { - this.decimals[chainID] = 18 - } else { - if (token.value === DEFAULT_NATIVE_TOKEN_CONTRACT_2) { + await Promise.all( + REAL_CHAIN_IDS.map(async (chainID) => { + const _contract = getContract(chainID as ChainId) + const token = this.tokens[chainID].find((t) => t.label === symbol) + if (!token) { this.decimals[chainID] = 18 } else { - const dataDecimals = await safeRead( - _contract.anyToken(token.value).decimals(), - 18 - ) - this.decimals[chainID] = dataDecimals + if (token.value === DEFAULT_NATIVE_TOKEN_CONTRACT_2) { + this.decimals[chainID] = 18 + } else { + const dataDecimals = await safeRead( + _contract.anyToken(token.value).decimals(), + 18 + ) + this.decimals[chainID] = dataDecimals + } } - } - } + }) + ) }, async approveIf(signer, amount, chainId, tokenAddress) { @@ -381,7 +348,7 @@ export const useToken = defineContractStore< }, async hasAllowance(owner, chainId, amount, tokenAddress) { - if(tokenAddress === DEFAULT_NATIVE_TOKEN_CONTRACT_2) return true + if (tokenAddress === DEFAULT_NATIVE_TOKEN_CONTRACT_2) return true const factory = useFactory() const _token = this.tokens[chainId].find((t) => t.label === this.symbol) const bridgeAssist = factory.assistAndTokenAddresses[chainId]?.find( diff --git a/frontend/src/views/index.vue b/frontend/src/views/index.vue index 2402eee..56983ee 100644 --- a/frontend/src/views/index.vue +++ b/frontend/src/views/index.vue @@ -63,40 +63,9 @@ const token = ref('USDT') const web3 = useWeb3() const tokenStore = useToken() -const nativeToken = computed(() => - tokenStore.tokens[web3.chainId].filter( - (t) => t.value === DEFAULT_NATIVE_TOKEN_CONTRACT_2, - ), -) - -const isNativeToken = computed(() => - nativeToken.value && nativeToken.value.length - ? nativeToken.value[0].label === tokenStore.symbol - : false, -) - -// const tokens = computed(() => -// isNativeToken.value -// ? REAL_CHAIN_IDS.map((chain) => tokensRead.value[chain]) -// .flat() -// .filter((t) => t.label !== 'RWA' || t.value === DEFAULT_NATIVE_TOKEN_CONTRACT_2) -// : REAL_CHAIN_IDS.map((chain) => tokensRead.value[chain]) -// .flat() -// .filter((t) => t.value !== DEFAULT_NATIVE_TOKEN_CONTRACT_2), -// ) - -// const tokens = computed(() => -// isNativeToken.value -// ? tokensRead.value[web3.chainId] -// .filter((t) => t.label !== 'RWA' || t.value === DEFAULT_NATIVE_TOKEN_CONTRACT_2) -// : tokensRead.value[web3.chainId] -// .flat() -// .filter((t) => t.value !== DEFAULT_NATIVE_TOKEN_CONTRACT_2), -// ) - -// const tokens = computed(() => tokenStore.tokens[web3.chainId].filter(v => v.label !== 'USDC')) - -// console.log(isNativeToken, tokens, tokenStore.tokens[web3.chainId], 'dksdk') + + + const options = computed(() => [ ...new Map(tokenStore.tokens[web3.chainId] ? tokenStore.tokens[web3.chainId].filter(v => {