Skip to content

Commit

Permalink
fix last deployed protocol view
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehor Podporinov authored and Yehor Podporinov committed Jun 5, 2024
1 parent 2b54de9 commit 8cb2598
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions src/pages/Mor20Ecosystem/MainPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<script lang="ts" setup>
import { AppButton, InfoCard } from '@/common'
import { useI18n } from '@/composables'
import { MAX_UINT_256 } from '@/const'
import { ICON_NAMES } from '@/enums'
import { ErrorHandler } from '@/helpers'
import { router } from '@/router'
Expand Down Expand Up @@ -108,36 +109,55 @@ const init = async () => {
try {
const { address, l1FactoryContract, l2FactoryContract } = web3ProvidersStore

const [l1ProtocolsCount, l2ProtocolsCount] = await Promise.all([
l1FactoryContract.providerBased.value.countProtocols(address),
l2FactoryContract.providerBased.value.countProtocols(address),
])

if (l1ProtocolsCount.isZero() && l2ProtocolsCount.isZero()) {
data.value = null
return
}

const [l1DeployedPools, l2DeployedPools] = await Promise.all([
l1FactoryContract.providerBased.value.getDeployedPools(
address,
l1ProtocolsCount.sub(1),
1,
0,
MAX_UINT_256,
),
l2FactoryContract.providerBased.value.getDeployedPools(
address,
l2ProtocolsCount.sub(1),
1,
0,
MAX_UINT_256,
),
])

let lastFullyL1DeployedPoolIdx = -1
let lastFullyL2DeployedPoolIdx = -1
for (let i = l1DeployedPools.length - 1; i >= 0; i--) {
if (
lastFullyL1DeployedPoolIdx !== -1 &&
lastFullyL2DeployedPoolIdx !== -1
)
break

for (let j = l2DeployedPools.length - 1; j >= 0; j--) {
if (l1DeployedPools[i].protocol === l2DeployedPools[j].protocol) {
lastFullyL1DeployedPoolIdx = i
lastFullyL2DeployedPoolIdx = j
break
}
}
}

if (
lastFullyL1DeployedPoolIdx === -1 ||
lastFullyL2DeployedPoolIdx === -1
) {
data.value = null
return
}

data.value = {
protocolName: l1DeployedPools[0].protocol,
distributionAddress: l1DeployedPools[0].distribution,
l1SenderAddress: l1DeployedPools[0].l1Sender,
l2MessageReceiverAddress: l2DeployedPools[0].l2MessageReceiver,
l2TokenReceiverAddress: l2DeployedPools[0].l2TokenReceiver,
tokenAddress: l2DeployedPools[0].mor20,
protocolName: l1DeployedPools[lastFullyL1DeployedPoolIdx].protocol,
distributionAddress:
l1DeployedPools[lastFullyL1DeployedPoolIdx].distribution,
l1SenderAddress: l1DeployedPools[lastFullyL1DeployedPoolIdx].l1Sender,
l2MessageReceiverAddress:
l2DeployedPools[lastFullyL2DeployedPoolIdx].l2MessageReceiver,
l2TokenReceiverAddress:
l2DeployedPools[lastFullyL2DeployedPoolIdx].l2TokenReceiver,
tokenAddress: l2DeployedPools[lastFullyL2DeployedPoolIdx].mor20,
}
} catch (error) {
data.value = null
Expand Down

0 comments on commit 8cb2598

Please sign in to comment.