Skip to content

Commit a9b7d2a

Browse files
committed
fixes
1 parent efa9655 commit a9b7d2a

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

migrations/20171029004746-claims.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ exports.setup = function(options, seedLink) {
1717
exports.up = function(db, callback) {
1818
db.createTable('claims', {
1919
id: {
20-
type: 'int',
20+
type: 'string',
21+
length: 100,
2122
notNull: true,
22-
primaryKey: true,
23-
autoIncrement: true
23+
primaryKey: true
2424
},
2525
user_id: {
2626
type: 'string',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"nodemon": "^1.12.1",
3030
"solc": "^0.4.18",
3131
"sqlite3": "^3.1.13",
32+
"uuid": "^3.1.0",
3233
"web3": "^1.0.0-beta.24"
3334
}
3435
}

src/claim/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ const Timestamps = require('../services/timestamps');
99

1010
router.post('/', function(req, res, next) {
1111
stats(req.googleApiClient, Timestamps.yesterday(), Timestamps.today()).then(yesterdaysResult => {
12-
console.log('User', req.user);
13-
console.log('User id', req.user.id);
1412
tryToClaim(req.user.id, yesterdaysResult.reward).then((claim) => {
13+
console.log('User', req.user);
1514
console.log('Claim', claim);
1615
res.json(chain.claimCoinsForAddress(req.user.wallet, yesterdaysResult.reward, claim.id));
1716
}, (error) => {

src/models/claims.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const db = require("../services/sqlite");
22
const Timestamps = require("../services/timestamps");
3+
const uuid = require("uuid/v4");
34

45
function newClaim(userId, amount) {
56
return {
7+
id: uuid(),
68
user_id: userId,
79
amount: amount,
8-
lastTimestamp: Timestamps.today(),
10+
completed_timestamp: Timestamps.today(),
911
};
1012
}
1113

@@ -19,19 +21,20 @@ function findLastUserClaim(userId) {
1921

2022
function createClaim(claim) {
2123
db.run(
22-
"INSERT INTO claims (user_id, amount, completed_timestamp) VALUES (?, ?, ?)",
23-
claim.userId,
24+
"INSERT INTO claims (id, user_id, amount, completed_timestamp) VALUES (?, ?, ?, ?)",
25+
claim.id,
26+
claim.user_id,
2427
claim.amount,
25-
claim.completedTimestamp
28+
claim.completed_timestamp
2629
);
2730
}
2831
let tryToClaim = function(userId, amount) {
2932
return new Promise((resolve, reject) => {
3033
findLastUserClaim(userId).then(claim => {
3134
if (!claim || claim.completed_timestamp < Timestamps.today()) {
32-
newClaim = newClaim(userId, amount)
33-
createClaim(newClaim);
34-
resolve(newClaim);
35+
let nclaim = newClaim(userId, amount)
36+
createClaim(nclaim);
37+
resolve(nclaim);
3538
} else {
3639
reject('This claim exists')
3740
}

src/services/chain.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ class Chain {
2727
return false;
2828
}
2929
let promise = new Promise((resolve, reject) => {
30-
let owner = this.mainContract.methods.owner().call({}, (error, owner) => {
30+
this.mainContract.methods.owner().call({}, (error, owner) => {
31+
console.log('Owner', owner);
3132
this.web3.eth.personal.unlockAccount(owner, local.password, (error, result) => {
33+
id = Date.now();
3234
this.mainContract.methods.sendPersonalSportReward(address, amount, id).send(
3335
{from: owner},
3436
(error, result) => {

0 commit comments

Comments
 (0)