Skip to content

Commit

Permalink
Merge pull request #29 from xendfinance/fix
Browse files Browse the repository at this point in the history
improving frontend
  • Loading branch information
theiceeman authored Sep 23, 2024
2 parents 9b684cd + 231e760 commit f59e6ac
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 201 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/nav/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const links = ref([
},
{
name: 'discord',
link: 'https://discord.gg/Bd2RSPcy',
link: 'https://discord.gg/wvvtY8Wk6M',
img: 'Discord.svg',
},
{
Expand Down
133 changes: 106 additions & 27 deletions frontend/src/store/contracts/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,51 @@ export const useBridge = defineContractStore<IBridgeAssistState, IBridgeAssistAc
const factory = useFactory()
const token = useToken()

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)
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)
},

Expand Down Expand Up @@ -215,9 +239,9 @@ export const useBridge = defineContractStore<IBridgeAssistState, IBridgeAssistAc
)
let _signatures = []
if (!signature) throw new Error('Signature Error: Something went wrong')
if (typeof signature === 'string'){
if (typeof signature === 'string') {
_signatures = [signature]
}else {
} else {
_signatures = [...signature]
}
const [tx] = await safeWrite(
Expand All @@ -242,8 +266,7 @@ export const useBridge = defineContractStore<IBridgeAssistState, IBridgeAssistAc

const token = useToken()

for (const chainId of supportedChains as ChainId[]) {
// const { bridgeAssist } = useContracts(undefined, chainId)
await Promise.all((supportedChains as ChainId[]).map(async chainId => {
let tokenAddr = token.tokenAddress
// const tokenAddr =
// token.symbol === 'RWA' && chainId === '42421'
Expand Down Expand Up @@ -277,7 +300,44 @@ export const useBridge = defineContractStore<IBridgeAssistState, IBridgeAssistAc
)
)
}
}
}))

// for (const chainId of supportedChains as ChainId[]) {
// // const { bridgeAssist } = useContracts(undefined, chainId)
// let tokenAddr = token.tokenAddress
// // const tokenAddr =
// // token.symbol === 'RWA' && chainId === '42421'
// // ? DEFAULT_NATIVE_TOKEN_CONTRACT_2
// // : token.tokenAddress
// if (
// (token.symbol === 'RWA' && chainId === '42421') ||
// (token.symbol === 'BTC' && chainId === '200810')
// ) {
// tokenAddr = DEFAULT_NATIVE_TOKEN_CONTRACT_2
// } else {
// const tokens = token.tokens[chainId]
// if (tokens) {
// const _token = tokens.find((t) => 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
},
Expand All @@ -292,7 +352,7 @@ export const useBridge = defineContractStore<IBridgeAssistState, IBridgeAssistAc

let symbol = ''

for (const transaction of transactions) {
await Promise.all(transactions.map(async transaction => {
const hashedTx = hashTx(transaction)
// const contract = getContract(fromChain)
// if (bridgeAddress) {
Expand All @@ -309,7 +369,26 @@ export const useBridge = defineContractStore<IBridgeAssistState, IBridgeAssistAc
txBlock: fulfillInfo.txBlock,
confirmations: fulfillInfo.confirmations,
}
}
}))

// for (const transaction of transactions) {
// const hashedTx = hashTx(transaction)
// // const contract = getContract(fromChain)
// // if (bridgeAddress) {
// // const tokenAddress = await safeRead(
// // contract.anyBridgeAssist(bridgeAddress).TOKEN(),
// // '',
// // )
// // symbol = await safeRead(contract.anyToken(tokenAddress).symbol(), '')
// // }

// const fulfillInfo = await this.fulfilledInfo(transaction)
// fulfilled[hashedTx] = fulfillInfo.isFulfilled
// claimInfo[hashedTx] = {
// txBlock: fulfillInfo.txBlock,
// confirmations: fulfillInfo.confirmations,
// }
// }

return [transactions, fulfilled, claimInfo, symbol]
},
Expand Down
69 changes: 43 additions & 26 deletions frontend/src/store/contracts/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,59 @@ export const useFactory = defineContractStore<
},

async upload() {
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]
}
}
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() {
this.loading = true

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
Expand Down
Loading

0 comments on commit f59e6ac

Please sign in to comment.