Refactor kredits setup code a bit

This commit is contained in:
2022-04-27 18:10:02 +02:00
parent 77dbde8bb4
commit eef9fa1aba
2 changed files with 18 additions and 25 deletions
+3 -5
View File
@@ -7,14 +7,12 @@ export default class ApplicationRoute extends Route {
@service communityFunds; @service communityFunds;
beforeModel(/* transition */) { beforeModel(/* transition */) {
const kredits = this.kredits; return this.kredits.setup().then(() => {
this.kredits.kredits.preflightChecks().catch(error => {
return kredits.setup().then(() => {
kredits.kredits.preflightChecks().catch((error) => {
console.error('Kredits preflight check failed!'); console.error('Kredits preflight check failed!');
console.error(error); console.error(error);
}); });
}).catch((error) => { }).catch(error => {
console.log('Error initializing Kredits', error); console.log('Error initializing Kredits', error);
}); });
} }
+6 -11
View File
@@ -111,28 +111,23 @@ export default Service.extend({
}); });
}, },
setup () { async setup () {
return this.getEthProvider().then((providerAndSigner) => { const kredits = await this.getEthProvider().then((providerAndSigner) => {
let kredits = new Kredits(providerAndSigner.ethProvider, providerAndSigner.ethSigner, { return new Kredits(providerAndSigner.ethProvider, providerAndSigner.ethSigner, {
addresses: { Kernel: config.kreditsKernelAddress },
apm: config.kreditsApmDomain,
ipfsConfig: config.ipfs ipfsConfig: config.ipfs
}).init();
}); });
return kredits
.init()
.then(async (kredits) => {
this.set('kredits', kredits); this.set('kredits', kredits);
this.set('currentBlock', await kredits.provider.getBlockNumber()); this.set('currentBlock', await kredits.provider.getBlockNumber());
if (this.currentUserAccounts && this.currentUserAccounts.length > 0) { if (this.currentUserAccounts && this.currentUserAccounts.length > 0) {
this.getCurrentUser.then((contributorData) => { this.getCurrentUser.then(contributorData => {
this.set('currentUser', contributorData); this.set('currentUser', contributorData);
}); });
} }
return kredits; return kredits;
});
});
}, },
getCurrentUser: computed('kredits.provider', 'currentUserAccounts.[]', function() { getCurrentUser: computed('kredits.provider', 'currentUserAccounts.[]', function() {