[#16] dev.dap.ps is empty on IOS (develop 09.08.2019)

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Andrey Shovkoplyas 2019-12-16 11:48:30 +01:00 committed by Jakub
parent ccae507c00
commit d1f654531f
2 changed files with 59 additions and 22 deletions

View File

@ -50,6 +50,49 @@ class DiscoverService extends BlockchainService {
return MetadataClient.getDappsCount()
}
async pushDapps(dappsCache, dapps) {
Object.keys(dappsCache).forEach(metadataHash => {
const dappMetadata = dappsCache[metadataHash]
if (dappMetadata.status == 'APPROVED') {
dapps.push({
developer: '',
id: dappMetadata.compressedMetadata,
metadata: {
...dappMetadata.details,
status: dappMetadata.status,
},
balance: 0,
rate: 0,
available: 0,
votesMinted: 0,
votesCast: 0,
effectiveBalance: 0,
})
}
})
}
async getAllDappsWithoutMetadata() {
try {
const contractDappsCount = await DiscoverContract.methods
.getDAppsCount()
.call({ from: this.sharedContext.account })
const dappsCache = JSON.parse(
JSON.stringify(await MetadataClient.retrieveMetadataCache()),
)
let dapps = [];
await this.pushDapps(dappsCache, dapps)
return dapps
} catch (error) {
throw new Error(`Error fetching dapps. Details: ${error.message}`)
}
}
async getAllDappsWithMetadata() {
try {
const contractDappsCount = await DiscoverContract.methods
@ -66,10 +109,11 @@ class DiscoverService extends BlockchainService {
DiscoverContract.methods.dapps(i).call({from: this.sharedContext.account})
)
}
let dapps = [];
/* using Promise.all() to run calls in parallel */
let dapps = await Promise.all(asyncCalls)
let dappsCalls = await Promise.all(asyncCalls)
for (let dapp of dapps) {
for (let dapp of dappsCalls) {
const dappMetadata = dappsCache[dapp.metadata]
if (dappMetadata) {
delete dappsCache[dapp.metadata]
@ -80,26 +124,7 @@ class DiscoverService extends BlockchainService {
}
}
Object.keys(dappsCache).forEach(metadataHash => {
const dappMetadata = dappsCache[metadataHash]
if (dappMetadata.status == 'APPROVED') {
dapps.push({
developer: '',
id: dappMetadata.compressedMetadata,
metadata: {
...dappMetadata.details,
status: dappMetadata.status,
},
balance: 0,
rate: 0,
available: 0,
votesMinted: 0,
votesCast: 0,
effectiveBalance: 0,
})
}
})
await this.pushDapps(dappsCache, dapps)
return dapps
} catch (error) {

View File

@ -33,7 +33,19 @@ export const fetchAllDappsAction = () => {
const { transactionStatus } = state
let dappSource = ''
/* we want to show dapps list first and then load all data from blockchain */
const allDappsWithoutMeta = await discoverService.getAllDappsWithoutMetadata()
for (let i = 0; i < allDappsWithoutMeta.length; i++) {
dappSource = allDappsWithoutMeta[i]
if (dappSource !== null) {
const dappModel = DappModel.instanceFromBlockchainWithMetadata(dappSource)
dispatch(onUpdateDappsAction(dappState.creditDapp(dappModel)))
}
}
const allDapps = await discoverService.getAllDappsWithMetadata()
for (let i = 0; i < allDapps.length; i++) {
dappSource = allDapps[i]
if (dappSource !== null) {