Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 47 additions & 22 deletions src/common/blockchain/services/discover-service/discover-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions src/modules/Dapps/Dapps.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down