Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4.0-alpha.19",
"version": "0.4.0-alpha.20",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/base/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const ERR_CODE = {
IN_FINISH_BUT_STATUS_IS_NOT_SUCCESS: 10023,
UNKNOWN: 10024,
DISCOVER_LOGIN_REQUIRED_APP: 10025,
NIGHT_ELF_NOT_DETECTED: 10026,
};

export const ERR_CODE_MSG: {
Expand Down Expand Up @@ -59,6 +60,7 @@ export const ERR_CODE_MSG: {
10023: 'Login completed, but the isLoginStatus is not success. Please log in again',
10024: 'Unknown error',
10025: 'Please use the FairyVault app or the FairyVault browser extension on your computer.',
10026: 'NightElf is not detected or has been disabled. Please connect in again.',
};

export function makeError(code: number, nativeError?: any): TWalletError {
Expand Down
5 changes: 5 additions & 0 deletions packages/base/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { getOriginalAddress } from './getOriginalAddress';
import { isPortkeyApp } from './isPortkeyApp';
import { isFairyVaultApp } from './isFairyVaultApp';
import { sleep } from './sleep';
import { checkConnectedWallet, checkNightElf, checkPrevLoginType } from './nightElf';

export default {
isMobileDevices,
getOriginalAddress,
isPortkeyApp,
isFairyVaultApp,
sleep,
checkConnectedWallet,
checkNightElf,
checkPrevLoginType,
};
47 changes: 47 additions & 0 deletions packages/base/src/utils/nightElf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Storage } from '../enhancedLocalStorage';
import { WalletTypeEnum } from '../types';

export function checkPrevLoginType(type = WalletTypeEnum.aa, storage: Storage = localStorage) {
return storage.getItem('connectedWallet') === type;
}

export function checkConnectedWallet(type = WalletTypeEnum.aa, storage: Storage = localStorage) {
try {
if (checkPrevLoginType(type)) storage.removeItem('connectedWallet');
} catch (error) {
console.log(error, '====checkConnectedWallet');
}
}

export async function checkNightElf(): Promise<boolean> {
let resolveTemp: ((arg0: boolean) => void) | undefined = undefined;
async function check(): Promise<boolean> {
return new Promise((resolve, reject) => {
const win = window as any;
if (win.NightElf) {
console.log('There is NightElf');
resolve(true);
return;
}
setTimeout(() => {
reject({
error: 200001,
message: 'timeout, please download and install the NightELF explorer extension',
});
}, 5000);
resolveTemp = resolve;
});
}
if (typeof window !== 'undefined') {
document.addEventListener('NightElf', () => {
resolveTemp?.(true);
});
}

try {
return await check();
} catch (error) {
console.log(error, '====checkNightElf');
return false;
}
}
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.4.0-alpha.19",
"version": "0.4.0-alpha.20",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
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.4.0-alpha.19",
"version": "0.4.0-alpha.20",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
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.4.0-alpha.19",
"version": "0.4.0-alpha.20",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/fairy-vault-discover/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-fairy-vault-discover",
"version": "0.4.0-alpha.19",
"version": "0.4.0-alpha.20",
"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.4.0-alpha.19",
"version": "0.4.0-alpha.20",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
10 changes: 6 additions & 4 deletions packages/wallets/night-elf/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { INightElfWalletAdapterConfig } from './index';
import { makeError, utils, ERR_CODE } from '@aelf-web-login/wallet-adapter-base';
import { makeError, utils, ERR_CODE, WalletTypeEnum } from '@aelf-web-login/wallet-adapter-base';
import type { AElfDappBridge, PublicKey } from '@aelf-react/types';
import AelfBridgeCheck from './AelfBridgeCheck';
import NightElfCheck from './NightElfCheck';

export const getBridges = async (nodes: INightElfWalletAdapterConfig['nodes'], appName: string) => {
const { isMobileDevices } = utils;
const { isMobileDevices, checkConnectedWallet } = utils;
try {
const isAElfBridge = isMobileDevices() && !(window as any)?.NightElf;
console.log('aelf-wallet-debug----------1');
Expand All @@ -24,7 +24,8 @@ export const getBridges = async (nodes: INightElfWalletAdapterConfig['nodes'], a
const bridges: { [key: string]: AElfDappBridge } = {};
console.log('nodes:', nodes);
if (!nodes || Object.keys(nodes).length === 0) {
throw makeError(ERR_CODE.INIT_BRIDGE_ERROR);
checkConnectedWallet(WalletTypeEnum.elf);
throw makeError(ERR_CODE.NIGHT_ELF_NOT_DETECTED);
}
Object.entries(nodes).forEach(([k, v]) => {
if (!firstKey) firstKey = k;
Expand All @@ -35,7 +36,8 @@ export const getBridges = async (nodes: INightElfWalletAdapterConfig['nodes'], a
const bridge = bridges[firstKey];
return { bridge, node, bridges };
} catch (e) {
throw makeError(ERR_CODE.INIT_BRIDGE_ERROR);
checkConnectedWallet(WalletTypeEnum.elf);
throw makeError(ERR_CODE.NIGHT_ELF_NOT_DETECTED);
}
};

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.4.0-alpha.19",
"version": "0.4.0-alpha.20",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
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.4.0-alpha.19",
"version": "0.4.0-alpha.20",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/portkey-web-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-portkey-web",
"version": "0.4.0-alpha.19",
"version": "0.4.0-alpha.20",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down