Added metadata functions and message for when there's no ships available

This commit is contained in:
Richard Ramos 2018-07-02 12:23:23 -04:00
parent 35f531281e
commit 7ec80a2270
3 changed files with 43 additions and 2 deletions

View File

@ -33,15 +33,31 @@ class AddToken extends Component {
this.setState({isSubmitting: true});
// TODO:
let attributes = {
"name": "Nave Espacial",
"image": "",
"attributes": {
"energy": this.state.energy,
"lasers": this.state.lasers,
"shield": this.state.shield
}
}
// Cargamos la imagen a IPFS
EmbarkJS.Storage.uploadFile(this.state.fileToUpload)
.then(fileHash => {
// Agregamos los datos a la lista de atributos
attributes.imageHash = fileHash;
attributes.image = 'https://ipfs.io/ipfs/' + fileHash;
// Guardamos la lista de atributos
return EmbarkJS.Storage.saveText(JSON.stringify(attributes))

View File

@ -61,6 +61,12 @@ enableMarketplace = () => {
<h3>{title}</h3>
{ wallet ? <EnableSales isSubmitting={this.state.isSubmitting} handleChange={this.enableMarketplace} salesEnabled={this.state.salesEnabled} /> : ''}
{ list.map((ship, i) => <Ship onAction={onAction} wallet={wallet} salesEnabled={salesEnabled} key={i} marketplace={marketplace} {...ship} />) }
{ list.length == 0
? <p>No hay naves disponibles</p>
: ''
}
</div>;
}

View File

@ -3,7 +3,6 @@ pragma solidity 0.4.24;
import "zeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
/**
@title Contrato base para Mexico Workshop
@dev En Status tambien hablamos espanol ;)
@ -96,4 +95,24 @@ contract SpaceshipToken is ERC721Token("CryptoSpaceships", "CST"), Ownable {
lasers = s.lasers;
shield = s.shield;
}
// Obtain metadata
function tokenURI(uint256 _spaceshipId) public view returns (string) {
Spaceship storage s = spaceships[_spaceshipId];
return strConcat("https://ipfs.io/ipfs/", string(s.metadataHash));
}
function strConcat(string _a, string _b) private returns (string) {
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
string memory ab = new string(_ba.length + _bb.length);
bytes memory bab = bytes(ab);
uint k = 0;
for (uint i = 0; i < _ba.length; i++) bab[k++] = _ba[i];
for (i = 0; i < _bb.length; i++) bab[k++] = _bb[i];
return string(bab);
}
}