Skip to content

Commit

Permalink
Merge branch 'ps/issue2' into 'develop'
Browse files Browse the repository at this point in the history
chore: added NFT minting and selling

Closes #13, #11, and #2

See merge request PBSA/dapps/NFT-store!2
  • Loading branch information
RoshanSyed committed May 26, 2021
2 parents 297a5fa + 1e50294 commit 8268693
Show file tree
Hide file tree
Showing 22 changed files with 598 additions and 39 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules/
data/
public/uploads
/config/*-local.json
.vscode
**.DS_Store
Expand Down
7 changes: 7 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ handlebars = handlebars.create({
>
<use xlink:href="/dist/feather-sprite.svg#${icon}"/>
</svg>`;
},
eqHidden: (lvalue, rvalue) => {
return lvalue === rvalue ? 'd-none' : 'd-flex';
},
neqHidden: (lvalue, rvalue) => {
return lvalue !== rvalue ? 'd-none' : 'd-flex';
}
}
});
Expand All @@ -348,6 +354,7 @@ if(!config.secretSession || config.secretSession === ''){
app.enable('trust proxy');
app.use(helmet());
app.set('port', process.env.PORT || 1111);
app.use('/imgs', express.static(path.join(__dirname, 'uploads')));
app.use(logger('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser(config.secretCookie));
Expand Down
2 changes: 2 additions & 0 deletions config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"peeridClientSecret": "Qv16Go2MPjBhn8P1Sdc7LgzPnr18F3JLGjC7F71nXw",
"peeridRedirectUri": "https://nftstore.peerplays.download/peerid_auth/redirect",
"peerplaysAssetID": "1.3.0",
"peerplaysAssetSymbol": "TEST",
"peerplaysAssetPrecision": 5,
"peerplaysAccountID": "1.2.73",
"commission": 10,
"categories": ["Digital Art", "Photographs", "Oil Paintings"]
Expand Down
22 changes: 15 additions & 7 deletions config/settingsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,31 +191,39 @@
},
"peeridUrl": {
"type": "string",
"default": false
"default": ""
},
"peeridClientID": {
"type": "string",
"default": false
"default": ""
},
"peeridClientSecret": {
"type": "string",
"default": false
"default": ""
},
"peeridRedirectUri": {
"type": "string",
"default": false
"default": ""
},
"peerplaysAssetID": {
"type": "string",
"default": false
"default": ""
},
"peerplaysAssetSymbol": {
"type": "string",
"default": ""
},
"peerplaysAssetPrecision": {
"type": "number",
"default": 5
},
"peerplaysAccountID": {
"type": "string",
"default": false
"default": ""
},
"commission": {
"type": "number",
"default": false
"default": 0
},
"categories": {
"type": "array"
Expand Down
1 change: 1 addition & 0 deletions lib/paginate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const PeerplaysService = require('../services/PeerplaysService');
const {
getConfig
} = require('./config');
Expand Down
15 changes: 14 additions & 1 deletion lib/schemas/editProduct.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"isNotEmpty": true,
"minLength": 6
},
"productTitle": {
"type": "string",
"isNotEmpty": true,
"minLength": 2
},
"productDescription": {
"type": "string",
"isNotEmpty": true,
Expand All @@ -25,6 +30,10 @@
"productPermalink": {
"type": "string",
"isNotEmpty": true
},
"owner": {
"type": "string",
"isNotEmpty": true
}
},
"errorMessage": {
Expand All @@ -36,6 +45,10 @@
}
},
"required": [
"productId"
"productId",
"nftMetadataID",
"productTitle",
"productDescription",
"owner"
]
}
13 changes: 12 additions & 1 deletion lib/schemas/newProduct.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"isNotEmpty": true,
"minLength": 6
},
"productTitle": {
"type": "string",
"isNotEmpty": true,
"minLength": 2
},
"productDescription": {
"type": "string",
"isNotEmpty": true,
Expand All @@ -22,6 +27,10 @@
"productPermalink": {
"type": "string",
"isNotEmpty": true
},
"owner": {
"type": "string",
"isNotEmpty": true
}
},
"errorMessage": {
Expand All @@ -33,6 +42,8 @@
},
"required": [
"nftMetadataID",
"productDescription"
"productTitle",
"productDescription",
"owner"
]
}
5 changes: 5 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@
"Save product": "Save NFT",
"Edit product": "Edit NFT",
"Product title": "NFT Title",
"Product quantity": "Quantity",
"Product image": "NFT Image",
"Product price": "NFT price",
"Product min price": "Min. price",
"Product max price": "Max. price",
"Product allow bid": "Allow bidding on the NFT",
"Sale end": "Sale end date",
"Published": "Published",
"Draft": "Draft",
"Stock level": "Stock level",
Expand Down
5 changes: 5 additions & 0 deletions locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@
"Save product": "Salva NFT",
"Edit product": "Modifica NFT",
"Product title": "Titolo NFT",
"Product quantity": "Quantità",
"Product image": "Immagine NFT",
"Product price": "Prezzo NFT",
"Product min price": "Prezzo minimo",
"Product max price": "Prezzo massimo",
"Product allow bid": "Consenti offerte sulla NFT",
"Sale end": "Data di fine della vendita",
"Published": "Pubblicato",
"Draft": "Bozza",
"Stock level": "Livello stock",
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ $(document).ready(function (){
// applies an product filter
$(document).on('click', '#btn_product_filter', function(e){
if($('#product_filter').val() !== ''){
window.location.href = '/products/filter/' + $('#product_filter').val();
window.location.href = '/customer/products/filter/' + $('#product_filter').val();
}else{
showNotification('Please enter a keyword to filter', 'danger');
}
Expand Down
131 changes: 129 additions & 2 deletions public/javascripts/expressCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ $(document).ready(function (){
processData: false
})
.done(function(msg){
showNotification(msg.message, 'success', false, '/customer/product/edit/' + msg.productId);
showNotification(msg.message, 'success', false, '/customer/products/1');
})
.fail(function(msg){
if(msg.responseJSON.length > 0){
if(msg.responseJSON && msg.responseJSON.length > 0){
var errorMessages = validationErrors(msg.responseJSON);
$('#validationModalBody').html(errorMessages);
$('#validationModal').modal('show');
Expand Down Expand Up @@ -326,6 +326,126 @@ $(document).ready(function (){
window.location.replace('/customer/setup');
});

$('#productButtons div button').on('click', function(e){
if($(this).text() === 'Mint') {
var productId = $(this).attr('data-id');
$('.modal-body #productId').val(productId);
$('#nftMintModal').modal('show');
} else if($(this).text() === 'Sell') {
var productId = $(this).attr('data-id');
$('.modal-body #sellProductId').val(productId);
$('#sellNFTModal').modal('show');
$('#saleEnd').datetimepicker({
uiLibrary: 'bootstrap4',
footer: true,
modal: true,
showOtherMonths: true
});
}
});

// Mint NFT
$(document).on('click', '#buttonMint', function(e){
$.ajax({
method: 'POST',
url: '/customer/product/mint',
data: {
productId: $('#productId').val(),
quantity: $('#productQuantity').val()
}
})
.done(function(msg){
showNotification(msg.message, 'success', true);
})
.fail(function(msg){
if(msg.responseJSON.message === 'You need to be logged in to Mint NFT'){
showNotification(msg.responseJSON.message, 'danger', false, '/customer/products');
}

if(msg.responseJSON.message === 'Product not found'){
showNotification(msg.responseJSON.message, 'danger', false, '/customer/products');
}

showNotification(msg.responseJSON.message, 'danger');
});
});

$(document).on('click','#productSellTypeCheckbox', function(e) {
var assetSymbol = $('#assetSymbol').val();
if($('#productSellTypeCheckbox').prop('checked')){
const bidHtml = `<div class="form-group">
<label for="productMinPrice" class="control-label">Min. Price (${assetSymbol}) *</label>
<input type="number" id="productMinPrice" class="form-control" min="0" step="any" required/>
</div>
<div class="form-group">
<label for="productMaxPrice" class="control-label">Max. Price (${assetSymbol}) *</label>
<input type="number" id="productMaxPrice" class="form-control" min="0" step="any" required/>
</div>
<div class="form-group">
<label for="saleEnd" class="control-label">Sale end date *</label>
<input id="saleEnd" />
</div>`;
$('#sellNFTFormWrapper').html(bidHtml);
$('#saleEnd').datetimepicker({
uiLibrary: 'bootstrap4',
footer: true,
modal: true,
showOtherMonths: true
});
} else {
const fixedPriceHtml = `<div class="form-group">
<label for="productSellQuantity" class="control-label">Quantity *</label>
<input type="number" id="productSellQuantity" class="form-control" min="0" step="1" onkeypress="return isNumberKey(event)" required/>
</div>
<div class="form-group">
<label for="productPrice" class="control-label">NFT Price (${assetSymbol}) *</label>
<input type="number" id="productPrice" class="form-control" min="0" step="any" required/>
</div>
<div class="form-group">
<label for="saleEnd" class="control-label">Sale end date *</label>
<input id="saleEnd" />
</div>`;
$('#sellNFTFormWrapper').html(fixedPriceHtml);
$('#saleEnd').datetimepicker({
uiLibrary: 'bootstrap4',
footer: true,
modal: true,
showOtherMonths: true
});
}
});

// Sell NFT
$(document).on('click', '#buttonSell', function(e){
const isBidding = $('#productSellTypeCheckbox').prop('checked');

$.ajax({
method: 'POST',
url: '/customer/product/sell',
data: {
productId: $('#sellProductId').val(),
quantity: isBidding ? 1 : $('#productSellQuantity').val(),
minPrice: isBidding ? $('#productMinPrice').val() : $('#productPrice').val(),
maxPrice: isBidding ? $('#productMaxPrice').val() : $('#productPrice').val(),
expirationDate: $('#saleEnd').val()
}
})
.done(function(msg){
showNotification(msg.message, 'success', true);
})
.fail(function(msg){
if(msg.responseJSON.message === 'You need to be logged in to Mint NFT'){
showNotification(msg.responseJSON.message, 'danger', false, '/customer/products');
}

if(msg.responseJSON.message === 'Product not found'){
showNotification(msg.responseJSON.message, 'danger', false, '/customer/products');
}

showNotification(msg.responseJSON.message, 'danger');
});
});

// call update settings API
$('#customerLogin').on('click', function(e){
if(!e.isDefaultPrevented()){
Expand Down Expand Up @@ -872,4 +992,11 @@ function validationErrors(errors){
errorMessage += `<p>${value.dataPath.replace('/', '')} - <span class="text-danger">${value.message}<span></p>`;
});
return errorMessage;
}

function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : evt.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
43 changes: 43 additions & 0 deletions public/uploads/expressCart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/logo-admin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8268693

Please sign in to comment.