Translations, fixes and additional images
This commit is contained in:
parent
2b38654eb5
commit
8c5c8f8b2c
|
@ -4,10 +4,9 @@ import "./SpaceshipToken.sol";
|
|||
import "zeppelin-solidity/contracts/token/ERC721/ERC721Holder.sol";
|
||||
|
||||
|
||||
/// @title Escrow para compra venta del token
|
||||
/// @title Escrow contract
|
||||
contract SpaceshipMarketplace is ERC721Holder {
|
||||
|
||||
// Esta estructura guarda informacion sobre las ventas
|
||||
struct Sale {
|
||||
uint spaceshipId;
|
||||
uint price;
|
||||
|
@ -25,49 +24,46 @@ contract SpaceshipMarketplace is ERC721Holder {
|
|||
event ShipSold(uint indexed spaceshipId, uint price, address indexed oldOwner, address indexed newOwner);
|
||||
|
||||
/// @notice Constructor
|
||||
/// @param _token Direccion del token
|
||||
/// @param _token Spaceship token address
|
||||
constructor(address _token) public {
|
||||
token = SpaceshipToken(_token);
|
||||
}
|
||||
|
||||
/// @notice Comprar token
|
||||
/// @param _saleId Id de la venta que se desea
|
||||
/// @notice Buy token
|
||||
/// @param _saleId Index of sales[]
|
||||
function buy(uint _saleId) public payable {
|
||||
Sale storage s = sales[_saleId];
|
||||
|
||||
// TODO: descomentar esto para evitar que el dueno compre su propia nave
|
||||
// TODO: uncomment this to avoid the owner buying his own tokens
|
||||
// require(s.owner != msg.sender);
|
||||
require(msg.value >= s.price);
|
||||
|
||||
// Devolvemos el sobrante
|
||||
uint refund = msg.value - s.price;
|
||||
if(refund > 0)
|
||||
msg.sender.transfer(refund);
|
||||
|
||||
// Transferimos el ether de la venta
|
||||
s.owner.transfer(s.price);
|
||||
|
||||
emit ShipSold(s.spaceshipId, s.price, s.owner, msg.sender);
|
||||
|
||||
// Transferimos el token
|
||||
// Transfer the token
|
||||
token.approve(msg.sender, s.spaceshipId);
|
||||
token.safeTransferFrom(address(this), msg.sender, s.spaceshipId);
|
||||
|
||||
// Eliminamos la venta
|
||||
// Delete sale
|
||||
delete spaceshipToSale[s.spaceshipId];
|
||||
Sale replacer = sales[sales.length - 1];
|
||||
sales[_saleId] = replacer;
|
||||
sales.length--;
|
||||
}
|
||||
|
||||
/// @notice Publicar token para venta
|
||||
/// @param _spaceshipId Id del token
|
||||
/// @param _price Precio de venta
|
||||
/// @notice Set token for sale
|
||||
/// @param _spaceshipId Token Id
|
||||
/// @param _price Sale price
|
||||
function forSale(uint _spaceshipId, uint _price){
|
||||
// Solo se pueden vender tus propias naves
|
||||
// You can only sell your own ships
|
||||
require(token.ownerOf(_spaceshipId) == msg.sender);
|
||||
|
||||
// Transferimos el token a este contrato escrow
|
||||
token.safeTransferFrom(msg.sender, address(this), _spaceshipId);
|
||||
|
||||
Sale memory s = Sale({
|
||||
|
@ -76,7 +72,6 @@ contract SpaceshipMarketplace is ERC721Holder {
|
|||
owner: msg.sender
|
||||
});
|
||||
|
||||
// Agregamos el token a la lista de vtokens en venta
|
||||
uint saleId = sales.push(s) - 1;
|
||||
|
||||
spaceshipToSale[_spaceshipId] = saleId;
|
||||
|
@ -84,20 +79,18 @@ contract SpaceshipMarketplace is ERC721Holder {
|
|||
emit NewSale(_spaceshipId, _price, saleId);
|
||||
}
|
||||
|
||||
/// @notice Retirar token de listado de venta
|
||||
/// @param _spaceshipId Id del token
|
||||
/// @notice Remove listing
|
||||
/// @param _spaceshipId Spaceship Id
|
||||
function withdraw(uint _spaceshipId){
|
||||
require(sales[spaceshipToSale[_spaceshipId]].owner == msg.sender);
|
||||
|
||||
// Eliminamos el registro de venta
|
||||
delete sales[spaceshipToSale[_spaceshipId]];
|
||||
delete spaceshipToSale[_spaceshipId];
|
||||
|
||||
// Transferimos nuestro token
|
||||
token.safeTransferFrom(address(this), msg.sender, _spaceshipId);
|
||||
}
|
||||
|
||||
/// @notice Cantidad de tokens a la venta
|
||||
/// @notice Ships for sale quantity
|
||||
function nSale() public view returns(uint) {
|
||||
return sales.length;
|
||||
}
|
||||
|
|
|
@ -5,9 +5,11 @@ A functionality a token marketplace requires is the ability to list and sell you
|
|||
|
||||
This approval process will be controlled via the toggle above our spaceships section, and this functionality shall be code on `app/js/components/shipList.js`.
|
||||
|
||||
Start by importing our escrow contract `SpaceshipMarketplace`:
|
||||
Start by importing our escrow contract `SpaceshipMarketplace`, `EmbarkJS` and our `SpaceshipToken` contract:
|
||||
|
||||
```
|
||||
import EmbarkJS from 'Embark/EmbarkJS';
|
||||
import SpaceshipToken from 'Embark/contracts/SpaceshipToken';
|
||||
import SpaceshipMarketplace from 'Embark/contracts/SpaceshipMarketplace';
|
||||
```
|
||||
|
||||
|
@ -76,6 +78,7 @@ componentDidMount(){
|
|||
}
|
||||
```
|
||||
|
||||
[IMAGE_HERE]
|
||||
|
||||
Finally, to sell our tokens, we need to edit the file `app/js/components/ship.js` to import our `SpaceshipMarketplace` contract and add the implementation of the `sellShip` method.
|
||||
|
||||
|
@ -142,7 +145,7 @@ _loadMarketPlace = async () => {
|
|||
price: sale.price,
|
||||
id: sale.spaceshipId,
|
||||
saleId: i,
|
||||
..._info
|
||||
...info
|
||||
};
|
||||
list.push(ship);
|
||||
}
|
||||
|
@ -196,7 +199,7 @@ buyFromMarket = () => {
|
|||
```
|
||||
|
||||
## Other features
|
||||
Congrats! you have implemented all the features of this tutorial! However, there's still some missing functionality on this DApp that would be great to build, and probably make sense to include, such as: Allow the user to cancel sales, to tranfer tokens to other addresses, trading tokens offchain (maybe through Whisper?), etc. This tutorial covers most of the patterns required to implement them, so if you're looking for an extra challenge, you can have fun building them!
|
||||
Congrats! you have implemented all the features of this tutorial! However, there's still some missing functionality on this DApp that would be great to build, and probably make sense to include, such as: Add validations to input fields, warning messages, Allow the user to cancel sales, to tranfer tokens to other addresses, trading tokens offchain (maybe through Whisper?), etc. This tutorial covers most of the patterns required to implement them, so if you're looking for an extra challenge, you can have fun building them!
|
||||
|
||||
## Conclusion
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 43 KiB |
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
Loading…
Reference in New Issue