Skip to content

Commit

Permalink
feat: add enableAcceleration for portkeyAA package
Browse files Browse the repository at this point in the history
  • Loading branch information
aelf-lxy committed Nov 13, 2024
1 parent 44d9bc0 commit 6e5179f
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"devDependencies": {
"@babel/parser": "^7.24.0",
"@biomejs/biome": "^1.4.1",
"@changesets/changelog-git": "^0.2.0",
"@changesets/changelog-git": "^0.2.1-alpha.3",
"@changesets/cli": "^2.27.1",
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
"@testing-library/react": "^14.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-base",
"version": "0.2.0",
"version": "0.2.1-alpha.3",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-bridge",
"version": "0.2.0",
"version": "0.2.1-alpha.3",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ export function initBridge({ baseConfig, wallets, didConfig }: IConfigProps): IB
}

export * as PortkeyDid from '@portkey/did-ui-react';

// export { demoFn } from './ui';
52 changes: 39 additions & 13 deletions packages/bridge/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
enhancedLocalStorage,
PORTKEYAA,
OperationTypeEnum,
// EventEmitter,
} from '@aelf-web-login/wallet-adapter-base';
import { Bridge } from './bridge';
import {
Expand Down Expand Up @@ -76,6 +77,8 @@ interface ISignInModalProps {
}
const { isMobile } = utils;

// const EE = new EventEmitter();

const ConfirmLogoutDialog = (props: Partial<IConfirmLogoutDialogProps>) => {
const { title, subTitle, okTxt, cancelTxt, visible, onOk, onCancel, width, mobileWidth } = {
...defaultProps,
Expand Down Expand Up @@ -295,30 +298,34 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
}
console.log('begin to excute autoAuthInTelegram');
if (enhancedLocalStorage.getItem('connectedWallet') === PORTKEYAA) {
ConfigProvider.setGlobalConfig({
globalLoadingHandler: {
onSetLoading: (loadingInfo) => {
console.log(loadingInfo, 'loadingInfo===');
if (enableAcceleration) {
ConfigProvider.setGlobalConfig({
globalLoadingHandler: {
onSetLoading: (loadingInfo) => {
console.log(loadingInfo, 'loadingInfo===');
},
},
},
});
});
}
await bridgeInstance.onPortkeyAAUnLock(defaultPin);
return;
}
if (!cancelAutoLoginInTelegram) {
ConfigProvider.setGlobalConfig({
globalLoadingHandler: {
onSetLoading: (loadingInfo) => {
console.log(loadingInfo, 'loadingInfo===');
if (enableAcceleration) {
ConfigProvider.setGlobalConfig({
globalLoadingHandler: {
onSetLoading: (loadingInfo) => {
console.log(loadingInfo, 'loadingInfo===');
},
},
},
});
});
}
console.log('begin to excute handleTelegram');
handleTelegram();
}
}
autoAuthInTelegram();
}, [bridgeInstance, cancelAutoLoginInTelegram, defaultPin, handleTelegram]);
}, [bridgeInstance, cancelAutoLoginInTelegram, defaultPin, enableAcceleration, handleTelegram]);

bridgeInstance.autoLogin = () => {
handleTelegram();
Expand Down Expand Up @@ -512,6 +519,18 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
);
}, [onForgetPinHandler]);

// const [showGuardianApprovalModal, setShowGuardianApprovalModal] = useState(false);

// useEffect(() => {
// const hander = (args: boolean) => {
// setShowGuardianApprovalModal(args);
// };
// EE.on('SET_GLOBAL_LOADING_1', hander);
// return () => {
// EE.off('SET_GLOBAL_LOADING_1', hander);
// };
// }, []);

return (
// <PortkeyProvider networkType={baseConfig.networkType} theme="dark">
<div>
Expand Down Expand Up @@ -583,3 +602,10 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
};

export default SignInModal;

// const demoFn = (bool: boolean) => {
// console.log('demoFn', EE);
// EE.emit('SET_GLOBAL_LOADING_1', bool);
// };

// export { demoFn };
26 changes: 15 additions & 11 deletions packages/bridge/src/useTelegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const useTelegram = (
async (value: IGuardianIdentifierInfo, extraData?: TOnSuccessExtraData) => {
// setDrawerVisible(false);
// setModalVisible(false);
if (extraData) {
if (enableAcceleration && extraData) {
setOriginChainId(extraData.originChainId);
setCaHash(extraData.caHash);
caInfoRef.current = {
Expand Down Expand Up @@ -244,7 +244,7 @@ const useTelegram = (
}
} else {
setLoading(false);
if (isTelegramPlatform) {
if (isTelegramPlatform && enableAcceleration) {
console.log('intg-----------more guardian', signResult.value.guardianList);
setGuardianList(signResult.value.guardianList || []);
setTimeout(() => {
Expand Down Expand Up @@ -277,17 +277,21 @@ const useTelegram = (
});

const handleTelegram = useCallback(async () => {
const res = await socialLoginAuth({
type: SocialLoginType.TELEGRAM,
network: network,
});
try {
const res = await socialLoginAuth({
type: SocialLoginType.TELEGRAM,
network: network,
});

console.log('socialLoginAuth', res);
console.log('socialLoginAuth', res);

signHandle.onSocialFinish({
type: res!.provider,
data: { accessToken: res!.token },
});
signHandle.onSocialFinish({
type: res!.provider,
data: { accessToken: res!.token },
});
} catch (e) {
console.log('execute await socialLoginAuth error', e);
}
}, [network, signHandle]);

const onTGSignInApprovalSuccess = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-react",
"version": "0.2.0",
"version": "0.2.1-alpha.3",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
15 changes: 15 additions & 0 deletions packages/starter/src/Demo/LoginDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from 'react';
import { Button, message, Divider, Flex } from 'antd';
import { useConnectWallet } from '@aelf-web-login/wallet-adapter-react';
// import { demoFn } from '@aelf-web-login/wallet-adapter-bridge';

const LoginDemo: React.FC = () => {
const {
Expand Down Expand Up @@ -47,6 +48,20 @@ const LoginDemo: React.FC = () => {
return (
<div>
<Flex gap={'small'}>
{/* <Button
onClick={() => {
demoFn(true);
}}
>
open
</Button>
<Button
onClick={() => {
demoFn(false);
}}
>
close
</Button> */}
<Button type="primary" onClick={onConnectBtnClickHandler} disabled={isConnected}>
{isLocking ? 'unlock' : 'connect'}
</Button>
Expand Down
1 change: 1 addition & 0 deletions packages/starter/src/Demo/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const wallets = [
chainId: CHAIN_ID,
autoShowUnlock: true,
noNeedForConfirm: true,
enableAcceleration: true,
}),
// new PortkeyDiscoverWallet({
// networkType: NETWORK_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/utils",
"version": "0.2.0",
"version": "0.2.1-alpha.3",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/night-elf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-night-elf",
"version": "0.2.0",
"version": "0.2.1-alpha.3",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/portkey-aa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-portkey-aa",
"version": "0.2.0",
"version": "0.2.1-alpha.3",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
13 changes: 10 additions & 3 deletions packages/wallets/portkey-aa/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface IPortkeyAAWalletAdapterConfig {
chainId: TChainId;
autoShowUnlock: boolean;
noNeedForConfirm?: boolean;
enableAcceleration?: boolean;
}

type TStatus = 'initial' | 'inBeforeLastGuardianApprove' | 'inCreatePending' | 'inFinish';
Expand Down Expand Up @@ -126,6 +127,7 @@ export class PortkeyAAWallet extends BaseWalletAdapter {
enhancedLocalStorage.setItem(PORTKEY_ORIGIN_CHAIN_ID_KEY, didWalletInfo.chainId);
this._loginState = LoginStateEnum.CONNECTING;
const chainId = this._config.chainId;
const enableAcceleration = this._config.enableAcceleration;
if (didWalletInfo.chainId !== chainId) {
const caInfo = await did.didWallet.getHolderInfoByContract({
caHash: didWalletInfo.caInfo?.caHash,
Expand All @@ -135,7 +137,7 @@ export class PortkeyAAWallet extends BaseWalletAdapter {
}

let nickName = 'Wallet 01';
if (this._status !== 'inBeforeLastGuardianApprove') {
if (enableAcceleration && this._status !== 'inBeforeLastGuardianApprove') {
try {
const holderInfo = await did.getCAHolderInfo(didWalletInfo.chainId);
nickName = holderInfo.nickName;
Expand Down Expand Up @@ -177,6 +179,7 @@ export class PortkeyAAWallet extends BaseWalletAdapter {
this._status = 'inFinish';
}
this.emit('connected', this._wallet);
this.emit('loginOnChainStatusChanged', did.didWallet.isLoginStatus!);
console.log('did.didWallet.isLoginStatus-1', did.didWallet.isLoginStatus);
return this._wallet;
} catch (error) {
Expand Down Expand Up @@ -507,16 +510,20 @@ export class PortkeyAAWallet extends BaseWalletAdapter {
args,
sendOptions,
}: ICallContractParams<T>) {
const enableAcceleration = this._config.enableAcceleration;
if (!this._wallet) {
throw makeError(ERR_CODE.PORTKEY_AA_NOT_CONNECTED);
}
if (!contractAddress) {
throw makeError(ERR_CODE.INVALID_CONTRACT_ADDRESS);
}
if (this._status === 'initial' || this._status === 'inBeforeLastGuardianApprove') {
if (
enableAcceleration &&
(this._status === 'initial' || this._status === 'inBeforeLastGuardianApprove')
) {
throw makeError(ERR_CODE.CANT_CALL_SEND_METHOD);
}
if (this._status === 'inCreatePending') {
if (enableAcceleration && this._status === 'inCreatePending') {
console.log(
'----------in callSendMethod and _status is inCreatePending, begin to execute getLoginStatus, sessionId=',
did.didWallet.sessionId,
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/portkey-discover/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-portkey-discover",
"version": "0.2.0",
"version": "0.2.1-alpha.3",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down

0 comments on commit 6e5179f

Please sign in to comment.