-
Notifications
You must be signed in to change notification settings - Fork 33
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
Show the number of coins going in or out in a tx (address page) #74
Conversation
src/app/app.datatypes.ts
Outdated
export function parseGetAddressTransaction(raw: GetAddressResponseTransaction, address: string): Transaction { | ||
|
||
//Detect if the address sent or received the coins. | ||
let incoming: boolean = true; |
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.
You don't have to type-cast it as a boolean, typescript will auto typecast as the default value is true
src/app/app.datatypes.ts
Outdated
|
||
//Detect if the address sent or received the coins. | ||
let incoming: boolean = true; | ||
if (raw.inputs[0].owner.toLowerCase() == address.toLowerCase()) { incoming = 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.
Same line if statement does not require brackets
src/app/app.datatypes.ts
Outdated
if (raw.inputs[0].owner.toLowerCase() == address.toLowerCase()) { incoming = false; } | ||
|
||
//Calculate the amount of incoming or outgoing coins, as appropriate. | ||
let coins:number = 0; |
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.
coins does not need to be cast as a number, will automatically be cast due to default value being a number
src/app/app.datatypes.ts
Outdated
//Calculate the amount of incoming or outgoing coins, as appropriate. | ||
let coins:number = 0; | ||
for (let output of raw.outputs) { | ||
if ((incoming == true) && (output.dst.toLowerCase() == address.toLowerCase())) { |
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.
- Don't need to compare with true as incoming is already a boolean
- Brackets are redundant
src/app/app.datatypes.ts
Outdated
@@ -131,6 +150,7 @@ function parseGetBlocksTransaction(transaction: GetBlocksResponseBlockBodyTransa | |||
inputs: transaction.inputs.map(input => ({ address: null, coins: null, hash: input, hours: null })), | |||
outputs: transaction.outputs.map(output => parseGetBlocksOutput(output)), | |||
status: null, | |||
coins_change: 0, |
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.
When adding default values to be calculated always use null instead of 0
@@ -41,5 +41,6 @@ <h2>{{ address }}</h2> | |||
</div> | |||
</div> | |||
</div> | |||
<div class="row -row"><div attr.class="{{'coins_change_box '+(transaction.coins_change < 0 ? '-red' : '-green')}}">{{ (transaction.coins_change<0?"":"+")+transaction.coins_change.toString() }}</div></div> |
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.
Use NgClass
src/app/app.datatypes.ts
Outdated
@@ -41,6 +41,7 @@ export class Transaction { | |||
outputs: Output[]; | |||
status: boolean; | |||
timestamp: number; | |||
coins_change: number; |
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 we use balance or value instead of coins_change, I feel like this is more in line with the language used so far
src/app/app.datatypes.ts
Outdated
|
||
//Detect if the address sent or received the coins. | ||
let incoming: boolean = true; | ||
if (raw.inputs[0].owner.toLowerCase() == address.toLowerCase()) { incoming = 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.
You have to check for each input, as the input could also be a second or later element in the array
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.
Hi Senyoret, thanks for the pull request, I like how you expanded on the existing code. Please take a look at my comments, thank you!
@Senyoret1 can you describe what API data would be necessary to display in/out flows? |
Greatly improved, thanks! Please create an issue for the required API change |
Now the address screen shows the amount of coins that went in or out the address in each transaction. I think the green color shown when coins go into the address is very clear, but it is the one established in the Brand Guidelines. The amount of coins shows only up to 6 decimals. Issue involved: skycoin/skycoin#754
![Sample of the boxes that were added to each transaction.](https://user-images.githubusercontent.com/34079003/34440506-01b95772-ec8c-11e7-9e34-b4cc0daba706.png)