Refactor registry service imports.

This commit is contained in:
Spencer Ofwiti 2021-05-18 12:38:27 +03:00
parent 405199cfe3
commit 8ae6436460
5 changed files with 59 additions and 67 deletions

View File

@ -25,8 +25,8 @@ export class BlockSyncService {
const settings: Settings = new Settings(this.scan); const settings: Settings = new Settings(this.scan);
const readyStateElements: { network: number } = { network: 2 }; const readyStateElements: { network: number } = { network: 2 };
settings.w3.provider = environment.web3Provider; settings.w3.provider = environment.web3Provider;
settings.w3.engine = this.registryService.getWeb3(); settings.w3.engine = this.registryService.web3;
settings.registry = this.registryService.getRegistry(); settings.registry = this.registryService.registry;
settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry); settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry);
settings.txHelper.ontransfer = async (transaction: any): Promise<void> => { settings.txHelper.ontransfer = async (transaction: any): Promise<void> => {
@ -35,12 +35,10 @@ export class BlockSyncService {
settings.txHelper.onconversion = async (transaction: any): Promise<any> => { settings.txHelper.onconversion = async (transaction: any): Promise<any> => {
window.dispatchEvent(this.newConversionEvent(transaction)); window.dispatchEvent(this.newConversionEvent(transaction));
}; };
settings.registry.onload = (addressReturned: number): void => { settings.registry.onload = (addressReturned: string): void => {
this.loggingService.sendInfoLevelMessage(`Loaded network contracts ${addressReturned}`); this.loggingService.sendInfoLevelMessage(`Loaded network contracts ${addressReturned}`);
this.readyStateProcessor(settings, readyStateElements.network, address, offset, limit); this.readyStateProcessor(settings, readyStateElements.network, address, offset, limit);
}; };
settings.registry.load();
} }
readyStateProcessor( readyStateProcessor(

View File

@ -22,12 +22,4 @@ export class RegistryService {
this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress); this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
this.registry.load(); this.registry.load();
} }
getRegistry(): any {
return this.registry;
}
getWeb3(): any {
return this.web3;
}
} }

View File

@ -15,8 +15,7 @@ export class TokenService {
LoadEvent: EventEmitter<number> = new EventEmitter<number>(); LoadEvent: EventEmitter<number> = new EventEmitter<number>();
constructor(private httpClient: HttpClient, private registryService: RegistryService) { constructor(private httpClient: HttpClient, private registryService: RegistryService) {
this.registry = registryService.getRegistry(); this.registry = registryService.registry;
this.registry.load();
this.registry.onload = async (address: string): Promise<void> => { this.registry.onload = async (address: string): Promise<void> => {
this.tokenRegistry = new TokenRegistry( this.tokenRegistry = new TokenRegistry(
await this.registry.getContractAddressByName('TokenRegistry') await this.registry.getContractAddressByName('TokenRegistry')

View File

@ -37,9 +37,8 @@ export class TransactionService {
private loggingService: LoggingService, private loggingService: LoggingService,
private registryService: RegistryService private registryService: RegistryService
) { ) {
this.web3 = this.registryService.getWeb3(); this.web3 = this.registryService.web3;
this.registry = registryService.getRegistry(); this.registry = registryService.registry;
this.registry.load();
} }
getAllTransactions(offset: number, limit: number): Observable<any> { getAllTransactions(offset: number, limit: number): Observable<any> {
@ -133,6 +132,7 @@ export class TransactionService {
recipientAddress: string, recipientAddress: string,
value: number value: number
): Promise<any> { ): Promise<any> {
this.registry.onload = async (addressReturned: string): Promise<void> => {
const transferAuthAddress = await this.registry.getContractAddressByName( const transferAuthAddress = await this.registry.getContractAddressByName(
'TransferAuthorization' 'TransferAuthorization'
); );
@ -169,5 +169,6 @@ export class TransactionService {
this.loggingService.sendInfoLevelMessage(`Result: ${result}`); this.loggingService.sendInfoLevelMessage(`Result: ${result}`);
const transaction = await this.web3.eth.getTransaction(result.transactionHash); const transaction = await this.web3.eth.getTransaction(result.transactionHash);
this.loggingService.sendInfoLevelMessage(`Transaction: ${transaction}`); this.loggingService.sendInfoLevelMessage(`Transaction: ${transaction}`);
};
} }
} }

View File

@ -46,8 +46,7 @@ export class UserService {
this.keystore = authService.mutableKeyStore; this.keystore = authService.mutableKeyStore;
this.signer = new PGPSigner(this.keystore); this.signer = new PGPSigner(this.keystore);
}); });
this.registry = registryService.getRegistry(); this.registry = registryService.registry;
this.registry.load();
} }
resetPin(phone: string): Observable<any> { resetPin(phone: string): Observable<any> {
@ -179,6 +178,7 @@ export class UserService {
async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> { async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> {
this.resetAccountsList(); this.resetAccountsList();
this.registry.onload = async (addressReturned: string): Promise<void> => {
const accountIndexAddress: string = await this.registry.getContractAddressByName( const accountIndexAddress: string = await this.registry.getContractAddressByName(
'AccountRegistry' 'AccountRegistry'
); );
@ -186,10 +186,12 @@ export class UserService {
const accountAddresses: Array<string> = await accountIndexQuery.last( const accountAddresses: Array<string> = await accountIndexQuery.last(
await accountIndexQuery.totalAccounts() await accountIndexQuery.totalAccounts()
); );
console.log(accountAddresses);
this.loggingService.sendInfoLevelMessage(accountAddresses); this.loggingService.sendInfoLevelMessage(accountAddresses);
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) { for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
await this.getAccountByAddress(accountAddress, limit); await this.getAccountByAddress(accountAddress, limit);
} }
};
} }
async getAccountByAddress( async getAccountByAddress(