This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
WIP: #239 #248
Closed
Closed
WIP: #239 #248
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
311a397
Balance TDD
sa3664 1e72e6e
Balance component implemenation
sa3664 bcebd11
Balance variable define
sa3664 c0df6fe
Fees variable
sa3664 6537b21
Fees TDD
sa3664 d9ee638
Fees component Imp
sa3664 d68a097
balance service
sa3664 c1176d7
Balance Service
sa3664 61b39b8
Mailchain inbox balance feature
sa3664 ec59b4a
Merge branch 'master' of https://github.com/mailchain/mailchain-web i…
sa3664 59c8e78
Merge branch 'mailchain-master'
sa3664 9a90088
feat: Balance functionality
sa3664 6e46d54
feat: Balance functionality
sa3664 4f44fc9
Merge branch 'master' into master
robdefeo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ import { PublicKeyService } from 'src/app/services/mailchain/public-key/public-k | |
import { AddressesService } from 'src/app/services/mailchain/addresses/addresses.service'; | ||
import { EnvelopeService } from 'src/app/services/mailchain/envelope/envelope.service'; | ||
import { NameserviceService } from 'src/app/services/mailchain/nameservice/nameservice.service'; | ||
import { BalanceService } from 'src/app/services/mailchain/addresses/balance.service'; | ||
tboeckmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import { Subject, of, Observable } from 'rxjs'; | ||
|
||
import { debounceTime, distinctUntilChanged, mergeMap } from "rxjs/operators"; | ||
|
@@ -15,6 +17,7 @@ import { ModalConnectivityErrorComponent } from 'src/app/modals/modal-connectivi | |
|
||
import * as ClassicEditor from '@ckeditor/ckeditor5-build-classic'; | ||
import { CKEditorComponent } from '@ckeditor/ckeditor5-angular'; | ||
import { getCurrencySymbol } from '@angular/common'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this used? |
||
|
||
@Component({ | ||
selector: '[inbox-compose]', | ||
|
@@ -34,6 +37,9 @@ export class InboxComposeComponent implements OnInit { | |
public model = new Mail() | ||
public fromAddresses: Array<any> = [] | ||
public envelopes: Array<any> = [] | ||
public balance: number = 0 | ||
public currency: string = "" | ||
public fees: string = "" | ||
|
||
public sendMessagesDisabled: boolean = false; | ||
private subscription | ||
|
@@ -64,6 +70,7 @@ export class InboxComposeComponent implements OnInit { | |
private addressesService: AddressesService, | ||
private envelopeService: EnvelopeService, | ||
private nameserviceService: NameserviceService, | ||
private balanceService: BalanceService, | ||
private modalService: BsModalService, | ||
) { | ||
this.initMail() | ||
|
@@ -78,6 +85,7 @@ export class InboxComposeComponent implements OnInit { | |
this.model.replyTo = "" | ||
this.model.subject = "" | ||
this.model.body = "" | ||
|
||
} | ||
|
||
/** | ||
|
@@ -120,6 +128,32 @@ export class InboxComposeComponent implements OnInit { | |
this.envelopes = await this.envelopeService.getEnvelope(); | ||
} | ||
|
||
|
||
/** | ||
* updates the balance whenver address dropdwon value is changed | ||
*/ | ||
|
||
public async updateBalanceForAddress(address) { | ||
this.balance = await this.balanceService.getBalance(address, this.currentProtocol, this.currentNetwork); | ||
|
||
} | ||
|
||
private async setBalance() { | ||
if (this.currentAccount != undefined) { | ||
|
||
this.balance = await this.balanceService.getBalance(this.currentAccount, this.currentProtocol, this.currentNetwork); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the currency | ||
*/ | ||
private async setCurrency() { | ||
this.currency = await this.mailchainService.getCurrencyForProtocol(this.currentProtocol) | ||
} | ||
|
||
|
||
|
||
/** | ||
* Returns the identicon for the an address | ||
* @param address the address | ||
|
@@ -197,7 +231,7 @@ export class InboxComposeComponent implements OnInit { | |
mergeMap(searchVal => { | ||
return this.resolveAddress(searchVal) | ||
}) | ||
).subscribe((res) => { | ||
).subscribe((res) => { | ||
res.subscribe(val => { | ||
let address = val['body']['address'] | ||
if ( | ||
|
@@ -353,7 +387,9 @@ export class InboxComposeComponent implements OnInit { | |
this.evaluateReply() | ||
this.handleReplyFields() | ||
this.setupRecipientAddressLookupSubscription() | ||
} | ||
await this.setBalance() | ||
await this.setCurrency() | ||
} | ||
|
||
/** | ||
* Handles content-type in the view | ||
|
@@ -463,21 +499,21 @@ export class InboxComposeComponent implements OnInit { | |
*/ | ||
private handleReplyFields() { | ||
if (this.currentMessage && this.currentMessage.headers) { | ||
|
||
if (this.inputContentType == "html") { | ||
this.handleReplyInHtml() | ||
} else if (this.inputContentType == "plaintext") { | ||
this.handleReplyInPlaintext() | ||
} | ||
|
||
if (this.currentMessage.headers["reply-to"] && this.currentMessage.headers["reply-to"].length) { | ||
this.model.to = this.mailchainService.parseAddressFromMailchain(this.currentProtocol, this.currentMessage.headers["reply-to"]) | ||
} else { | ||
this.model.to = this.mailchainService.parseAddressFromMailchain(this.currentProtocol, this.currentMessage.headers["from"]) | ||
} | ||
|
||
this.messageToField = this.currentRecipientValue = this.model.to | ||
|
||
this.model.replyTo = this.model.from = this.mailchainService.parseAddressFromMailchain(this.currentProtocol, this.currentMessage.headers.to) | ||
this.model.subject = this.addRePrefixToSubject(this.currentMessage["subject"]) | ||
} | ||
|
72 changes: 72 additions & 0 deletions
72
src/app/services/mailchain/addresses/balance.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
|
||
import { BalanceService } from './balance.service'; | ||
import { MailchainTestService } from 'src/app/test/test-helpers/mailchain-test.service'; | ||
import { HttpHelpersService } from '../../helpers/http-helpers/http-helpers.service'; | ||
import { ProtocolsServiceStub } from '../protocols/protocols.service.stub'; | ||
import { ProtocolsService } from '../protocols/protocols.service'; | ||
import { Observable, of } from 'rxjs'; | ||
|
||
|
||
describe('BalanceService', () => { | ||
|
||
let balanceService: BalanceService; | ||
let httpTestingController: HttpTestingController; | ||
let mailchainTestService: MailchainTestService | ||
let serverResponse | ||
|
||
const currentAccount = '0x92d8f10248c6a3953cc3692a894655ad05d61efb'; | ||
const desiredUrl = `http://127.0.0.1:8080/api/addresses/` + currentAccount + `/balance?protocol=ethereum&network=mainnet` | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
HttpHelpersService, | ||
{ provide: ProtocolsService, useClass: ProtocolsServiceStub }, | ||
BalanceService, | ||
], | ||
imports: [HttpClientTestingModule] | ||
}); | ||
|
||
balanceService = TestBed.inject(BalanceService); | ||
mailchainTestService = TestBed.inject(MailchainTestService); | ||
httpTestingController = TestBed.inject(HttpTestingController); | ||
|
||
//serverResponse = mailchainTestService.senderAddressesEthereumObserveResponse() | ||
// expectedAddresses = mailchainTestService.senderAddresses() | ||
}); | ||
|
||
afterEach(() => { | ||
httpTestingController.verify(); | ||
}); | ||
|
||
|
||
describe('initUrl', () => { | ||
it('should initialize the url', () => { | ||
balanceService.initUrl() | ||
expect(balanceService['url']).toEqual('http://127.0.0.1:8080/api') | ||
}); | ||
}) | ||
|
||
it('should be created', () => { | ||
expect(balanceService).toBeTruthy(); | ||
}); | ||
|
||
describe('getBalance', () => { | ||
beforeEach(() => { | ||
let obs: Observable<any> = of(mailchainTestService.senderBalanceEthereumObserveResponse()) | ||
tboeckmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
spyOn(balanceService, 'getBalance').and.returnValue( | ||
obs.toPromise() | ||
) | ||
}); | ||
it('should get balance for addresses', async () => { | ||
let result | ||
await balanceService.getBalance(currentAccount, 'ethereum', 'mainnet').then(res => { | ||
result = res | ||
}); | ||
expect(result).toEqual(mailchainTestService.senderBalanceEthereumObserveResponse()) | ||
expect(balanceService.getBalance).toHaveBeenCalled() | ||
}); | ||
}) | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please can you remove this until it's implemented?