-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
Conversation
config/development.json
Outdated
"secret": "dvl-7749ba6ad8e62b53b18b4c30295f45d849c1", | ||
"session_secret": "i&j@/V6Wx.`g>Aq?qQQF(>u)/Erm;3A=" | ||
} | ||
}, |
There was a problem hiding this comment.
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.
config/development.json
Outdated
} | ||
}, | ||
"stripe": { | ||
"platformPublishableKey": "pk_test_VgSB4VSg2wb5LdAkz7p38Gw8" |
There was a problem hiding this comment.
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.
server/graphql/v1/queries.js
Outdated
order: [['createdAt', 'DESC']], | ||
type: args.type, | ||
limit: args.limit, | ||
offset: args.offset, | ||
startDate: args.dateFrom, | ||
endDate: args.dateTo, | ||
}); | ||
if (!fetchDataFromLedger) return allTransactions; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
server/graphql/v1/queries.js
Outdated
}), | ||
); | ||
} | ||
return ledgerFormattedTransactions; |
There was a problem hiding this comment.
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.
server/lib/transactions.js
Outdated
} | ||
return parsedTransaction; | ||
} | ||
|
There was a problem hiding this comment.
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.
server/graphql/v1/queries.js
Outdated
}, | ||
async resolve(_, args) { | ||
const fetchDataFromLedger = args.fetchDataFromLedger || process.env.GET_TRANSACTIONS_FROM_LEDGER || false; |
There was a problem hiding this comment.
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.
server/graphql/v1/queries.js
Outdated
}, | ||
async resolve(_, args) { | ||
let fetchDataFromLedger = process.env.GET_TRANSACTIONS_FROM_LEDGER || false; | ||
if (args.fetchDataFromLedger) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- the default is false
- if there is
process.env.GET_TRANSACTIONS_FROM_LEDGER
it will go with that. - if there is
args.fetchDataFromLedger
it'll go with that regardless the default andprocess.env.GET_TRANSACTIONS_FROM_LEDGER
.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
40c855c
to
0dfc7d7
Compare
… and parse them into the api format
…n case it's not a sequelize transaction object
…o instead of returning normal api transactions, return from ledger
…etchDataFromLedger' logic
…her its going to return transactions from the collectives of that host or only the transactions of the host itself
…, if so consider it and not the defaults/env vars
…e in case transaction is not a sequelize model
0dfc7d7
to
b8f4cba
Compare
@znarf after adding comments on the |
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 variableGET_TRANSACTIONS_FROM_LEDGER
.