Skip to content

Commit f05900e

Browse files
authored
Merge pull request #176 from AElfProject/feature/tg-acceleration
feat: support tg login acceleration for phase 2
2 parents 7a7a660 + 44d9bc0 commit f05900e

File tree

20 files changed

+502
-218
lines changed

20 files changed

+502
-218
lines changed

packages/base/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aelf-web-login/wallet-adapter-base",
3-
"version": "0.1.19",
3+
"version": "0.2.0",
44
"type": "module",
55
"main": "dist/esm/index.js",
66
"module": "dist/esm/index.js",
@@ -33,8 +33,8 @@
3333
"@babel/core": "^7.24.7",
3434
"@babel/preset-env": "^7.24.7",
3535
"@babel/preset-typescript": "^7.24.7",
36-
"@portkey/did-ui-react": "^2.13.2",
37-
"@portkey/types": "^2.13.2",
36+
"@portkey/did-ui-react": "^2.14.0-alpha.6",
37+
"@portkey/types": "^2.14.0-alpha.6",
3838
"@types/jest": "^29.5.12",
3939
"babel-jest": "^29.7.0",
4040
"jest": "^29.7.0",
@@ -44,7 +44,7 @@
4444
"typescript": "^5.3.3"
4545
},
4646
"peerDependencies": {
47-
"@portkey/did-ui-react": "^2.13.2"
47+
"@portkey/did-ui-react": "^2.14.0-alpha.6"
4848
},
4949
"publishConfig": {
5050
"registry": "https://registry.npmjs.org",

packages/base/src/adapter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
TSignatureParams,
77
TWalletInfo,
88
TChainId,
9-
WalletStateEnum,
109
ICallContractParams,
1110
IMultiTransactionParams,
1211
IMultiTransactionResult,
12+
LoginStatusEnum,
1313
} from './types';
1414

1515
export { EventEmitter };
@@ -22,6 +22,7 @@ export interface IWalletAdapterEvents {
2222
lock(): void;
2323
// readyStateChange(readyState: WalletStateEnum): void;
2424
error(error: TWalletError): void;
25+
loginOnChainStatusChanged(status: LoginStatusEnum): void;
2526
}
2627
export interface IWalletAdapter<Name extends string = string> {
2728
name: WalletName<Name>;

packages/base/src/types.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SendOptions, IContract } from '@portkey/types';
1+
import { SendOptions, IContract, LoginStatusEnum } from '@portkey/types';
22

33
export enum WalletStateEnum {
44
// Wallet plug-in detected
@@ -100,3 +100,21 @@ export interface IMultiTransactionParams<T> {
100100
export interface IMultiTransactionResult {
101101
string: string[];
102102
}
103+
104+
export enum OperationTypeEnum {
105+
unknown = 0,
106+
register = 1,
107+
communityRecovery = 2,
108+
addGuardian = 3,
109+
deleteGuardian = 4,
110+
editGuardian = 5,
111+
removeOtherManager = 6,
112+
setLoginAccount = 7,
113+
managerApprove = 8,
114+
modifyTransferLimit = 9,
115+
transferApprove = 10,
116+
unsetLoginAccount = 11,
117+
setupBackupMailbox = 13,
118+
}
119+
120+
export { LoginStatusEnum };

packages/bridge/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aelf-web-login/wallet-adapter-bridge",
3-
"version": "0.1.19",
3+
"version": "0.2.0",
44
"type": "module",
55
"main": "dist/esm/index.js",
66
"module": "dist/esm/index.js",
@@ -29,21 +29,22 @@
2929
},
3030
"dependencies": {
3131
"@aelf-web-login/wallet-adapter-base": "workspace:*",
32-
"@portkey/services": "^2.13.2",
32+
"@portkey/services": "^2.14.0-alpha.6",
3333
"@reduxjs/toolkit": "^2.2.3",
3434
"react": "^18.0.0",
3535
"react-dom": "^18.0.0"
3636
},
3737
"devDependencies": {
38-
"@portkey/did-ui-react": "^2.13.2",
38+
"@portkey/types": "^2.14.0-alpha.6",
39+
"@portkey/did-ui-react": "^2.14.0-alpha.6",
3940
"@types/react": "^18.3.1",
4041
"@types/react-dom": "^18.3.0",
4142
"antd": "4.24.14",
4243
"father": "^4.3.8",
4344
"typescript": "^5.3.3"
4445
},
4546
"peerDependencies": {
46-
"@portkey/did-ui-react": "^2.13.2"
47+
"@portkey/did-ui-react": "^2.14.0-alpha.6"
4748
},
4849
"publishConfig": {
4950
"registry": "https://registry.npmjs.org",

packages/bridge/src/bridge.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
utils,
1515
IMultiTransactionParams,
1616
IMultiTransactionResult,
17+
LoginStatusEnum,
1718
} from '@aelf-web-login/wallet-adapter-base';
1819
import {
1920
setWalletInfo,
@@ -24,6 +25,7 @@ import {
2425
dispatch,
2526
setLoginError,
2627
clearLoginError,
28+
setLoginOnChainStatus,
2729
} from './store';
2830
import { CreatePendingInfo, DIDWalletInfo, TelegramPlatform } from '@portkey/did-ui-react';
2931
import { IBaseConfig } from '.';
@@ -53,6 +55,7 @@ class Bridge {
5355
disconnected: this.onDisConnectedHandler,
5456
lock: this.onLockHandler,
5557
error: this.onConnectErrorHandler,
58+
loginOnChainStatusChanged: this.onLoginOnChainStatusChangedHandler,
5659
};
5760
this.bindEvents();
5861
}
@@ -229,6 +232,7 @@ class Bridge {
229232
dispatch(clearWalletType());
230233
dispatch(clearLoginError());
231234
dispatch(setLocking(false));
235+
dispatch(setLoginOnChainStatus(LoginStatusEnum.INIT));
232236
};
233237

234238
onLockHandler = () => {
@@ -253,6 +257,10 @@ class Bridge {
253257
dispatch(setLoginError(err));
254258
};
255259

260+
onLoginOnChainStatusChangedHandler = (status: LoginStatusEnum) => {
261+
dispatch(setLoginOnChainStatus(status));
262+
};
263+
256264
bindEvents = () => {
257265
console.log('bindEvents', this.activeWallet);
258266
if (!this.activeWallet) {
@@ -375,6 +383,7 @@ class Bridge {
375383
dispatch(setLocking(false));
376384
dispatch(clearLoginError());
377385
}
386+
378387
return walletInfo;
379388
} catch (error) {
380389
console.log('onPortkeyAAUnLockFail----------');

packages/bridge/src/store.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { createSlice, configureStore, EnhancedStore } from '@reduxjs/toolkit';
22
import { TWalletInfo, WalletTypeEnum, TWalletError } from '@aelf-web-login/wallet-adapter-base';
3+
import { LoginStatusEnum } from '@portkey/types';
34

45
type TState = {
56
walletInfo: TWalletInfo;
67
isLocking: boolean;
78
walletType: WalletTypeEnum;
89
loginError: TWalletError | null;
10+
loginOnChainStatus: LoginStatusEnum;
911
};
1012

1113
const initialState: TState = {
1214
walletInfo: undefined,
1315
isLocking: false,
1416
walletType: WalletTypeEnum.unknown,
1517
loginError: null,
18+
loginOnChainStatus: LoginStatusEnum.INIT,
1619
};
1720

1821
const aelfWebLoginSlice = createSlice({
@@ -40,6 +43,9 @@ const aelfWebLoginSlice = createSlice({
4043
clearLoginError: (state) => {
4144
state.loginError = null;
4245
},
46+
setLoginOnChainStatus: (state, action) => {
47+
state.loginOnChainStatus = action.payload;
48+
},
4349
},
4450
});
4551

@@ -79,6 +85,7 @@ export const {
7985
clearWalletType,
8086
setLoginError,
8187
clearLoginError,
88+
setLoginOnChainStatus,
8289
} = aelfWebLoginSlice.actions;
8390

8491
export type AppDispatch = typeof store.dispatch;

packages/bridge/src/ui.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
utils,
55
enhancedLocalStorage,
66
PORTKEYAA,
7+
OperationTypeEnum,
78
} from '@aelf-web-login/wallet-adapter-base';
89
import { Bridge } from './bridge';
910
import {
@@ -15,6 +16,9 @@ import {
1516
TelegramPlatform,
1617
CreatePendingInfo,
1718
setLoading,
19+
GuardianApprovalModal,
20+
getOperationDetails,
21+
ConfigProvider,
1822
} from '@portkey/did-ui-react';
1923
import '@portkey/did-ui-react/dist/assets/index.css';
2024
import { IBaseConfig } from '.';
@@ -230,7 +234,16 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
230234
const [isWrongPassword, setIsWrongPassword] = useState(false);
231235
const [isShowConfirmLogoutPanel, setIsShowConfirmLogoutPanel] = useState(false);
232236
const [isShowNestedModal, setIsShowNestedModal] = useState(false);
233-
const { handleTelegram, currentLifeCircle } = useTelegram(
237+
const {
238+
handleTelegram,
239+
currentLifeCircle,
240+
guardianList,
241+
approvalVisible,
242+
setApprovalVisible,
243+
caHash,
244+
originChainId,
245+
onTGSignInApprovalSuccess,
246+
} = useTelegram(
234247
baseConfig.enableAcceleration,
235248
baseConfig.defaultPin,
236249
baseConfig.chainId,
@@ -282,10 +295,24 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
282295
}
283296
console.log('begin to excute autoAuthInTelegram');
284297
if (enhancedLocalStorage.getItem('connectedWallet') === PORTKEYAA) {
298+
ConfigProvider.setGlobalConfig({
299+
globalLoadingHandler: {
300+
onSetLoading: (loadingInfo) => {
301+
console.log(loadingInfo, 'loadingInfo===');
302+
},
303+
},
304+
});
285305
await bridgeInstance.onPortkeyAAUnLock(defaultPin);
286306
return;
287307
}
288308
if (!cancelAutoLoginInTelegram) {
309+
ConfigProvider.setGlobalConfig({
310+
globalLoadingHandler: {
311+
onSetLoading: (loadingInfo) => {
312+
console.log(loadingInfo, 'loadingInfo===');
313+
},
314+
},
315+
});
289316
console.log('begin to excute handleTelegram');
290317
handleTelegram();
291318
}
@@ -527,6 +554,23 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
527554
</DynamicWrapper>
528555
)}
529556

557+
{guardianList?.length && (
558+
<GuardianApprovalModal
559+
open={approvalVisible}
560+
isAsyncVerify
561+
networkType={baseConfig.networkType}
562+
caHash={caHash}
563+
originChainId={originChainId}
564+
targetChainId={baseConfig.chainId}
565+
guardianList={guardianList}
566+
operationType={OperationTypeEnum.communityRecovery}
567+
operationDetails={getOperationDetails(OperationTypeEnum.communityRecovery)}
568+
onClose={() => setApprovalVisible(false)}
569+
onBack={() => setApprovalVisible(false)}
570+
onApprovalSuccess={onTGSignInApprovalSuccess}
571+
/>
572+
)}
573+
530574
<FinalConfirmLogoutDialog
531575
visible={isShowConfirmLogoutPanel}
532576
onOk={confirmLogoutHandler}

0 commit comments

Comments
 (0)