Skip to content

Commit 5303a16

Browse files
committed
Handle registred wallet addresses
1 parent ca1aaa7 commit 5303a16

File tree

8 files changed

+101
-36
lines changed

8 files changed

+101
-36
lines changed

ui/component/walletBalance/view.jsx

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Symbol from 'component/common/symbol';
1313
import LbcSymbol from 'component/common/lbc-symbol';
1414
import I18nMessage from 'component/i18nMessage';
1515
import { useArStatus } from 'effects/use-ar-status';
16+
import { LocalStorage } from 'util/storage';
1617

1718
type Props = {
1819
clientSettings: any,
@@ -68,7 +69,7 @@ const WalletBalance = (props: Props) => {
6869
doArDisconnect,
6970
} = props;
7071

71-
const { hasArweaveExtension, hasArSignin, hasArConnection, isSigningIn, hasConnection } = useArStatus();
72+
const { hasArweaveExtension, hasArSignin, hasArConnection, isSigningIn, hasConnection, addressInUse } = useArStatus();
7273

7374
const isMobile = useIsMobile();
7475
const isWanderApp = navigator.userAgent.includes('WanderMobile');
@@ -232,41 +233,50 @@ const WalletBalance = (props: Props) => {
232233
</>
233234
)
234235
}
235-
subtitle={!hasArConnection ? (
236-
<>
237-
<div className="wallet-check-row">
238-
<div>{__(`Wander login${!isMobile ? ' or extension' : ''}`)}</div>
239-
<div>
240-
{!hasConnection && !isSigningIn ? (
241-
<img src="https://thumbs.odycdn.com/bd2adbec2979b00b1fcb6794e118d5db.webp" alt="Failed" />
242-
) : isSigningIn ? (
243-
<img src="https://thumbs.odycdn.com/fcf0fa003f3537b8e5d6acd1d5a96055.webp" alt="Loading..." />
244-
) : (
245-
<img src="https://thumbs.odycdn.com/8ee966185b537b147fb7be4412b6bc68.webp" alt="Success" />
246-
)}
236+
subtitle={
237+
!hasArConnection ? (
238+
<>
239+
<div className="wallet-check-row">
240+
<div>{__(`Wander login${!isMobile ? ' or extension' : ''}`)}</div>
241+
<div>
242+
{!hasConnection && !isSigningIn ? (
243+
<img src="https://thumbs.odycdn.com/bd2adbec2979b00b1fcb6794e118d5db.webp" alt="Failed" />
244+
) : isSigningIn ? (
245+
<img src="https://thumbs.odycdn.com/fcf0fa003f3537b8e5d6acd1d5a96055.webp" alt="Loading..." />
246+
) : (
247+
<img src="https://thumbs.odycdn.com/8ee966185b537b147fb7be4412b6bc68.webp" alt="Success" />
248+
)}
249+
</div>
247250
</div>
248-
</div>
249251

250-
<div className="wallet-check-row">
251-
<div>{__('Wander wallet connection')}</div>
252-
<div>
253-
{hasArConnection ? (
254-
<img src="https://thumbs.odycdn.com/8ee966185b537b147fb7be4412b6bc68.webp" />
255-
) : (
256-
<img src="https://thumbs.odycdn.com/bd2adbec2979b00b1fcb6794e118d5db.webp" />
257-
)}
252+
<div className="wallet-check-row">
253+
<div>{__('Wander wallet connection')}</div>
254+
<div>
255+
{hasArConnection ? (
256+
<img src="https://thumbs.odycdn.com/8ee966185b537b147fb7be4412b6bc68.webp" />
257+
) : (
258+
<img src="https://thumbs.odycdn.com/bd2adbec2979b00b1fcb6794e118d5db.webp" />
259+
)}
260+
</div>
258261
</div>
259-
</div>
260262
</>
261-
) : (
262-
<I18nMessage tokens={{
263+
) : (
264+
<I18nMessage
265+
tokens={{
263266
ar: <Symbol inline token="ar" />,
264267
usd: <Symbol inline token="usd" />,
265-
price: <img style={{ height: '16px' }} src="https://thumbnails.odycdn.com/optimize/s:40:0/quality:95/plain/https://thumbs.odycdn.com/6392753ffcf0f9318c3bded3b13388e6.webp" />,
266-
}}>
267-
Your total %ar% balance in %usd%. The displayed %usd% amount is subject to change and reflects the value based on the current exchange rate (%price%).
268+
price: (
269+
<img
270+
style={{ height: '16px' }}
271+
src="https://thumbnails.odycdn.com/optimize/s:40:0/quality:95/plain/https://thumbs.odycdn.com/6392753ffcf0f9318c3bded3b13388e6.webp"
272+
/>
273+
),
274+
}}
275+
>
276+
Your total %ar% balance in %usd%. The displayed %usd% amount is subject to change and reflects the value
277+
based on the current exchange rate (%price%).
268278
</I18nMessage>
269-
)
279+
)
270280
}
271281
background
272282
actions={
@@ -357,6 +367,23 @@ const WalletBalance = (props: Props) => {
357367
{`%text% %status%`}
358368
</I18nMessage>
359369
</div>
370+
) : !hasArConnection && addressInUse ? (
371+
<div>
372+
<p>
373+
{__(
374+
'The currently active Wander wallet is already connected to another Odysee account. Please switch to a different wallet.'
375+
)}
376+
</p>
377+
<a
378+
className="link"
379+
onClick={() => {
380+
LocalStorage.setItem('AR_ADDRESS_IN_USE', 'false');
381+
window.wanderInstance.open();
382+
}}
383+
>
384+
{__('Change login')}
385+
</a>
386+
</div>
360387
) : !hasArConnection ? (
361388
<div>
362389
<I18nMessage

ui/component/wander/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { connect } from 'react-redux';
22
import { doArInit, doArConnect, doArSetAuth, doArUpdateBalance, doCleanTips } from 'redux/actions/arwallet';
33
import { selectArweaveWanderAuth, selectArweaveAddress, selectArweaveConnecting } from 'redux/selectors/arwallet';
4+
import { selectArAccountRegisteringError } from 'redux/selectors/stripe';
45
import { selectTheme } from 'redux/selectors/settings';
56
import { selectUserVerifiedEmail } from 'redux/selectors/user';
67
import Wander from './view';
@@ -11,6 +12,7 @@ const select = (state) => ({
1112
theme: selectTheme(state),
1213
auth: selectArweaveWanderAuth(state),
1314
authenticated: selectUserVerifiedEmail(state),
15+
addressInUse: selectArAccountRegisteringError(state) === 'address already exists for another user',
1416
});
1517

1618
const perform = (dispatch) => ({

ui/component/wander/view.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Props = {
1111
theme: string,
1212
auth: any,
1313
authenticated: any,
14+
addressInUse: boolean,
1415
doArInit: () => void,
1516
connectArWallet: () => void,
1617
doArSetAuth: (status: string) => void,
@@ -23,6 +24,7 @@ export default function Wander(props: Props) {
2324
theme,
2425
auth,
2526
authenticated,
27+
addressInUse,
2628
doArInit,
2729
doArSetAuth,
2830
connecting,
@@ -36,7 +38,8 @@ export default function Wander(props: Props) {
3638
const wrapperRef = React.useRef();
3739

3840
React.useEffect(() => {
39-
if (instance) {
41+
const arAddressInUse = addressInUse || LocalStorage.getItem('AR_ADDRESS_IN_USE') === 'true';
42+
if (instance && !arAddressInUse) {
4043
if (auth?.authStatus === 'onboarding') instance.open();
4144
if (auth?.authStatus === 'authenticated') {
4245
// Connected
@@ -190,6 +193,9 @@ export default function Wander(props: Props) {
190193
) {
191194
if (data.data.authStatus !== 'loading') {
192195
LocalStorage.setItem('WALLET_TYPE', data.data.authType);
196+
if (data.data.authStatus === 'authenticated') {
197+
LocalStorage.setItem('AR_ADDRESS_IN_USE', 'false');
198+
}
193199
window.wanderInstance.close();
194200
doArSetAuth(data.data);
195201
if (data.data.authStatus === 'authenticated') {

ui/effects/use-ar-status.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { useState, useEffect } from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
33
import { LocalStorage } from 'util/storage';
44
import { selectArweaveWanderAuth, selectArweaveStatus } from 'redux/selectors/arwallet';
5+
import { selectArAccountRegisteringError } from 'redux/selectors/stripe';
56
import { useIsMobile } from 'effects/use-screensize';
67
import { doArConnect } from 'redux/actions/arwallet';
78

89
export const useArStatus = () => {
910
const wanderAuth = useSelector(selectArweaveWanderAuth);
1011
const arStatus = useSelector(selectArweaveStatus);
12+
const reduxAddressInUse = useSelector(selectArAccountRegisteringError) === 'address already exists for another user';
13+
const addressInUse = reduxAddressInUse || LocalStorage.getItem('AR_ADDRESS_IN_USE') === 'true';
1114
const isMobile = useIsMobile();
1215
const dispatch = useDispatch();
1316

@@ -64,7 +67,7 @@ export const useArStatus = () => {
6467
!hasArConnection
6568
) {
6669
const intentionalDisconnect = LocalStorage.getItem('WANDER_DISCONNECT') === 'true';
67-
if (!intentionalDisconnect) {
70+
if (!intentionalDisconnect && !addressInUse) {
6871
dispatch(doArConnect());
6972
}
7073
}
@@ -80,5 +83,6 @@ export const useArStatus = () => {
8083
hasConnection,
8184
hasArAddress,
8285
activeArStatus,
86+
addressInUse,
8387
};
8488
};

ui/modal/modalArweaveConnect/view.jsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ export default function ModalAnnouncements(props: Props) {
5353

5454
React.useEffect(() => {
5555
// automatically register first address if there isn't one
56-
if (!hasArweaveEntry) {
56+
if (!hasArweaveEntry && walletAddress) {
5757
doRegisterArweaveAddress(walletAddress, true)
5858
.then(() => {
5959
doHideModal();
6060
})
61-
.catch((e) => {});
61+
.catch((e) => {
62+
if (e?.message === 'address already exists for another user') {
63+
doHideModal();
64+
}
65+
});
6266
}
6367
}, [walletAddress, doRegisterArweaveAddress, doHideModal, hasArweaveEntry, apiEntryWithAddress]);
6468

@@ -191,9 +195,15 @@ export default function ModalAnnouncements(props: Props) {
191195
const showRegister = !showConnecting && !arAccountRegisteringError && hasArweaveEntry && !apiEntryWithAddress;
192196
const showMakeDefault =
193197
!showConnecting && !arAccountRegisteringError && apiEntryWithAddress && defaultApiAddress !== walletAddress;
194-
const showErrorCard = !showConnecting && !!arAccountRegisteringError;
198+
const showErrorCard =
199+
!showConnecting &&
200+
!!arAccountRegisteringError &&
201+
arAccountRegisteringError !== 'address already exists for another user';
195202

196-
if (apiEntryWithAddress && !showConnecting && !showRegister && !showMakeDefault) {
203+
if (
204+
(apiEntryWithAddress && !showConnecting && !showRegister && !showMakeDefault) ||
205+
arAccountRegisteringError === 'address already exists for another user'
206+
) {
197207
handleCloseModal();
198208
return null;
199209
}

ui/redux/actions/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ function doSignOutAction() {
607607
await pushNotifications.disconnect(user.id);
608608
}
609609
} finally {
610+
LocalStorage.setItem('AR_ADDRESS_IN_USE', 'false');
610611
Lbryio.call('user', 'signout')
611612
.then(doSignOutCleanup)
612613
.then(async () => {

ui/redux/actions/arwallet.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export function doArInit() {
7070
}
7171

7272
export function doArConnect() {
73+
if (LocalStorage.getItem('AR_ADDRESS_IN_USE') === 'true') {
74+
return () => {};
75+
}
7376
LocalStorage.setItem('WANDER_DISCONNECT', 'false');
7477
return async (dispatch: Dispatch, getState: GetState) => {
7578
dispatch({ type: ARCONNECT_STARTED });
@@ -135,7 +138,10 @@ export function doArConnect() {
135138
}
136139

137140
export function doArUpdateBalance() {
138-
return async (dispatch: Dispatch) => {
141+
return async (dispatch: Dispatch, getState: GetState) => {
142+
if (LocalStorage.getItem('AR_ADDRESS_IN_USE') === 'true') {
143+
return;
144+
}
139145
dispatch({ type: ARCONNECT_FETCHBALANCE });
140146
if (window.arweaveWallet) {
141147
try {

ui/redux/actions/stripe.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
selectAccountStatusFetching,
99
} from 'redux/selectors/stripe';
1010
import { doToast } from 'redux/actions/notifications';
11+
import { LocalStorage } from 'util/storage';
1112

1213
import * as ACTIONS from 'constants/action_types';
1314
import * as STRIPE from 'constants/stripe';
@@ -281,6 +282,13 @@ export const doRegisterArweaveAddress = (address: string, makeDefault: boolean)
281282
return;
282283
}
283284

285+
if (e.message === 'address already exists for another user') {
286+
LocalStorage.setItem('AR_ADDRESS_IN_USE', 'true');
287+
dispatch({ type: ACTIONS.AR_ADDR_REGISTER_ERROR, data: e.message });
288+
dispatch({ type: ACTIONS.ARCONNECT_FAILURE, data: { error: e.message } });
289+
throw e;
290+
}
291+
284292
dispatch(
285293
doOpenModal(MODALS.ERROR, {
286294
error: e.message || e,
@@ -292,6 +300,7 @@ export const doRegisterArweaveAddress = (address: string, makeDefault: boolean)
292300
};
293301

294302
export const doRegisterArweaveAddressClear = () => (dispatch: Dispatch) => {
303+
LocalStorage.setItem('AR_ADDRESS_IN_USE', 'false');
295304
dispatch({ type: ACTIONS.AR_ADDR_REGISTER_CLEAR });
296305
};
297306

0 commit comments

Comments
 (0)