Skip to content

Commit

Permalink
Merge pull request #172 from AElfProject/feature/ecoEarn-support
Browse files Browse the repository at this point in the history
feat: add slot and logic for forgetting pin code
  • Loading branch information
aelf-lxy authored Oct 24, 2024
2 parents 59b99f5 + 2ed50f8 commit 0cebaec
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 190 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@
# Install

```sh
yarn add @aelf-web-login/wallet-adapter-night-elf @aelf-web-login/wallet-adapter-portkey-aa @aelf-web-login/wallet-adapter-portkey-discover @aelf-web-login/wallet-adapter-react @aelf-web-login/wallet-adapter-base @aelf-web-login/wallet-adapter-bridge @aelf-web-login/utils
yarn add @aelf-web-login/wallet-adapter-night-elf @aelf-web-login/wallet-adapter-portkey-aa @aelf-web-login/wallet-adapter-portkey-discover @aelf-web-login/wallet-adapter-react @aelf-web-login/wallet-adapter-base @aelf-web-login/wallet-adapter-bridge @aelf-web-login/utils @portkey/did-ui-react
```

Then the `package.json` will be like this

```json
"dependencies": {
"@aelf-web-login/wallet-adapter-night-elf": "^0.1.0",
"@aelf-web-login/wallet-adapter-portkey-aa": "^0.1.0",
"@aelf-web-login/wallet-adapter-portkey-discover": "^0.1.0",
"@aelf-web-login/wallet-adapter-react": "^0.1.0",
"@aelf-web-login/wallet-adapter-base": "^0.1.0",
"@aelf-web-login/wallet-adapter-bridge": "^0.1.0",
"@aelf-web-login/utils": "^0.1.0",
"@aelf-web-login/wallet-adapter-night-elf": "^0.1.7",
"@aelf-web-login/wallet-adapter-portkey-aa": "^0.1.7",
"@aelf-web-login/wallet-adapter-portkey-discover": "^0.1.7",
"@aelf-web-login/wallet-adapter-react": "^0.1.7",
"@aelf-web-login/wallet-adapter-base": "^0.1.7",
"@aelf-web-login/wallet-adapter-bridge": "^0.1.7",
"@aelf-web-login/utils": "^0.1.7",
"@portkey/did-ui-react": "^2.13.2",
}
```

Expand All @@ -67,7 +68,7 @@ const RPC_SERVER_AELF = 'https://aelf-test-node.aelf.io';
const RPC_SERVER_TDVV = 'https://tdvv-public-node.aelf.io';
const RPC_SERVER_TDVW = 'https://tdvw-test-node.aelf.io';
const GRAPHQL_SERVER =
'https://dapp-aa-portkey-test.portkey.finance/Portkey_DID/PortKeyIndexerCASchema/graphql';
'https://dapp-aa-portkey-test.portkey.finance/aefinder-v2/api/app/graphql/portkey';
const CONNECT_SERVER = 'https://auth-aa-portkey-test.portkey.finance';
const SERVICE_SERVER = 'https://aa-portkey-test.portkey.finance';
const TELEGRAM_BOT_ID = 'xx';
Expand Down Expand Up @@ -103,7 +104,7 @@ const baseConfig = {
// },
// omitTelegramScript: false,
// cancelAutoLoginInTelegram: false,
enableAcceleration: true,
enableAcceleration: false,
networkType: NETWORK_TYPE,
showVconsole: false,
chainId: CHAIN_ID,
Expand Down
8 changes: 4 additions & 4 deletions 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.1.17",
"version": "0.1.18",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -33,8 +33,8 @@
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@portkey/did-ui-react": "^2.11.0",
"@portkey/types": "^2.11.0",
"@portkey/did-ui-react": "^2.13.2",
"@portkey/types": "^2.13.2",
"@types/jest": "^29.5.12",
"babel-jest": "^29.7.0",
"jest": "^29.7.0",
Expand All @@ -44,7 +44,7 @@
"typescript": "^5.3.3"
},
"peerDependencies": {
"@portkey/did-ui-react": "^2.11.0"
"@portkey/did-ui-react": "^2.13.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface IWalletAdapter<Name extends string = string> {
noNeedForConfirm?: boolean;

login(arg?: DIDWalletInfo): Promise<TWalletInfo>;
logout(): Promise<void>;
logout(isForgetPin?: boolean): Promise<void>;
loginEagerly(type?: string): Promise<void>;
// getAccounts(chainId: TChainId): Promise<string>;
// callContract<T, R>(params: ICallContractParams<T>): Promise<R>;
Expand Down Expand Up @@ -67,7 +67,7 @@ export abstract class BaseWalletAdapter<Name extends string = string>
abstract wallet: TWalletInfo;

abstract login(arg?: DIDWalletInfo): Promise<TWalletInfo>;
abstract logout(): Promise<void>;
abstract logout(isForgetPin?: boolean): Promise<void>;
abstract loginEagerly(type?: string): Promise<void>;
// abstract getAccounts(chainId: TChainId): Promise<string>;
// abstract callContract<T, R>(params: ICallContractParams<T>): Promise<R>;
Expand Down
8 changes: 4 additions & 4 deletions 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.1.17",
"version": "0.1.18",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -29,21 +29,21 @@
},
"dependencies": {
"@aelf-web-login/wallet-adapter-base": "workspace:*",
"@portkey/services": "^2.11.0",
"@portkey/services": "^2.13.2",
"@reduxjs/toolkit": "^2.2.3",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@portkey/did-ui-react": "^2.11.0",
"@portkey/did-ui-react": "^2.13.2",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"antd": "4.24.14",
"father": "^4.3.8",
"typescript": "^5.3.3"
},
"peerDependencies": {
"@portkey/did-ui-react": "^2.11.0"
"@portkey/did-ui-react": "^2.13.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
Expand Down
9 changes: 5 additions & 4 deletions packages/bridge/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ class Bridge {
});
};

doubleCheckDisconnect = async () => {
doubleCheckDisconnect = async (isForgetPin?: boolean) => {
if (isDisconnectClicked) {
return;
}
isDisconnectClicked = true;
await this.activeWallet?.logout();
await this.activeWallet?.logout(isForgetPin);
this.closeConfirmLogoutPanel();
this.closeLockPanel();
isDisconnectClicked = false;
this._logoutResolve(true);
};

disConnect = async (): Promise<boolean> => {
disConnect = async (isForgetPin?: boolean): Promise<boolean> => {
return new Promise((resolve, reject) => {
this._logoutResolve = resolve;
this._logoutReject = reject;
Expand All @@ -121,7 +121,7 @@ class Bridge {
try {
if (this.isAAWallet) {
if (this.activeWallet!.noNeedForConfirm) {
await this.doubleCheckDisconnect();
await this.doubleCheckDisconnect(isForgetPin);
} else {
this.openConfirmLogoutPanel();
}
Expand Down Expand Up @@ -228,6 +228,7 @@ class Bridge {
dispatch(clearWalletInfo());
dispatch(clearWalletType());
dispatch(clearLoginError());
dispatch(setLocking(false));
};

onLockHandler = () => {
Expand Down
14 changes: 14 additions & 0 deletions packages/bridge/src/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,17 @@
justify-content: space-between;
align-items: center;
}
.unlock-footer-text{
color: #55585E;
font-size: 14px;
font-weight: 400;
text-align: center;
line-height: 20px;
margin-left: 14px;
margin-right: 14px;
.unlock-footer-text-href{
color: #5D42FF;
padding: 0 4px;
cursor: pointer;
}
}
23 changes: 22 additions & 1 deletion packages/bridge/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
await bridgeInstance.doubleCheckDisconnect();
TelegramPlatform.close();
};
TelegramPlatform.initializeTelegramWebApp({ handleLogout });
TelegramPlatform.initializeTelegramWebApp({ tgUserChanged: handleLogout });
};

console.log('begin to init and execute handleTelegram', TelegramPlatform.isTelegramPlatform());
Expand Down Expand Up @@ -464,6 +464,26 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
isShowNestedModal,
]);

const onForgetPinHandler = useCallback(async () => {
// await bridgeInstance.onPortkeyAAUnLock(defaultPin);
await bridgeInstance.disConnect(true);
if (TelegramPlatform.isTelegramPlatform()) {
TelegramPlatform.close();
}
}, [bridgeInstance]);

const forgetPinElement = useMemo(() => {
return (
<div className="unlock-footer-text">
Forgot your PIN? Click
<span className="unlock-footer-text-href" onClick={onForgetPinHandler}>
here
</span>
to log back in.
</div>
);
}, [onForgetPinHandler]);

return (
// <PortkeyProvider networkType={baseConfig.networkType} theme="dark">
<div>
Expand All @@ -477,6 +497,7 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
onChange={setPassword}
onCancel={onCloseWrapperInternal}
onUnlock={onUnlockInternal}
footer={forgetPinElement}
/>
) : (
<DynamicWrapper
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.1.17",
"version": "0.1.18",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
"@aelf-web-login/wallet-adapter-portkey-aa": "workspace:*",
"@aelf-web-login/wallet-adapter-portkey-discover": "workspace:*",
"@aelf-web-login/wallet-adapter-react": "workspace:*",
"@portkey/did-ui-react": "^2.13.2",
"aelf-sdk": "^3.4.16-alpha.7",
"flatted": "^3.3.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"@portkey/did-ui-react": "^2.11.0",
"aelf-sdk": "^3.4.16-alpha.7"
"react-dom": "^18.0.0"
},
"devDependencies": {
"@types/react": "^18.3.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/starter/src/Demo/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const RPC_SERVER_AELF = 'https://explorer-test.aelf.io/chain';
const RPC_SERVER_TDVV = 'https://explorer-test-side02.aelf.io/chain';
const RPC_SERVER_TDVW = 'https://explorer-test-side02.aelf.io/chain';
const GRAPHQL_SERVER =
'https://dapp-aa-portkey-test.portkey.finance/Portkey_DID/PortKeyIndexerCASchema/graphql';
'https://dapp-aa-portkey-test.portkey.finance/aefinder-v2/api/app/graphql/portkey';
const CONNECT_SERVER = 'https://auth-aa-portkey-test.portkey.finance';
const SERVICE_SERVER = 'https://aa-portkey-test.portkey.finance';
const TELEGRAM_BOT_ID = '7329439364';
Expand Down Expand Up @@ -60,7 +60,7 @@ const baseConfig = {
// ConfirmLogoutDialog: CustomizedConfirmLogoutDialog,
// SignInComponent: SignInProxy,
defaultPin: '111111',
enableAcceleration: true,
enableAcceleration: false,
PortkeyProviderProps: {
theme: 'light' as any,
},
Expand All @@ -82,7 +82,7 @@ const wallets = [
appName: APP_NAME,
chainId: CHAIN_ID,
autoShowUnlock: true,
noNeedForConfirm: false,
noNeedForConfirm: 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.1.17",
"version": "0.1.18",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
6 changes: 3 additions & 3 deletions 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.1.17",
"version": "0.1.18",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand All @@ -26,13 +26,13 @@
},
"dependencies": {
"@aelf-web-login/wallet-adapter-base": "workspace:*",
"@portkey/contracts": "^2.11.0",
"@portkey/contracts": "^2.13.2",
"aelf-bridge": "^0.0.11-alpha.4",
"bn.js": "^5.2.1"
},
"devDependencies": {
"@aelf-react/types": "^0.1.10",
"@portkey/types": "^2.11.0",
"@portkey/types": "^2.13.2",
"@types/bn.js": "^5.1.5",
"father": "^4.3.8",
"typescript": "^5.3.3"
Expand Down
12 changes: 6 additions & 6 deletions 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.1.17",
"version": "0.1.18",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand All @@ -26,17 +26,17 @@
},
"dependencies": {
"@aelf-web-login/wallet-adapter-base": "workspace:*",
"@portkey/contracts": "^2.11.0",
"@portkey/utils": "^2.11.0"
"@portkey/contracts": "^2.13.2",
"@portkey/utils": "^2.13.2"
},
"devDependencies": {
"@portkey/did-ui-react": "^2.11.0",
"@portkey/types": "^2.11.0",
"@portkey/did-ui-react": "^2.13.2",
"@portkey/types": "^2.13.2",
"father": "^4.3.8",
"typescript": "^5.3.3"
},
"peerDependencies": {
"@portkey/did-ui-react": "^2.11.0"
"@portkey/did-ui-react": "^2.13.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
Expand Down
17 changes: 10 additions & 7 deletions packages/wallets/portkey-aa/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,21 @@ export class PortkeyAAWallet extends BaseWalletAdapter {
this.emit('disconnected', true);
}

async logout() {
async logout(isForgetPin = false) {
try {
const originChainId = enhancedLocalStorage.getItem(PORTKEY_ORIGIN_CHAIN_ID_KEY);
if (!originChainId) {
return;
}
await did.logout(
{
chainId: originChainId as TChainId,
},
{ onMethod: 'transactionHash' },
);
console.log('isForgetPin', isForgetPin);
if (!isForgetPin) {
await did.logout(
{
chainId: originChainId as TChainId,
},
{ onMethod: 'transactionHash' },
);
}

this._wallet = null;
this._loginState = LoginStateEnum.INITIAL;
Expand Down
8 changes: 4 additions & 4 deletions 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.1.17",
"version": "0.1.18",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand All @@ -26,14 +26,14 @@
},
"dependencies": {
"@aelf-web-login/wallet-adapter-base": "workspace:*",
"@portkey/contracts": "^2.11.0",
"@portkey/contracts": "^2.13.2",
"@portkey/detect-provider": "^2.3.5-alpha.2",
"@portkey/provider-types": "^2.3.5-alpha.2",
"@portkey/utils": "^2.11.0",
"@portkey/utils": "^2.13.2",
"bn.js": "^5.2.1"
},
"devDependencies": {
"@portkey/types": "^2.11.0",
"@portkey/types": "^2.13.2",
"@types/bn.js": "^5.1.5",
"father": "^4.3.8",
"typescript": "^5.3.3"
Expand Down
Loading

0 comments on commit 0cebaec

Please sign in to comment.