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

Integrate with Kauri API :: GetRawTransactions #46

Merged
merged 39 commits into from
Jun 26, 2018
Merged

Conversation

zanuka
Copy link
Contributor

@zanuka zanuka commented Jun 20, 2018

This wires up the api service, data service, model and wallet component to get raw tx data for supplied wallet addresses of selected currency.

  • add model
  • add data service
  • add wallet component
  • add currency selector
  • add address inputs
  • add scss support
  • build transactions payload from input data
  • verify POST succeeds to localhost and returns raw tx data for each address
  • add tests
  • add parser
  • add service stub
  • fix coverage
  • fix accessibility issues (flagged in Lighthouse)
  • replace coveralls with codecov

Note: To test this, you'll need the Kauri API running. Follow the directions here

constructor(private http: HttpClient) {}

getRawTransactions(addresses: any[]) {

Copy link

@red010b37 red010b37 Jun 20, 2018

Choose a reason for hiding this comment

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

we should always type the arrays - so string[] avoid using any where ever possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@red010b37 updated 🌮

styleUrls: ['./api-sample.component.css']
})
export class ApiSampleComponent {
addresses = []

Choose a reason for hiding this comment

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

we should always strongly type the arrays - so addresses = string[]

Copy link

@red010b37 red010b37 left a comment

Choose a reason for hiding this comment

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

Press the wroing btn

@zanuka
Copy link
Contributor Author

zanuka commented Jun 21, 2018

@red010b37 can you test this branch and let me know if you have any further suggestions? I made some additional updates last night

@matt-auckland
Copy link
Contributor

Still not working for me, I'm getting CORS errors.
Do we need to update the package GoLang is building to allow CORS?
image

@zanuka
Copy link
Contributor Author

zanuka commented Jun 25, 2018

@ro-savage Yeah it's setup to only accept wallet addresses, not txids. So in Postman, the request body would look like this:

{"transactions": [
    {"currency":  "NAV", "addresses": ["NW7uXr4ZAeJKigMGnKbSLfCBQY59cH1T8G", "NUDke42E3fwLqaBbBFRyVSTETuhWAi7ugk"]}
]}

And when testing from this branch, you would select NAV from the dropdown and then enter 2 NAV wallet addresses in the inputs. The logic in this PR will build out the proper request body (above) and POST it to the Kauri API running locally. The response will then contain all of the raw transaction data for each address.

screen shot 2018-06-26 at 8 01 08 am


onGetTransactions(currency: string, addresses: string[]) {

const apiModel: ApiModel = {} as ApiModel;
Copy link
Contributor

@ro-savage ro-savage Jun 25, 2018

Choose a reason for hiding this comment

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

I thought the as syntax was for overwriting the intefered type.
E.g. Type Assertions

However, it seems to be in a lot of places.

Would just const apiModel = {} as ApiModel; work?

Or

const apiModel: ApiModel = {
  currency,
  addresses,
};

Copy link
Contributor

@ro-savage ro-savage Jun 25, 2018

Choose a reason for hiding this comment

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

To take it a step further, does this work?

wallet.component.html

  onGetTransactions(transactionsReq:  ApiModel) {
    this._apiService.getRawTransactions(transactionsReq);
  }

wallet.component.html

  <button mat-raised-button (click)="onGetTransactions({ currency: currency.value, addresses: [addressOne.value, addressTwo.value]})">Get Transactions</button>

I am not sure if/how angular/typescript handle type errors in a template?

Copy link

@red010b37 red010b37 Jun 26, 2018

Choose a reason for hiding this comment

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

As discussed we should do as ApiModel for consistency.
const apiModel: ApiModel = {} as ApiModel;


<br>

<input matInput placeholder="Enter Address" type="text" #addressTwo>
Copy link
Contributor

Choose a reason for hiding this comment

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

We still have a few matInput, mat-raised etc in the template files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@ro-savage
Copy link
Contributor

@zanuka - Let us know when you are ready for a review (e.g. you think its completed)

@ro-savage ro-savage changed the title Integrate with Kauri API :: GetRawTransactions Integrate with Kauri API :: GetRawTransactions / WIP / DO NOT MERGE Jun 26, 2018
@zanuka zanuka changed the title Integrate with Kauri API :: GetRawTransactions / WIP / DO NOT MERGE Integrate with Kauri API :: GetRawTransactions Jun 26, 2018
@zanuka
Copy link
Contributor Author

zanuka commented Jun 26, 2018

the following spec tests have been added for parsed response data:

parseRawTransaction
currency
data should have currency
currency should be NAV
parseAddressItem()
should have correct address
parseTransactions()
transaction 1 test
should have correct txid
should have correct rawtxt
should have correct verbose
transaction 2 test
should have correct txid
should have correct rawtxt
should have verbose
parseVerbose()
should have no anon dest
should have correct blockhash
should have correct blocktime
should have correct confirmations
should have correct hash
should have correct height
should have correct hex
should have correct locktime
should have correct size
should have correct time
should have correct txid
should have correct version
parseVinData()
should have a scriptSig object
should have correct sequence
should have correct txid
should have correct vout
parseScriptSigData()
should have asm
should have hex
parseVoutData()
should have correct value for n
should have scriptPubKey object
should have correct value for value
should have correct value for valueSat
scriptPubKeyData()
should have addresses
should have correct asm
should have correct hex
should have correct reqSigs
should have correct type

@zanuka
Copy link
Contributor Author

zanuka commented Jun 26, 2018

@ro-savage it's ready for review. I'm happy with it at this point. From this pattern we can expand/adapt functionality. Just need to get it passing the lighthouse gauntlet 🔨

@codecov-io
Copy link

codecov-io commented Jun 26, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@f3556b0). Click here to learn what that means.
The diff coverage is 84.95%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #46   +/-   ##
=========================================
  Coverage          ?   84.07%           
=========================================
  Files             ?       13           
  Lines             ?      157           
  Branches          ?        0           
=========================================
  Hits              ?      132           
  Misses            ?       25           
  Partials          ?        0
Impacted Files Coverage Δ
...ers/sw-update-prompt/sw-update-prompt.component.ts 69.23% <ø> (ø)
...kages/kauri-wallet/src/environments/environment.ts 100% <ø> (ø)
...ri-wallet/src/app/services/api/api.service.stub.ts 100% <100%> (ø)
...app/services/api/parsers/raw-transaction-parser.ts 100% <100%> (ø)
...kauri-wallet/src/app/services/data/data.service.ts 100% <100%> (ø)
packages/kauri-wallet/src/app/app.component.ts 100% <100%> (ø)
...translation-sample/translation-sample.component.ts 100% <100%> (ø)
...s/kauri-wallet/src/app/services/api/api.service.ts 38.09% <38.09%> (ø)
...es/kauri-wallet/src/app/wallet/wallet.component.ts 71.42% <71.42%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3556b0...3cb5d1d. Read the comment docs.

txAddress.address = item['address'];
txAddress.transactions = [];

item['transactions'].forEach((tx) => {
Copy link
Contributor

@ro-savage ro-savage Jun 26, 2018

Choose a reason for hiding this comment

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

Throws on item.transactions = null which is the default result if only one item is requested.

Maybe should add a test for null/undefined, and ensure we handle it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ro-savage sounds good, will add

@@ -28,8 +28,7 @@
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [
true,
140
false
],
"member-access": false,
"member-ordering": [
Copy link
Contributor

Choose a reason for hiding this comment

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

On line 73 can we change :

"no-unused-expressions": true,
to
"no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true }],

So we can do short cuts like data.transactions && data.transactions.forEach()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great suggestion, just updated 🔍

Copy link
Contributor

@ro-savage ro-savage left a comment

Choose a reason for hiding this comment

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

Happy with this as is.

Awesome work getting it started and getting us a great base to learn from.

We'll make whatever changes we need as we add more real world use cases.

@zanuka
Copy link
Contributor Author

zanuka commented Jun 26, 2018

@ro-savage sounds good, thanks for the review guys. Agreed, it's a good base and am looking forward to the next phase of feature adds.

@zanuka zanuka dismissed red010b37’s stale review June 26, 2018 23:19

updates made, team approved

@zanuka zanuka merged commit a6071d4 into master Jun 26, 2018
@zanuka zanuka deleted the get-raw-transactions branch June 26, 2018 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Sprint for June 13-26
  
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

5 participants