mirror of
https://github.com/status-im/discover-dapps.git
synced 2025-02-20 14:18:28 +00:00
Implement getDapps
This commit is contained in:
parent
46b5524a5f
commit
674ab10037
@ -1,7 +1,7 @@
|
||||
import bs58 from 'bs58'
|
||||
|
||||
export const base64ToBlob = base64Text => {
|
||||
const byteString = atob(base64Text)
|
||||
const byteString = atob(base64Text.split(',')[1])
|
||||
|
||||
const arrayBuffer = new ArrayBuffer(byteString.length)
|
||||
const uintArray = new Uint8Array(arrayBuffer)
|
||||
|
@ -24,15 +24,27 @@ class DiscoverService extends BlockchainService {
|
||||
return DiscoverContract.methods.downvoteCost(dapp.id).call()
|
||||
}
|
||||
|
||||
// Todo: Should be implemented
|
||||
// async getDApps() {
|
||||
// const dapps = []
|
||||
// const dappsCount = await DiscoverContract.methods.getDAppsCount().call()
|
||||
async getDAppsCount() {
|
||||
return DiscoverContract.methods.getDAppsCount().call()
|
||||
}
|
||||
|
||||
// for (let i = 0; i < dappsCount; i++) {
|
||||
// const dapp = await DiscoverContract.methods.dapps(i).call()
|
||||
// }
|
||||
// }
|
||||
async getDApps() {
|
||||
const dapps = []
|
||||
const dappsCount = await DiscoverContract.methods.getDAppsCount().call()
|
||||
|
||||
try {
|
||||
for (let i = 0; i < dappsCount; i++) {
|
||||
const dapp = await DiscoverContract.methods.dapps(i).call()
|
||||
dapp.metadata = await ipfsSDK.retrieveDAppMetadataByHash(dapp.metadata)
|
||||
|
||||
dapps.push(dapp)
|
||||
}
|
||||
|
||||
return dapps
|
||||
} catch (error) {
|
||||
throw new Error(`Error fetching dapps. Details: ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
async getDAppById(id) {
|
||||
let dapp
|
||||
|
@ -64,34 +64,35 @@ class Example extends React.Component {
|
||||
}
|
||||
|
||||
async logDiscoverMethods() {
|
||||
const createdDApp = await this.createDApp()
|
||||
console.log(await SERVICES.DiscoverService.getDApps())
|
||||
// const createdDApp = await this.createDApp()
|
||||
|
||||
const dappData = await this.getFullDApp(createdDApp.id)
|
||||
console.log(`Created DApp : ${JSON.stringify(dappData)}`)
|
||||
// const dappData = await this.getFullDApp(createdDApp.id)
|
||||
// console.log(`Created DApp : ${JSON.stringify(dappData)}`)
|
||||
|
||||
document.getElementById('testImage').src = dappData.metadata.image
|
||||
// document.getElementById('testImage').src = dappData.metadata.image
|
||||
|
||||
const downVote = await this.downVoteCost(createdDApp.id)
|
||||
console.log(
|
||||
`Downvote TX Hash : ${await this.downvote(createdDApp.id, downVote.c)}`,
|
||||
)
|
||||
console.log(`Upvote TX Hash : ${await this.upvote(createdDApp.id)}`)
|
||||
console.log(`Withdraw TX Hash : ${await this.withdraw(createdDApp.id)}`)
|
||||
console.log(
|
||||
`UpvoteEffect Result : ${await this.upVoteEffect(createdDApp.id)}`,
|
||||
)
|
||||
console.log(
|
||||
`DownVoteCost Result : ${await this.downVoteCost(createdDApp.id)}`,
|
||||
)
|
||||
// const downVote = await this.downVoteCost(createdDApp.id)
|
||||
// console.log(
|
||||
// `Downvote TX Hash : ${await this.downvote(createdDApp.id, downVote.c)}`,
|
||||
// )
|
||||
// console.log(`Upvote TX Hash : ${await this.upvote(createdDApp.id)}`)
|
||||
// console.log(`Withdraw TX Hash : ${await this.withdraw(createdDApp.id)}`)
|
||||
// console.log(
|
||||
// `UpvoteEffect Result : ${await this.upVoteEffect(createdDApp.id)}`,
|
||||
// )
|
||||
// console.log(
|
||||
// `DownVoteCost Result : ${await this.downVoteCost(createdDApp.id)}`,
|
||||
// )
|
||||
|
||||
console.log(
|
||||
`Set metadata TX Hash : ${await this.setMetadata(createdDApp.id)}`,
|
||||
)
|
||||
console.log(
|
||||
`Updated DApp : ${JSON.stringify(
|
||||
await this.getFullDApp(createdDApp.id),
|
||||
)}`,
|
||||
)
|
||||
// console.log(
|
||||
// `Set metadata TX Hash : ${await this.setMetadata(createdDApp.id)}`,
|
||||
// )
|
||||
// console.log(
|
||||
// `Updated DApp : ${JSON.stringify(
|
||||
// await this.getFullDApp(createdDApp.id),
|
||||
// )}`,
|
||||
// )
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -5,17 +5,9 @@ import {
|
||||
onReceiveTransactionHashAction,
|
||||
} from '../TransactionStatus/TransactionStatus.recuder'
|
||||
|
||||
//TODO: create here. You can completely delete the following two functions. They must be imported.
|
||||
const createDapp = async (name, url, desc, category, img) => {
|
||||
return '0x3513rewrsdfsdf'
|
||||
}
|
||||
const checkTransactionStatus = async hash => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve()
|
||||
}, 5000)
|
||||
})
|
||||
}
|
||||
import BlockchainTool from '../../common/blockchain'
|
||||
|
||||
const blockchainSDK = BlockchainTool.init()
|
||||
|
||||
const SHOW_SUBMIT = 'SHOW_SUBMIT'
|
||||
const CLOSE_SUBMIT = 'CLOSE_SUBMIT'
|
||||
@ -99,23 +91,23 @@ export const onImgDoneAction = imgBase64 => ({
|
||||
export const submitAction = dapp => {
|
||||
return async dispatch => {
|
||||
dispatch(closeSubmitAction())
|
||||
const hash = await createDapp(
|
||||
dapp.name,
|
||||
dapp.url,
|
||||
dapp.desc,
|
||||
dapp.category,
|
||||
dapp.img,
|
||||
)
|
||||
dispatch(onReceiveTransactionHashAction(hash))
|
||||
const createdDapp = await blockchainSDK.DiscoverService.createDApp(1, {
|
||||
name: dapp.name,
|
||||
url: dapp.url,
|
||||
desc: dapp.desc,
|
||||
category: dapp.category,
|
||||
image: dapp.img,
|
||||
})
|
||||
dispatch(onReceiveTransactionHashAction(createdDapp.tx))
|
||||
|
||||
await checkTransactionStatus(hash)
|
||||
await blockchainSDK.utils.getTxStatus(createdDapp.tx)
|
||||
dispatch(onPublishedSuccessAction())
|
||||
}
|
||||
}
|
||||
|
||||
export const statusCheckAction = hash => {
|
||||
return async dispatch => {
|
||||
await checkTransactionStatus(hash)
|
||||
await blockchainSDK.utils.getTxStatus(hash)
|
||||
dispatch(onPublishedSuccessAction())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user