From 2b59d0adaeb841201920b792e18f1a39c8b93d29 Mon Sep 17 00:00:00 2001 From: Juan Cazala Date: Fri, 9 Feb 2018 17:21:29 -0300 Subject: [PATCH 1/7] 0.2.10 --- .gitignore | 1 + package.json | 4 +-- pages/linker.js | 73 ++++++++++++++++++++++++++++++++++++------- src/utils/linker.ts | 11 +++++++ src/utils/uploader.ts | 37 ++++++++++++++++++++-- 5 files changed, 109 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 99146d84..cc61cbe6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .vs/ .vscode/ +.idea bower_components/ node_modules/ tmp/ diff --git a/package.json b/package.json index 3c454300..45b88670 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "decentraland", - "version": "0.2.9", + "version": "0.2.10", "description": "CLI tool for parcel management.", "main": "./dist/index.js", "scripts": { - "start": "./dev.js", + "start": "LAND_REGISTRY_CONTRACT_ADDRESS='0x7a73483784ab79257bb11b96fd62a2c3ae4fb75b' ./dev.js", "watch": "tsc --watch", "build": "npm run clean && tsc && npm run linker:build", "clean": "rimraf dist && rimraf tmp", diff --git a/pages/linker.js b/pages/linker.js index 272a8198..f96bcb55 100644 --- a/pages/linker.js +++ b/pages/linker.js @@ -1,19 +1,22 @@ import "babel-polyfill"; import React from 'react'; import Router from 'next/router'; -import { eth } from 'decentraland-commons'; +import { eth, txUtils } from 'decentraland-commons'; import { LANDRegistry } from 'decentraland-commons/dist/contracts/LANDRegistry'; async function ethereum() { - const { address } = await getContractAddress() + // const { address } = await getContractAddress() + const address = '0x7a73483784ab79257bb11b96fd62a2c3ae4fb75b' const land = new LANDRegistry(address) - await eth.connect({ contracts: [land]}) + const connected = await eth.connect({ + contracts: [LANDRegistry] + }) return { address: await eth.getAddress(), - land, - web3: eth.web3 + land: eth.getContract('LANDRegistry'), + web3: eth.web3, } } @@ -33,17 +36,31 @@ async function getIPFSKey() { return ipfsKey; } +async function getPeerId() { + const res = await fetch('/api/get-ipfs-peerid'); + const peerId = await res.json(); + return peerId; +} + async function closeServer(ok, message) { console.log('closing server:', message) await fetch(`/api/close?ok=${ok}&reason=${message}`); } +async function pinFiles (peerId, x, y) { + const res = await fetch(`http://ipfs.decentraland.zone:3000/api/pin/${peerId}/${x}/${y}`); + const { ok } = await res.json() + return ok +} + export default class Page extends React.Component { constructor(...args) { super(...args); this.state = { loading: true, + transactionLoading: false, + pinningLoading: false, error: false, address: null, tx: null @@ -51,7 +68,7 @@ export default class Page extends React.Component { } async componentDidMount() { - try { + try { let land, address, web3 try { @@ -59,12 +76,12 @@ export default class Page extends React.Component { land = res.land address = res.address web3 = res.web3 - this.setState({ loading: false, address }) } catch(err) { + console.log(err.message) this.setState({ error: `Could not connect to MetaMask` }); @@ -84,7 +101,8 @@ export default class Page extends React.Component { try { const ipfsKey = await getIPFSKey(); - this.setState({ ipfsKey }); + const peerId = await getPeerId(); + this.setState({ ipfsKey, peerId }); } catch(err) { this.setState({ error: `There was a problem getting IPNS hash of your scene.\nTry to re-upload with dcl upload.` @@ -129,10 +147,12 @@ export default class Page extends React.Component { try { console.log('update land data', coordinates, data) const tx = await land.updateManyLandData(coordinates, data) - this.setState({ tx }) - closeServer(true, 'transaction successful') + this.watchTransactions(tx, coordinates[0].x, coordinates[0].y) + this.setState({ tx, transactionLoading: true }) + // closeServer(true, 'transaction successful') } catch(err) { this.setState({loading: false, error: 'Transaction Rejected'}) + console.log(err.message) closeServer(false, 'transaction rejected') } } catch(err) { @@ -141,6 +161,17 @@ export default class Page extends React.Component { } } + async watchTransactions (tx, x, y) { + const { peerId } = this.state + await txUtils.waitForCompletion(tx) + this.setState({ transactionLoading: false, pinningLoading: true }) + const success = await pinFiles(peerId, x, y) + this.setState({ + pinningLoading: false, + error: !success ? 'Failed pinning files to ipfs' : null + }) + } + renderTxHash = () => ( this.state.tx ? (

Transaction:
@@ -155,6 +186,22 @@ export default class Page extends React.Component { this.state.error ?

{this.state.error}

: null ) + renderTransactionStatus = () => ( + this.state.tx ? + !this.state.transactionLoading ? +

{`Transaction confirmed.`}

+ :

{`Transaction pending. Will take a while...`}

+ : null + ) + + renderPinningIPFSStatus = () => ( + !this.state.error && this.state.tx && !this.state.transactionLoading ? + !this.state.pinningLoading ? +

{`Pinning Success.`}

+ :

{`Pinning pending. Will take a while...`}

+ : null + ) + render() { return (
@@ -163,8 +210,10 @@ export default class Page extends React.Component {

MetaMask address:
{this.state.loading ? "loading..." : this.state.address}

- {this.renderTxHash()} - {this.renderError()} + { this.renderTxHash() } + { this.renderTransactionStatus() } + { this.renderPinningIPFSStatus() } + { this.renderError() }