mirror of
https://github.com/status-im/discover-dapps.git
synced 2025-02-22 15:18:11 +00:00
Fix services
This commit is contained in:
parent
5e72cc248c
commit
a9e1df90bc
@ -109,7 +109,7 @@ module.exports = {
|
|||||||
testnet: {
|
testnet: {
|
||||||
deployment: {
|
deployment: {
|
||||||
accounts: [{ mnemonic: wallet.mnemonic }],
|
accounts: [{ mnemonic: wallet.mnemonic }],
|
||||||
host: `ropsten.infura.io/v3/`,
|
host: `ropsten.infura.io/v3/8675214b97b44e96b70d05326c61fd6a`,
|
||||||
port: false,
|
port: false,
|
||||||
type: 'rpc',
|
type: 'rpc',
|
||||||
protocol: 'https',
|
protocol: 'https',
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
module.exports.mnemonic =
|
module.exports.mnemonic =
|
||||||
'artefact rebuild liquid honey sport clean candy motor cereal job gap series'
|
''
|
||||||
|
@ -2,21 +2,21 @@ module.exports = {
|
|||||||
// default applies to all environments
|
// default applies to all environments
|
||||||
default: {
|
default: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
ipfs_bin: "ipfs",
|
ipfs_bin: 'ipfs',
|
||||||
available_providers: ["ipfs"],
|
provider: 'ipfs',
|
||||||
|
available_providers: ['ipfs'],
|
||||||
upload: {
|
upload: {
|
||||||
provider: "ipfs",
|
host: 'localhost',
|
||||||
host: "localhost",
|
port: 5001,
|
||||||
port: 5001
|
|
||||||
},
|
},
|
||||||
dappConnection: [
|
dappConnection: [
|
||||||
{
|
{
|
||||||
provider: "ipfs",
|
provider: 'ipfs',
|
||||||
host: "localhost",
|
host: 'localhost',
|
||||||
port: 5001,
|
port: 5001,
|
||||||
getUrl: "http://localhost:8080/ipfs/"
|
getUrl: 'http://localhost:8080/ipfs/',
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
// Configuration to start Swarm in the same terminal as `embark run`
|
// Configuration to start Swarm in the same terminal as `embark run`
|
||||||
/* ,account: {
|
/* ,account: {
|
||||||
address: "YOUR_ACCOUNT_ADDRESS", // Address of account accessing Swarm
|
address: "YOUR_ACCOUNT_ADDRESS", // Address of account accessing Swarm
|
||||||
@ -30,30 +30,45 @@ module.exports = {
|
|||||||
development: {
|
development: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
upload: {
|
upload: {
|
||||||
provider: "ipfs",
|
provider: 'ipfs',
|
||||||
host: "localhost",
|
host: 'localhost',
|
||||||
port: 5001,
|
port: 5001,
|
||||||
getUrl: "http://localhost:8080/ipfs/"
|
getUrl: 'http://localhost:8080/ipfs/',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// merges with the settings in default
|
// merges with the settings in default
|
||||||
// used with "embark run privatenet"
|
// used with "embark run privatenet"
|
||||||
privatenet: {
|
privatenet: {},
|
||||||
},
|
|
||||||
|
|
||||||
// merges with the settings in default
|
// merges with the settings in default
|
||||||
// used with "embark run testnet"
|
// used with "embark run testnet"
|
||||||
testnet: {
|
testnet: {
|
||||||
|
enabled: true,
|
||||||
|
ipfs_bin: 'ipfs',
|
||||||
|
provider: 'ipfs',
|
||||||
|
available_providers: ['ipfs'],
|
||||||
|
upload: {
|
||||||
|
host: 'localhost',
|
||||||
|
port: 5001,
|
||||||
|
},
|
||||||
|
dappConnection: [
|
||||||
|
{
|
||||||
|
provider: 'ipfs',
|
||||||
|
protocol: 'https',
|
||||||
|
host: 'ipfs.infura.io',
|
||||||
|
port: 5001,
|
||||||
|
getUrl: 'https://ipfs.infura.io/ipfs/',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
// merges with the settings in default
|
// merges with the settings in default
|
||||||
// used with "embark run livenet"
|
// used with "embark run livenet"
|
||||||
livenet: {
|
livenet: {},
|
||||||
},
|
|
||||||
|
|
||||||
// you can name an environment with specific settings and then specify with
|
// you can name an environment with specific settings and then specify with
|
||||||
// "embark run custom_name"
|
// "embark run custom_name"
|
||||||
// custom_name: {
|
// custom_name: {
|
||||||
// }
|
// }
|
||||||
};
|
}
|
||||||
|
@ -93,9 +93,7 @@ contract Discover is ApproveAndCallFallBack, BancorFormula {
|
|||||||
* @param _amount uint, included for approveAndCallFallBack
|
* @param _amount uint, included for approveAndCallFallBack
|
||||||
*/
|
*/
|
||||||
function downvote(bytes32 _id, uint _amount) external {
|
function downvote(bytes32 _id, uint _amount) external {
|
||||||
(,,uint c) = downvoteCost(_id);
|
_downvote(msg.sender, _id, _amount);
|
||||||
require(_amount == c, "Incorrect amount: valid iff effect on ranking is 1%");
|
|
||||||
_downvote(msg.sender, _id, c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,28 +1,48 @@
|
|||||||
|
/* global web3 */
|
||||||
import utils from './utils'
|
import utils from './utils'
|
||||||
|
import EmbarkJS from '../../embarkArtifacts/embarkjs'
|
||||||
|
|
||||||
|
import * as IPFSService from './ipfs'
|
||||||
import SNTService from './services/contracts-services/snt-service/snt-service'
|
import SNTService from './services/contracts-services/snt-service/snt-service'
|
||||||
import DiscoverService from './services/contracts-services/discover-service/discover-service'
|
import DiscoverService from './services/contracts-services/discover-service/discover-service'
|
||||||
|
|
||||||
import BlockchainConfig from './services/config'
|
const initServices = function() {
|
||||||
|
|
||||||
const init = function() {
|
|
||||||
try {
|
|
||||||
BlockchainConfig()
|
|
||||||
|
|
||||||
const sharedContext = {
|
const sharedContext = {
|
||||||
account: '',
|
account: '0x0000000000000000000000000000000000000000',
|
||||||
}
|
}
|
||||||
|
|
||||||
sharedContext.SNTService = new SNTService(sharedContext)
|
sharedContext.SNTService = new SNTService(sharedContext)
|
||||||
sharedContext.DiscoverService = new DiscoverService(sharedContext)
|
sharedContext.DiscoverService = new DiscoverService(sharedContext)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
IPFSService,
|
||||||
SNTService: sharedContext.SNTService,
|
SNTService: sharedContext.SNTService,
|
||||||
DiscoverService: sharedContext.DiscoverService,
|
DiscoverService: sharedContext.DiscoverService,
|
||||||
utils,
|
utils,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getInstance = async () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const returnInstance = () => {
|
||||||
|
try {
|
||||||
|
const services = initServices()
|
||||||
|
resolve(services)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error.message)
|
reject(error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { init, utils }
|
if (web3.currentProvider) {
|
||||||
|
returnInstance()
|
||||||
|
} else {
|
||||||
|
EmbarkJS.onReady(err => {
|
||||||
|
if (err) reject(err)
|
||||||
|
|
||||||
|
returnInstance()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { getInstance, utils }
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as helpers from './helpers'
|
import * as helpers from './helpers'
|
||||||
import EmbarkJSService from '../services/embark-service/embark-service'
|
import EmbarkJS from '../../../embarkArtifacts/embarkjs'
|
||||||
|
|
||||||
const checkIPFSAvailability = async () => {
|
const checkIPFSAvailability = async () => {
|
||||||
const isAvailable = await EmbarkJSService.Storage.isAvailable()
|
const isAvailable = await EmbarkJS.Storage.isAvailable()
|
||||||
if (!isAvailable) {
|
if (!isAvailable) {
|
||||||
throw new Error('IPFS Storage is unavailable')
|
throw new Error('IPFS Storage is unavailable')
|
||||||
}
|
}
|
||||||
@ -15,11 +15,11 @@ const uploadImage = async base64Image => {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
return EmbarkJSService.Storage.uploadFile(imageFile)
|
return EmbarkJS.Storage.uploadFile(imageFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadMetadata = async metadata => {
|
const uploadMetadata = async metadata => {
|
||||||
const hash = await EmbarkJSService.Storage.saveText(metadata)
|
const hash = await EmbarkJS.Storage.saveText(metadata)
|
||||||
return helpers.getBytes32FromIpfsHash(hash)
|
return helpers.getBytes32FromIpfsHash(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,11 +40,11 @@ export const uploadDAppMetadata = async metadata => {
|
|||||||
|
|
||||||
const retrieveMetadata = async metadataBytes32 => {
|
const retrieveMetadata = async metadataBytes32 => {
|
||||||
const metadataHash = helpers.getIpfsHashFromBytes32(metadataBytes32)
|
const metadataHash = helpers.getIpfsHashFromBytes32(metadataBytes32)
|
||||||
return EmbarkJSService.Storage.get(metadataHash)
|
return EmbarkJS.Storage.get(metadataHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
const retrieveImageUrl = async imageHash => {
|
const retrieveImageUrl = async imageHash => {
|
||||||
return EmbarkJSService.Storage.getUrl(imageHash)
|
return EmbarkJS.Storage.getUrl(imageHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const retrieveDAppMetadataByHash = async metadataBytes32 => {
|
export const retrieveDAppMetadataByHash = async metadataBytes32 => {
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
/* global web3 */
|
|
||||||
import Web3 from '../../../embarkArtifacts/modules/web3'
|
|
||||||
|
|
||||||
// Todo: Should be moved to .env
|
|
||||||
const RPC_URL = 'https://ropsten.infura.io/v3/'
|
|
||||||
|
|
||||||
export default function() {
|
|
||||||
web3 = new Web3(new Web3.providers.HttpProvider(RPC_URL))
|
|
||||||
}
|
|
@ -1,32 +1,32 @@
|
|||||||
/* global web3 */
|
/* global web3 */
|
||||||
|
|
||||||
import EmbarkJSService from '../embark-service/embark-service'
|
import EmbarkJS from '../../../../embarkArtifacts/embarkjs'
|
||||||
|
|
||||||
|
const getAccount = async () => {
|
||||||
|
try {
|
||||||
|
const account = (await EmbarkJS.Blockchain.Providers.web3.getAccounts())[0]
|
||||||
|
return account || (await EmbarkJS.enableEthereum())[0]
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
'Could not unlock an account. Consider installing Status on your mobile or Metamask extension',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class BlockchainService {
|
class BlockchainService {
|
||||||
constructor(sharedContext, contract, Validator) {
|
constructor(sharedContext, contract, Validator) {
|
||||||
this.contract = contract.address
|
this.contract = contract.address
|
||||||
contract.setProvider(web3.currentProvider)
|
|
||||||
|
|
||||||
this.sharedContext = sharedContext
|
this.sharedContext = sharedContext
|
||||||
this.validator = new Validator(this)
|
this.validator = new Validator(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
async __unlockServiceAccount() {
|
async __unlockServiceAccount() {
|
||||||
// const accounts = await EmbarkJS.Blockchain.Providers.web3.getAccounts()
|
if (web3 && EmbarkJS.Blockchain.Providers.web3) {
|
||||||
// // if (accounts.length > 0) {
|
this.sharedContext.account = await getAccount()
|
||||||
// this.sharedContext.account = accounts[0]
|
} else {
|
||||||
// } else {
|
throw new Error('web3 is missing')
|
||||||
// const provider = global.web3.currentProvider
|
|
||||||
// Check for undefined
|
|
||||||
// console.log(await global.web3.eth.getAccounts())
|
|
||||||
const accounts = await EmbarkJSService.enableEthereum()
|
|
||||||
if (accounts) {
|
|
||||||
this.sharedContext.account = accounts[0]
|
|
||||||
}
|
}
|
||||||
// global.web3.setProvider(provider)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// throw new Error('Could not unlock an account or web3 is missing')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,30 +16,37 @@ class DiscoverService extends BlockchainService {
|
|||||||
async upVoteEffect(id, amount) {
|
async upVoteEffect(id, amount) {
|
||||||
await this.validator.validateUpVoteEffect(id, amount)
|
await this.validator.validateUpVoteEffect(id, amount)
|
||||||
|
|
||||||
return DiscoverContract.methods.upvoteEffect(id, amount).call()
|
return DiscoverContract.methods
|
||||||
|
.upvoteEffect(id, amount)
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
}
|
}
|
||||||
|
|
||||||
async downVoteCost(id) {
|
async downVoteCost(id) {
|
||||||
const dapp = await this.getDAppById(id)
|
const dapp = await this.getDAppById(id)
|
||||||
return DiscoverContract.methods.downvoteCost(dapp.id).call()
|
return DiscoverContract.methods
|
||||||
|
.downvoteCost(dapp.id)
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDAppsCount() {
|
async getDAppsCount() {
|
||||||
return DiscoverContract.methods.getDAppsCount().call()
|
return DiscoverContract.methods
|
||||||
|
.getDAppsCount()
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDApps() {
|
async getDApps() {
|
||||||
const dapps = []
|
const dapps = []
|
||||||
const dappsCount = await DiscoverContract.methods.getDAppsCount().call()
|
const dappsCount = await DiscoverContract.methods
|
||||||
|
.getDAppsCount()
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < dappsCount; i++) {
|
for (let i = 0; i < dappsCount; i++) {
|
||||||
const dapp = await DiscoverContract.methods.dapps(i).call()
|
const dapp = await DiscoverContract.methods
|
||||||
|
.dapps(i)
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
dapp.metadata = await ipfsSDK.retrieveDAppMetadataByHash(dapp.metadata)
|
dapp.metadata = await ipfsSDK.retrieveDAppMetadataByHash(dapp.metadata)
|
||||||
|
|
||||||
dapps.push(dapp)
|
dapps.push(dapp)
|
||||||
}
|
}
|
||||||
|
|
||||||
return dapps
|
return dapps
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Error fetching dapps. Details: ${error.message}`)
|
throw new Error(`Error fetching dapps. Details: ${error.message}`)
|
||||||
@ -49,8 +56,12 @@ class DiscoverService extends BlockchainService {
|
|||||||
async getDAppById(id) {
|
async getDAppById(id) {
|
||||||
let dapp
|
let dapp
|
||||||
try {
|
try {
|
||||||
const dappId = await DiscoverContract.methods.id2index(id).call()
|
const dappId = await DiscoverContract.methods
|
||||||
dapp = await DiscoverContract.methods.dapps(dappId).call()
|
.id2index(id)
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
|
dapp = await DiscoverContract.methods
|
||||||
|
.dapps(dappId)
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error('Searching DApp does not exists')
|
throw new Error('Searching DApp does not exists')
|
||||||
}
|
}
|
||||||
@ -74,11 +85,15 @@ class DiscoverService extends BlockchainService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async safeMax() {
|
async safeMax() {
|
||||||
return DiscoverContract.methods.safeMax().call()
|
return DiscoverContract.methods
|
||||||
|
.safeMax()
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
}
|
}
|
||||||
|
|
||||||
async isDAppExists(id) {
|
async isDAppExists(id) {
|
||||||
return DiscoverContract.methods.existingIDs(id).call()
|
return DiscoverContract.methods
|
||||||
|
.existingIDs(id)
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transaction methods
|
// Transaction methods
|
||||||
@ -114,10 +129,13 @@ class DiscoverService extends BlockchainService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async downVote(id, amount) {
|
async downVote(id) {
|
||||||
await this.validator.validateDownVoting(id, amount)
|
const dapp = await this.getDAppById(id)
|
||||||
|
const amount = (await this.downVoteCost(dapp.id)).c
|
||||||
|
|
||||||
const callData = DiscoverContract.methods.downvote(id, amount).encodeABI()
|
const callData = DiscoverContract.methods
|
||||||
|
.downvote(dapp.id, amount)
|
||||||
|
.encodeABI()
|
||||||
return this.sharedContext.SNTService.approveAndCall(
|
return this.sharedContext.SNTService.approveAndCall(
|
||||||
this.contract,
|
this.contract,
|
||||||
amount,
|
amount,
|
||||||
|
@ -41,15 +41,6 @@ class DiscoverValidator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateDownVoting(id, amount) {
|
|
||||||
const dapp = await this.service.getDAppById(id)
|
|
||||||
|
|
||||||
const downVoteCost = await this.service.downVoteCost(dapp.id)
|
|
||||||
if (downVoteCost.c != amount) {
|
|
||||||
throw new Error('Incorrect amount: valid if effect on ranking is 1%')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async validateWithdrawing(id, amount) {
|
async validateWithdrawing(id, amount) {
|
||||||
const dapp = await this.service.getDAppById(id)
|
const dapp = await this.service.getDAppById(id)
|
||||||
|
|
||||||
|
@ -11,19 +11,27 @@ class SNTService extends BlockchainService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async allowance(from, to) {
|
async allowance(from, to) {
|
||||||
return SNTToken.methods.allowance(from, to).call()
|
return SNTToken.methods
|
||||||
|
.allowance(from, to)
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
}
|
}
|
||||||
|
|
||||||
async balanceOf(account) {
|
async balanceOf(account) {
|
||||||
return SNTToken.methods.balanceOf(account).call()
|
return SNTToken.methods
|
||||||
|
.balanceOf(account)
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
}
|
}
|
||||||
|
|
||||||
async controller() {
|
async controller() {
|
||||||
return SNTToken.methods.controller().call()
|
return SNTToken.methods
|
||||||
|
.controller()
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
}
|
}
|
||||||
|
|
||||||
async transferable() {
|
async transferable() {
|
||||||
return SNTToken.methods.transfersEnabled().call()
|
return SNTToken.methods
|
||||||
|
.transfersEnabled()
|
||||||
|
.call({ from: this.sharedContext.account })
|
||||||
}
|
}
|
||||||
|
|
||||||
async approveAndCall(spender, amount, callData) {
|
async approveAndCall(spender, amount, callData) {
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
import EmbarkJS from '../../../../embarkArtifacts/embarkjs'
|
|
||||||
|
|
||||||
class EmbarkService {
|
|
||||||
constructor() {
|
|
||||||
if (!EmbarkService.instance) {
|
|
||||||
EmbarkJS.Storage.setProvider('ipfs')
|
|
||||||
EmbarkService.instance = EmbarkJS
|
|
||||||
}
|
|
||||||
|
|
||||||
return EmbarkService.instance
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default new EmbarkService()
|
|
@ -3,7 +3,7 @@ import exampleImage from './dapp.image'
|
|||||||
|
|
||||||
import BlockchainSDK from '../../common/blockchain'
|
import BlockchainSDK from '../../common/blockchain'
|
||||||
|
|
||||||
const SERVICES = BlockchainSDK.init()
|
let SERVICES = ''
|
||||||
|
|
||||||
const DAPP_DATA = {
|
const DAPP_DATA = {
|
||||||
name: 'Test1',
|
name: 'Test1',
|
||||||
@ -35,7 +35,7 @@ class Example extends React.Component {
|
|||||||
|
|
||||||
async createDApp() {
|
async createDApp() {
|
||||||
await SERVICES.SNTService.generateTokens()
|
await SERVICES.SNTService.generateTokens()
|
||||||
return SERVICES.DiscoverService.createDApp(10000, DAPP_DATA)
|
// return SERVICES.DiscoverService.createDApp(10000, DAPP_DATA)
|
||||||
}
|
}
|
||||||
|
|
||||||
async upvote(id) {
|
async upvote(id) {
|
||||||
@ -64,8 +64,9 @@ class Example extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async logDiscoverMethods() {
|
async logDiscoverMethods() {
|
||||||
console.log(await SERVICES.DiscoverService.getDApps())
|
SERVICES = await BlockchainSDK.getInstance()
|
||||||
// const createdDApp = await this.createDApp()
|
// console.log(await SERVICES.DiscoverService.getDApps())
|
||||||
|
const createdDApp = await this.createDApp()
|
||||||
|
|
||||||
// const dappData = await this.getFullDApp(createdDApp.id)
|
// const dappData = await this.getFullDApp(createdDApp.id)
|
||||||
// console.log(`Created DApp : ${JSON.stringify(dappData)}`)
|
// console.log(`Created DApp : ${JSON.stringify(dappData)}`)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// import hardcodedDapps from '../../common/data/dapps'
|
// import hardcodedDapps from '../../common/data/dapps'
|
||||||
import * as Categories from '../../common/data/categories'
|
import * as Categories from '../../common/data/categories'
|
||||||
import reducerUtil from '../../common/utils/reducer'
|
import reducerUtil from '../../common/utils/reducer'
|
||||||
// import BlockchainTool from '../../common/blockchain'
|
import BlockchainSDK from '../../common/blockchain'
|
||||||
|
|
||||||
const ON_FINISH_FETCH_ALL_DAPPS_ACTION = 'ON_FINISH_FETCH_ALL_DAPPS_ACTION'
|
const ON_FINISH_FETCH_ALL_DAPPS_ACTION = 'ON_FINISH_FETCH_ALL_DAPPS_ACTION'
|
||||||
|
|
||||||
@ -18,16 +18,6 @@ const ON_ADD_NEW_DAPP = 'ON_ADD_NEW_DAPP'
|
|||||||
const RECENTLY_ADDED_SIZE = 50
|
const RECENTLY_ADDED_SIZE = 50
|
||||||
const HIGHEST_RANKED_SIZE = 50
|
const HIGHEST_RANKED_SIZE = 50
|
||||||
|
|
||||||
// const BlockchainSDK = BlockchainTool.init()
|
|
||||||
const BlockchainSDK = { DiscoverService: {} }
|
|
||||||
BlockchainSDK.DiscoverService.getDApps = () => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve(hardcodedDapps)
|
|
||||||
}, 100)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
class DappsState {
|
class DappsState {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.items = []
|
this.items = []
|
||||||
@ -100,9 +90,14 @@ export const onFinishFetchByCategoryAction = (category, dapps) => ({
|
|||||||
const fetchAllDappsInState = async (dispatch, getState) => {
|
const fetchAllDappsInState = async (dispatch, getState) => {
|
||||||
const stateDapps = getState().dapps
|
const stateDapps = getState().dapps
|
||||||
if (stateDapps.dapps === null) {
|
if (stateDapps.dapps === null) {
|
||||||
let dapps = await BlockchainSDK.DiscoverService.getDApps()
|
const blockchain = await BlockchainSDK.getInstance()
|
||||||
|
let dapps = await blockchain.DiscoverService.getDApps()
|
||||||
|
|
||||||
dapps = dapps.map(dapp => {
|
dapps = dapps.map(dapp => {
|
||||||
return Object.assign(dapp.metadata, { sntValue: parseInt(dapp.rate, 10) })
|
return Object.assign(dapp.metadata, {
|
||||||
|
id: dapp.id,
|
||||||
|
sntValue: parseInt(dapp.effectiveBalance, 10),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
dapps.sort((a, b) => {
|
dapps.sort((a, b) => {
|
||||||
return b.sntValue - a.sntValue
|
return b.sntValue - a.sntValue
|
||||||
@ -272,7 +267,7 @@ const onAddNewDapp = (state, dapp) => {
|
|||||||
state.dappsCategoryMap.forEach((dappState, category_) => {
|
state.dappsCategoryMap.forEach((dappState, category_) => {
|
||||||
dappsCategoryMap.set(category_, dappState)
|
dappsCategoryMap.set(category_, dappState)
|
||||||
})
|
})
|
||||||
const dappState = dappsCategoryMap.get(dapp.metadata.category)
|
const dappState = dappsCategoryMap.get(dapp.category)
|
||||||
insertDappIntoSortedArray(dappState.items, dapp, (target, dappItem) => {
|
insertDappIntoSortedArray(dappState.items, dapp, (target, dappItem) => {
|
||||||
return target.sntValue < dappItem.sntValue
|
return target.sntValue < dappItem.sntValue
|
||||||
})
|
})
|
||||||
|
@ -5,16 +5,7 @@ import {
|
|||||||
checkTransactionStatusAction,
|
checkTransactionStatusAction,
|
||||||
} from '../TransactionStatus/TransactionStatus.recuder'
|
} from '../TransactionStatus/TransactionStatus.recuder'
|
||||||
|
|
||||||
// import BlockchainTool from '../../common/blockchain'
|
import BlockchainSDK from '../../common/blockchain'
|
||||||
|
|
||||||
// const BlockchainSDK = BlockchainTool.init()
|
|
||||||
const BlockchainSDK = { DiscoverService: {} }
|
|
||||||
BlockchainSDK.DiscoverService.createDapp = async (snt, dapp) => {
|
|
||||||
return {
|
|
||||||
tx: '0x3513rewrsdfsdf',
|
|
||||||
id: 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const SHOW_SUBMIT = 'SHOW_SUBMIT'
|
const SHOW_SUBMIT = 'SHOW_SUBMIT'
|
||||||
const CLOSE_SUBMIT = 'CLOSE_SUBMIT'
|
const CLOSE_SUBMIT = 'CLOSE_SUBMIT'
|
||||||
@ -98,7 +89,8 @@ export const onImgDoneAction = imgBase64 => ({
|
|||||||
export const submitAction = dapp => {
|
export const submitAction = dapp => {
|
||||||
return async dispatch => {
|
return async dispatch => {
|
||||||
dispatch(closeSubmitAction())
|
dispatch(closeSubmitAction())
|
||||||
const { tx, id } = await BlockchainSDK.DiscoverService.createDApp(1, {
|
const blockchain = await BlockchainSDK.getInstance()
|
||||||
|
const { tx, id } = await blockchain.DiscoverService.createDApp(1, {
|
||||||
name: dapp.name,
|
name: dapp.name,
|
||||||
url: dapp.url,
|
url: dapp.url,
|
||||||
desc: dapp.desc,
|
desc: dapp.desc,
|
||||||
|
@ -5,39 +5,13 @@ import {
|
|||||||
transactionStatusInitInstance,
|
transactionStatusInitInstance,
|
||||||
} from './TransactionStatus.utilities'
|
} from './TransactionStatus.utilities'
|
||||||
import { onAddNewDappAction } from '../Dapps/Dapps.reducer'
|
import { onAddNewDappAction } from '../Dapps/Dapps.reducer'
|
||||||
// import BlockchainTool from '../../common/blockchain'
|
import BlockchainSDK from '../../common/blockchain'
|
||||||
|
|
||||||
const HIDE = 'HIDE'
|
const HIDE = 'HIDE'
|
||||||
const ON_START_PROGRESS = 'ON_START_PROGRESS'
|
const ON_START_PROGRESS = 'ON_START_PROGRESS'
|
||||||
const ON_RECEIVE_TRANSACTION_TX = 'ON_RECEIVE_TRANSACTION_TX'
|
const ON_RECEIVE_TRANSACTION_TX = 'ON_RECEIVE_TRANSACTION_TX'
|
||||||
const ON_CHANGE_TRANSACTION_STATUS_DATA = 'ON_CHANGE_TRANSACTION_STATUS_DATA'
|
const ON_CHANGE_TRANSACTION_STATUS_DATA = 'ON_CHANGE_TRANSACTION_STATUS_DATA'
|
||||||
|
|
||||||
// const BlockchainSDK = BlockchainTool.init()
|
|
||||||
const BlockchainSDK = { DiscoverService: {} }
|
|
||||||
BlockchainSDK.DiscoverService.getTxStatus = async tx => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve(1)
|
|
||||||
}, 5000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
BlockchainSDK.DiscoverService.getDAppDataById = async id => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
resolve({
|
|
||||||
metadata: {
|
|
||||||
name: 'Newly added',
|
|
||||||
url: 'https://www.astroledger.org/#/onSale',
|
|
||||||
description: 'Funding space grants with blockchain star naming',
|
|
||||||
image: '/images/dapps/astroledger.svg',
|
|
||||||
category: 'EXCHANGES',
|
|
||||||
dateAdded: '2019-10-10',
|
|
||||||
categoryPosition: 2,
|
|
||||||
},
|
|
||||||
rate: 10002345,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const hideAction = () => ({
|
export const hideAction = () => ({
|
||||||
type: HIDE,
|
type: HIDE,
|
||||||
payload: null,
|
payload: null,
|
||||||
@ -73,11 +47,13 @@ export const checkTransactionStatusAction = tx => {
|
|||||||
default:
|
default:
|
||||||
case 1:
|
case 1:
|
||||||
transacationStatus.setPublished(true)
|
transacationStatus.setPublished(true)
|
||||||
dapp = await BlockchainSDK.DiscoverService.getDAppDataById(
|
const blockchain = await BlockchainSDK.getInstance()
|
||||||
|
dapp = await blockchain.DiscoverService.getDAppDataById(
|
||||||
transacationStatus.dappId,
|
transacationStatus.dappId,
|
||||||
)
|
)
|
||||||
dapp = Object.assign(dapp.metadata, {
|
dapp = Object.assign(dapp.metadata, {
|
||||||
sntValue: parseInt(dapp.rate, 10),
|
id: dapp.id,
|
||||||
|
sntValue: parseInt(dapp.effectiveBalance, 10),
|
||||||
})
|
})
|
||||||
dispatch(onAddNewDappAction(dapp))
|
dispatch(onAddNewDappAction(dapp))
|
||||||
break
|
break
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import voteInitialState from '../../common/data/vote'
|
import voteInitialState from '../../common/data/vote'
|
||||||
import reducerUtil from '../../common/utils/reducer'
|
import reducerUtil from '../../common/utils/reducer'
|
||||||
|
import BlockchainSDK from '../../common/blockchain'
|
||||||
|
|
||||||
const SHOW_UP_VOTE = 'SHOW_UP_VOTE'
|
const SHOW_UP_VOTE = 'SHOW_UP_VOTE'
|
||||||
const SHOW_DOWN_VOTE = 'SHOW_DOWN_VOTE'
|
const SHOW_DOWN_VOTE = 'SHOW_DOWN_VOTE'
|
||||||
@ -9,29 +10,6 @@ const SWITCH_TO_DOWNVOTE = 'SWITCH_TO_DOWNVOTE'
|
|||||||
const ON_INPUT_SNT_VALUE = 'ON_INPUT_SNT_VALUE'
|
const ON_INPUT_SNT_VALUE = 'ON_INPUT_SNT_VALUE'
|
||||||
const UPDATE_AFTER_VOTING_VALUES = 'UPDATE_AFTER_VOTING_VALUES'
|
const UPDATE_AFTER_VOTING_VALUES = 'UPDATE_AFTER_VOTING_VALUES'
|
||||||
|
|
||||||
const BlockchainSDK = { DiscoverService: {} }
|
|
||||||
BlockchainSDK.DiscoverService.upVoteEffect = (id, amount) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve(amount)
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
BlockchainSDK.DiscoverService.upVote = (id, amount) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve('0xfae78787fa79')
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
BlockchainSDK.DiscoverService.downVote = (id, amount) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve('0xfae78787fa79')
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const showUpVoteAction = dapp => {
|
export const showUpVoteAction = dapp => {
|
||||||
window.location.hash = 'vote'
|
window.location.hash = 'vote'
|
||||||
return {
|
return {
|
||||||
@ -85,7 +63,8 @@ export const fetchVoteRatingAction = (dapp, isUpvote, sntValue) => {
|
|||||||
if (isUpvote === true && voteState.sntValue !== sntValue.toString()) return
|
if (isUpvote === true && voteState.sntValue !== sntValue.toString()) return
|
||||||
if (sntValue === 0) return
|
if (sntValue === 0) return
|
||||||
|
|
||||||
const rating = await BlockchainSDK.DiscoverService.upVoteEffect(
|
const blockchain = await BlockchainSDK.getInstance()
|
||||||
|
const rating = await blockchain.DiscoverService.upVoteEffect(
|
||||||
dapp.id,
|
dapp.id,
|
||||||
sntValue,
|
sntValue,
|
||||||
)
|
)
|
||||||
@ -97,7 +76,8 @@ export const fetchVoteRatingAction = (dapp, isUpvote, sntValue) => {
|
|||||||
export const upVoteAction = (dapp, amount) => {
|
export const upVoteAction = (dapp, amount) => {
|
||||||
return async dispatch => {
|
return async dispatch => {
|
||||||
dispatch(closeVoteAction())
|
dispatch(closeVoteAction())
|
||||||
const tx = await BlockchainSDK.DiscoverService.upVote(dapp.id, amount)
|
const blockchain = await BlockchainSDK.getInstance()
|
||||||
|
const tx = await blockchain.DiscoverService.upVote(dapp.id, amount)
|
||||||
console.log('upvote', tx)
|
console.log('upvote', tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user