Skip to content

Commit 482283e

Browse files
committed
chore: misc
* Fix setting emai after registration * Add better error reporting on the frontend * Better listing UI on mobile
1 parent ad86f8d commit 482283e

File tree

12 files changed

+160
-24
lines changed

12 files changed

+160
-24
lines changed

extend.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111

1212
namespace Blomstra\Web3;
1313

14-
use Blomstra\Web3\Exception\InvalidSignatureException;
15-
use Blomstra\Web3\Query\Web3AccountFilterer;
1614
use Fig\Http\Message\StatusCodeInterface;
1715
use Flarum\Api\Serializer\CurrentUserSerializer;
18-
use Flarum\Api\Serializer\ForumSerializer;
1916
use Flarum\Extend;
2017
use Flarum\Frontend\Document;
2118

@@ -40,7 +37,8 @@
4037
->get('/web3/accounts', 'web3-accounts.index', Api\Controller\ListWeb3AccountsController::class)
4138
->post('/web3/accounts', 'web3-accounts.create', Api\Controller\CreateWeb3AccountController::class)
4239
->delete('/web3/accounts/{id}', 'web3-accounts.delete', Api\Controller\DeleteWeb3AccountController::class)
43-
->post('/web3/token', 'web3-accounts.token', Api\Controller\CreateTokenWithWeb3Account::class),
40+
->post('/web3/token', 'web3-accounts.token', Api\Controller\CreateTokenWithWeb3Account::class)
41+
->put('/web3/set-email', 'web3.set-email', Api\Controller\SetUserEmailController::class),
4442

4543
(new Extend\Routes('forum'))
4644
->post('/web3/login', 'web3-accounts.login', Forum\Controller\LoginWithWeb3AccountController::class)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import app from 'flarum/forum/app';
2+
import Button from 'flarum/common/components/Button';
3+
import BaseChangeEmailModal from 'flarum/forum/components/ChangeEmailModal';
4+
5+
export default class ChangeEmailModal extends BaseChangeEmailModal {
6+
content() {
7+
if (this.success) {
8+
return super.content();
9+
}
10+
11+
return (
12+
<div className="Modal-body">
13+
<div className="Form Form--centered">
14+
<div className="Form-group">
15+
<input
16+
type="email"
17+
name="email"
18+
className="FormControl"
19+
placeholder={app.session.user!.email()}
20+
bidi={this.email}
21+
disabled={this.loading}
22+
/>
23+
</div>
24+
<div className="Form-group">
25+
{Button.component(
26+
{
27+
className: 'Button Button--primary Button--block',
28+
type: 'submit',
29+
loading: this.loading,
30+
},
31+
app.translator.trans('core.forum.change_email.submit_button')
32+
)}
33+
</div>
34+
</div>
35+
</div>
36+
);
37+
}
38+
39+
onsubmit(e: SubmitEvent) {
40+
e.preventDefault();
41+
42+
// If the user hasn't actually entered a different email address, we don't
43+
// need to do anything. Woot!
44+
if (this.email() === app.session.user!.email()) {
45+
this.hide();
46+
return;
47+
}
48+
49+
this.loading = true;
50+
this.alertAttrs = null;
51+
52+
app
53+
.request({
54+
url: app.forum.attribute('apiUrl') + '/web3/set-email',
55+
method: 'PUT',
56+
body: {
57+
data: { email: this.email() },
58+
},
59+
errorHandler: this.onerror.bind(this),
60+
})
61+
.then(() => {
62+
this.success = true;
63+
})
64+
.catch(() => {})
65+
.then(this.loaded.bind(this));
66+
}
67+
}

js/src/forum/components/ConnectWalletModal.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import EvmConnectWalletModal from './EvmConnectWalletModal';
88
export interface IConnectWalletModalAttrs extends IInternalModalAttrs {
99
username: string;
1010
onattach?: (address: string, signature: string, source: string, type: string) => void;
11+
onclose: Function;
1112
}
1213

1314
type WalletTypeName = 'evm' | 'polkadot';
@@ -20,6 +21,11 @@ const nameToComponent: Record<WalletTypeName, ComponentClass> = {
2021
export default class ConnectWalletModal<CustomAttrs extends IConnectWalletModalAttrs = IConnectWalletModalAttrs> extends Modal<CustomAttrs> {
2122
private current: WalletTypeName | null = null;
2223

24+
hide() {
25+
this.attrs.onclose();
26+
super.hide();
27+
}
28+
2329
className(): string {
2430
return 'ConnectWalletModal';
2531
}
@@ -43,7 +49,7 @@ export default class ConnectWalletModal<CustomAttrs extends IConnectWalletModalA
4349
{app.translator.trans('blomstra-web3.forum.connect-wallet-modal.goback')}
4450
</Button>
4551
</div>
46-
<ComponentName onerror={this.onerror} {...this.attrs} key={this.current} />
52+
<ComponentName onerror={this.onerror.bind(this)} {...this.attrs} key={this.current} />
4753
</div>
4854
);
4955
}

js/src/forum/components/EvmConnectWalletModal.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ import Component from 'flarum/common/Component';
3939
// }
4040
// }
4141

42-
export interface IEvmConnectWalletModalAttrs extends IConnectWalletModalAttrs {
43-
onerror: Function;
44-
}
42+
export interface IEvmConnectWalletModalAttrs extends IConnectWalletModalAttrs {}
4543

4644
export default class EvmConnectWalletModal<
4745
CustomAttrs extends IEvmConnectWalletModalAttrs = IEvmConnectWalletModalAttrs
@@ -143,8 +141,9 @@ export default class EvmConnectWalletModal<
143141
}
144142

145143
if (this.attrs.onattach) this.attrs.onattach(this.currentAddress!, signature, source, type);
146-
} catch (e) {
144+
} catch (error: any) {
147145
app.alerts.show({ type: 'error' }, app.translator.trans('blomstra-web3.forum.connect-wallet-modal.could-not-sign'));
146+
app.alerts.show({ type: 'error' }, error.message);
148147
}
149148

150149
m.redraw();

js/src/forum/components/LogInModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ export default class LogInModal extends BaseLogInModal {
7878
},
7979
errorHandler: this.onerror.bind(this),
8080
})
81-
.then(() => window.location.reload(), this.loaded.bind(this));
81+
.then(() => window.location.reload(), this.loaded.bind(this))
82+
.finally(() => (this.loading = false));
8283
},
84+
onclose: () => (this.loading = false),
8385
},
8486
true
8587
);

js/src/forum/components/SignUpModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ export default class SignUpModal extends BaseSignUpModal {
9191
},
9292
errorHandler: this.onerror.bind(this),
9393
})
94-
.then(() => window.location.reload(), this.loaded.bind(this));
94+
.then(() => window.location.reload(), this.loaded.bind(this))
95+
.finally(() => (this.loading = false));
9596
},
97+
onclose: () => (this.loading = false),
9698
},
9799
true
98100
);

js/src/forum/components/WalletAccounts.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ export default class WalletAccounts<CustomAttrs extends IWalletAccountsAttrs = I
137137
}
138138

139139
if (this.attrs.onattach) this.attrs.onattach(hexAddress, signature, source, type);
140-
} catch (err) {
140+
} catch (error: any) {
141141
app.alerts.show({ type: 'error' }, app.translator.trans('blomstra-web3.forum.connect-wallet-modal.could-not-sign'));
142+
app.alerts.show({ type: 'error' }, error.message);
142143
}
143144

144145
this.loading = false;

js/src/forum/components/alertNoEmail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Alert from 'flarum/common/components/Alert';
2-
import ChangeEmailModal from 'flarum/forum/components/ChangeEmailModal';
32
import Button from 'flarum/common/components/Button';
3+
import ChangeEmailModal from './ChangeEmailModal';
44

55
/**
66
* Shows an alert if the user signed up with no email address.

less/components/AttachedAccounts.less

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
&-account {
88
--icon-size: 32px;
99
display: grid;
10-
grid-template-columns: var(--icon-size) 1fr 1fr;
10+
grid-template-columns: var(--icon-size) 3fr 1fr;
1111
align-items: center;
1212
grid-gap: 16px;
1313
padding: 8px;
@@ -30,6 +30,12 @@
3030

3131
&-address {
3232
font-weight: bold;
33+
text-overflow: ellipsis;
34+
overflow: hidden;
35+
}
36+
37+
&-content {
38+
overflow: hidden;
3339
}
3440

3541
&-wallet {

locale/en.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ blomstra-web3:
4343
unbind_confirm: Are you sure you want to unbind this address from your account?
4444
log-in:
4545
basic-login-link: Switch to basic Login
46-
with-wallet: Log in with web3
46+
with-wallet: Log In with web3
4747
select-wallet-account: => blomstra-web3.ref.select-wallet-account
4848
sign-up:
4949
basic-signup-link: Switch to basic Signup
50-
with-wallet: Sign up with web3
50+
with-wallet: Sign Up with web3
5151
select-wallet-account: => blomstra-web3.ref.select-wallet-account
5252

5353
ref:

0 commit comments

Comments
 (0)