Skip to content

Commit

Permalink
Merge pull request #214 from 67P/chore/remove_last_ethereum_bits
Browse files Browse the repository at this point in the history
Remove mentions of Ethereum from UI and code, refactor wallet connect
  • Loading branch information
raucao committed Aug 14, 2023
2 parents 2697563 + d5edb93 commit 97ebebe
Show file tree
Hide file tree
Showing 22 changed files with 334 additions and 218 deletions.
2 changes: 1 addition & 1 deletion app/components/add-contributor/template.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<form onsubmit={{action "submit"}}>
<p>
<label for="c-account">Ethereum account</label>
<label for="c-account">Rootstock account</label>
<Input @type="text"
@value={{this.account}}
name="account" id="c-account"
Expand Down
62 changes: 27 additions & 35 deletions app/components/topbar-account-panel/component.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
import Component from '@ember/component';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { action } from '@ember/object';
import { isPresent } from '@ember/utils';

export default Component.extend({
export default class TopbarAccountPanelComponent extends Component {
@service router;
@service kredits;

tagName: '',
@tracked setupInProgress = false;

kredits: service(),
router: service(),
get userHasWallet () {
return isPresent(window.ethereum);
}

setupInProgress: false,
get walletConnected () {
return this.userHasWallet && this.kredits.hasAccounts;
}

userHasEthereumWallet: computed(function() {
return isPresent(window.ethereum);
}),

showConnectButton: computed('userHasEthereumWallet',
'kredits.hasAccounts', function() {
return this.userHasEthereumWallet &&
!this.kredits.hasAccounts;
}),

actions: {

signup() {
this.router.transitionTo('signup');
},

async connectAccount() {
try {
await window.ethereum.enable();
this.set('setupInProgress', true);
await this.kredits.setup();
this.set('setupInProgress', false);
} catch (error) {
this.set('setupInProgress', false);
console.log('Opening Ethereum wallet failed:', error);
}
}
get walletDisconnected () {
return this.userHasWallet && !this.kredits.hasAccounts;
}

@action
signup () {
this.router.transitionTo('signup');
}

@action
async connectWallet () {
this.setupInProgress = true;
await this.kredits.connectWallet();
this.setupInProgress = false;
}

});
}
13 changes: 6 additions & 7 deletions app/components/topbar-account-panel/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
{{#if this.setupInProgress}}
Connecting account...
{{else}}
{{#if (and this.kredits.hasAccounts this.kredits.currentUser)}}
{{#if (and this.walletConnected this.kredits.currentUser)}}
{{this.kredits.currentUser.name}}
{{#if this.kredits.currentUserIsCore}}
<span class="core-flag">(core)</span>
{{/if}}
{{else}}
<span class="anonymous">Anonymous</span>
<button onclick={{action "signup"}} class="small" type="button">Sign up</button>
{{#if this.showConnectButton}}
<button onclick={{action "connectAccount"}} class="small green" type="button">Connect account</button>
<button onclick={{action "signup"}} id="signup"
class="small" type="button">Sign up</button>
{{#if this.walletDisconnected}}
<button onclick={{action "connectWallet"}} id="connect"
class="small green" type="button">Connect wallet</button>
{{/if}}
{{/if}}
{{/if}}
Expand Down
50 changes: 50 additions & 0 deletions app/controllers/signup/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import config from 'kredits-web/config/environment';
import { isAddress } from 'web3-utils';

export default class AccountController extends Controller {
@service kredits;

@tracked accountAddress = null;

get isValidEthAccount () {
return isAddress(this.accountAddress);
}

get signupButtonDisabled () {
return !this.isValidEthAccount;
}

@action
completeSignup () {
const payload = {
accessToken: this.kredits.githubAccessToken,
account: this.accountAddress
}

fetch(config.githubSignupUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
})
.then(res => res.json())
.then(data => {
if (data.error) {
alert('Creating profile failed. We have been notified about this error and will take a look soon. Sorry!');
console.warn('Creating contributor profile failed:',
JSON.parse(data.error.body).error.message)
return false;
} else {
console.log('[signup/account] Created contributor:', data);

this.kredits.githubAccessToken = null;
this.accountAddress = null;

this.transitionToRoute('signup.complete');
}
})
}
}
49 changes: 0 additions & 49 deletions app/controllers/signup/eth-account.js

This file was deleted.

14 changes: 6 additions & 8 deletions app/controllers/signup/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import config from 'kredits-web/config/environment';

export default Controller.extend({

actions: {

connectGithub () {
window.location = config.githubConnectUrl;
}
export default class IndexController extends Controller {

@action
connectGithub () {
window.location = config.githubConnectUrl;
}

});
}
2 changes: 1 addition & 1 deletion app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Router.map(function() {
});
this.route('signup', function() {
this.route('github');
this.route('eth-account');
this.route('account');
this.route('complete');
});
this.route('budget', function() {
Expand Down
23 changes: 23 additions & 0 deletions app/routes/signup/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { isEmpty } from '@ember/utils';

export default class SignupAccountRoute extends Route {
@service kredits;

async setupController (controller) {
if (!window.ethereum) return;

if (this.kredits.hasAccounts) {
controller.accountAddress = this.kredits.currentUserAccounts.firstObject;
} else {
return this.kredits.connectWallet();
}
}

redirect () {
if (isEmpty(this.kredits.githubAccessToken)) {
this.transitionTo('signup.index');
}
}
}
17 changes: 0 additions & 17 deletions app/routes/signup/eth-account.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/routes/signup/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default Route.extend({

this.kredits.set('githubAccessToken', accessToken);

this.transitionTo('signup.eth-account');
this.transitionTo('signup.account');
}

});
Expand Down
4 changes: 2 additions & 2 deletions app/services/browser-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import config from 'kredits-web/config/environment';

function createStore(name) {
let networkName;
if (config.web3RequiredNetworkName) {
networkName = config.web3RequiredNetworkName.toLocaleLowerCase().replace(' ', '-');
if (config.web3NetworkName) {
networkName = config.web3NetworkName.toLocaleLowerCase().replace(' ', '-');
} else {
networkName = 'custom';
}
Expand Down
Loading

0 comments on commit 97ebebe

Please sign in to comment.