Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Transactions from Ledger #1578

Merged
merged 10 commits into from
Dec 12, 2018
Merged

Conversation

marcogbarcellos
Copy link
Contributor

This PR changes the allTransactions query to support reading data either from the api OR from the ledger through either a boolean parameter on the query or an Environment variable GET_TRANSACTIONS_FROM_LEDGER .

"secret": "dvl-7749ba6ad8e62b53b18b4c30295f45d849c1",
"session_secret": "i&j@/V6Wx.`g>Aq?qQQF(>u)/Erm;3A="
}
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keys added there are outdated and unnecessary.

}
},
"stripe": {
"platformPublishableKey": "pk_test_VgSB4VSg2wb5LdAkz7p38Gw8"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stripe added there is outdated and unnecessary.

order: [['createdAt', 'DESC']],
type: args.type,
limit: args.limit,
offset: args.offset,
startDate: args.dateFrom,
endDate: args.dateTo,
});
if (!fetchDataFromLedger) return allTransactions;
Copy link
Member

@znarf znarf Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why execute and wait for allTransactions if fetchDataFromLedger is true?

I see it's used later. But why can't we fetch first from the ledger?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm I get your point, perhaps something fails when fetching data from the ledger and then makes it useless. you're right, I'll fix that.

}),
);
}
return ledgerFormattedTransactions;
Copy link
Member

@znarf znarf Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract all this block in a separated ledger lib, which should expose a getTransactions method or similar.

}
return parsedTransaction;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can also be added to the ledger lib.

},
async resolve(_, args) {
const fetchDataFromLedger = args.fetchDataFromLedger || process.env.GET_TRANSACTIONS_FROM_LEDGER || false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If args.fetchDataFromLedger is explicitly false, it will use the value of process.env.GET_TRANSACTIONS_FROM_LEDGER. This is not what we want.

@coveralls
Copy link

coveralls commented Dec 11, 2018

Coverage Status

Coverage decreased (-0.6%) to 68.474% when pulling b8f4cba on feat/ledger-get-transactions into fe6881b on master.

},
async resolve(_, args) {
let fetchDataFromLedger = process.env.GET_TRANSACTIONS_FROM_LEDGER || false;
if (args.fetchDataFromLedger) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't go in the if when args.fetchDataFromLedger is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default will be false which makes it ok as it'll only catch the if if the args are true, otherwise it will already be false OR defined by process.env.GET_TRANSACTIONS_FROM_LEDGER.

The way it'll be is:

  1. the default is false
  2. if there is process.env.GET_TRANSACTIONS_FROM_LEDGER it will go with that.
  3. if there is args.fetchDataFromLedger it'll go with that regardless the default and process.env.GET_TRANSACTIONS_FROM_LEDGER.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if (args.fetchDataFromLedger) { is not checking if args.fetchDataFromLedger is undefined or not. It's checking if args.fetchDataFromLedger is truthy or falsy. If the value is false, it's not going in the condition.

If GET_TRANSACTIONS_FROM_LEDGER is true and args.fetchDataFromLedger is false, we're not having the expected behavior.

},
},
privateMessage: {
type: GraphQLString,
resolve(transaction) {
// TODO: Put behind a login check
return transaction.getOrder().then(order => order && order.privateMessage);
return transaction.getOrder ? transaction.getOrder().then(order => order && order.privateMessage) : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add all this defensive code to check if methods are available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransactionInterface is supposed to be expecting a Sequelize Model but when we parse the transactions coming from the ledger, those transactions are just object(with some fields like the Sequelize model) but they don't have their methods. That's why the validation is necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain me why it's ok to send null there when there is no method? Aren't we expecting a value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked every return null case for those validations. I don't think we're waiting these specific values where we return null/undefined. But also in all other scenarios we have, we are using the sequelize models and the validations I added won't never be catched other than the transactionsFromLedger

@marcogbarcellos marcogbarcellos force-pushed the feat/ledger-get-transactions branch from 0dfc7d7 to b8f4cba Compare December 12, 2018 14:56
@marcogbarcellos
Copy link
Contributor Author

marcogbarcellos commented Dec 12, 2018

@znarf after adding comments on the TransactionInterface i'll be moving forward in a couple minutes if there's nothing else! thanks for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants