Skip to content

Commit 71db32f

Browse files
authored
Merge pull request #221 from AElfProject/fix/mobile-login
fix: mobile login issue
2 parents 1aacf3b + c4f652f commit 71db32f

File tree

23 files changed

+844
-247
lines changed

23 files changed

+844
-247
lines changed

.github/workflows/coverage.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
strategy:
1717
matrix:
1818
package: [utils, base, react, bridge]
19+
env:
20+
NODE_OPTIONS: "--max-old-space-size=4096"
1921

2022
steps:
2123
- name: Checkout repository
@@ -24,11 +26,21 @@ jobs:
2426
- name: Set up Node.js
2527
uses: actions/setup-node@v3
2628
with:
27-
node-version: '20'
29+
node-version: '22'
2830

2931
- name: Install pnpm
3032
run: npm install -g pnpm
3133

34+
- name: Cache dependencies
35+
uses: actions/cache@v3
36+
with:
37+
path: |
38+
**/node_modules
39+
~/.pnpm-store
40+
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
41+
restore-keys: |
42+
${{ runner.os }}-pnpm-
43+
3244
- name: Install dependencies
3345
run: pnpm install --no-frozen-lockfile
3446

@@ -52,7 +64,7 @@ jobs:
5264
output: packages/${{ matrix.package }}/coverage/badge.svg
5365

5466
- name: Upload coverage report to artifact
55-
uses: actions/upload-artifact@v3
67+
uses: actions/upload-artifact@v4
5668
with:
5769
name: coverage-${{ matrix.package }}
5870
path: packages/${{ matrix.package }}/coverage
@@ -66,7 +78,7 @@ jobs:
6678
uses: actions/checkout@v3
6779

6880
- name: Download coverage artifacts
69-
uses: actions/download-artifact@v3
81+
uses: actions/download-artifact@v4
7082
with:
7183
path: coverage
7284

.github/workflows/test-badge.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ jobs:
1818
strategy:
1919
matrix:
2020
package: [utils, base, react, bridge]
21+
env:
22+
NODE_OPTIONS: "--max-old-space-size=4096"
2123
steps:
2224
- name: Run frontend CI
23-
uses: AElfProject/[email protected].2
25+
uses: AElfProject/[email protected].3
2426
with:
2527
commit-token: ${{ secrets.COMMIT_TOKEN }}
2628
branch-name: "feature/badge-json"
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { initBridge } from '../index';
3+
import { Bridge } from '../bridge';
4+
import { store } from '../store';
5+
import { NetworkEnum, SignInDesignEnum, TChainId } from '@aelf-web-login/wallet-adapter-base';
6+
import { ThemeType } from '@portkey/connect-web-wallet';
7+
8+
// Mock Bridge class
9+
vi.mock('../bridge', () => ({
10+
Bridge: vi.fn().mockImplementation(() => ({
11+
_wallets: [],
12+
_sideChainId: 'tDVV',
13+
theme: 'dark',
14+
_activeWallet: undefined,
15+
})),
16+
}));
17+
18+
// Mock store
19+
vi.mock('../store', () => ({
20+
store: {
21+
dispatch: vi.fn(),
22+
getState: vi.fn(),
23+
subscribe: vi.fn(),
24+
},
25+
}));
26+
27+
describe('initBridge', () => {
28+
const mockWallets = [
29+
{
30+
name: 'Portkey Web Wallet',
31+
icon: 'icon1',
32+
loginState: 'unlocked',
33+
wallet: {},
34+
loginEagerly: vi.fn(),
35+
login: vi.fn(),
36+
logout: vi.fn(),
37+
connect: vi.fn(),
38+
disconnect: vi.fn(),
39+
signMessage: vi.fn(),
40+
signTransaction: vi.fn(),
41+
sendTransaction: vi.fn(),
42+
goAssets: vi.fn(),
43+
},
44+
{
45+
name: 'Portkey Discover',
46+
icon: 'icon2',
47+
loginState: 'unlocked',
48+
wallet: {},
49+
loginEagerly: vi.fn(),
50+
login: vi.fn(),
51+
logout: vi.fn(),
52+
connect: vi.fn(),
53+
disconnect: vi.fn(),
54+
signMessage: vi.fn(),
55+
signTransaction: vi.fn(),
56+
sendTransaction: vi.fn(),
57+
goAssets: vi.fn(),
58+
},
59+
] as any;
60+
61+
const mockBaseConfig = {
62+
networkType: NetworkEnum.MAINNET,
63+
appName: 'Test App',
64+
chainId: 'AELF' as TChainId,
65+
sideChainId: 'tDVV' as TChainId,
66+
design: SignInDesignEnum.CryptoDesign,
67+
theme: 'dark' as ThemeType,
68+
showVconsole: false,
69+
omitTelegramScript: false,
70+
enableAcceleration: true,
71+
};
72+
73+
const mockConfig = {
74+
baseConfig: mockBaseConfig,
75+
wallets: mockWallets,
76+
};
77+
78+
beforeEach(() => {
79+
vi.clearAllMocks();
80+
});
81+
82+
it('should initialize bridge with correct configuration', () => {
83+
const result = initBridge(mockConfig);
84+
85+
expect(Bridge).toHaveBeenCalledWith(mockWallets, mockBaseConfig);
86+
expect(result).toEqual({
87+
instance: expect.any(Object),
88+
store: store,
89+
});
90+
});
91+
92+
it('should initialize bridge with minimal configuration', () => {
93+
const minimalConfig = {
94+
baseConfig: {
95+
networkType: NetworkEnum.MAINNET,
96+
appName: 'Test App',
97+
chainId: 'AELF' as TChainId,
98+
sideChainId: 'tDVV' as TChainId,
99+
},
100+
wallets: mockWallets,
101+
};
102+
103+
const result = initBridge(minimalConfig);
104+
105+
expect(Bridge).toHaveBeenCalledWith(mockWallets, minimalConfig.baseConfig);
106+
expect(result).toEqual({
107+
instance: expect.any(Object),
108+
store: store,
109+
});
110+
});
111+
112+
it('should initialize bridge with all optional parameters', () => {
113+
const fullConfig = {
114+
baseConfig: {
115+
...mockBaseConfig,
116+
loginConfig: {
117+
loginMethods: ['Email', 'Phone'],
118+
} as any,
119+
showVconsole: true,
120+
omitTelegramScript: true,
121+
enableAcceleration: false,
122+
},
123+
wallets: mockWallets,
124+
};
125+
126+
const result = initBridge(fullConfig);
127+
128+
expect(Bridge).toHaveBeenCalledWith(mockWallets, fullConfig.baseConfig);
129+
expect(result).toEqual({
130+
instance: expect.any(Object),
131+
store: store,
132+
});
133+
});
134+
135+
it('should handle empty wallets array', () => {
136+
const configWithEmptyWallets = {
137+
baseConfig: mockBaseConfig,
138+
wallets: [],
139+
};
140+
141+
const result = initBridge(configWithEmptyWallets);
142+
143+
expect(Bridge).toHaveBeenCalledWith([], mockBaseConfig);
144+
expect(result).toEqual({
145+
instance: expect.any(Object),
146+
store: store,
147+
});
148+
});
149+
150+
it('should handle different network types', () => {
151+
const testnetConfig = {
152+
baseConfig: {
153+
...mockBaseConfig,
154+
networkType: NetworkEnum.TESTNET,
155+
},
156+
wallets: mockWallets,
157+
};
158+
159+
const result = initBridge(testnetConfig);
160+
161+
expect(Bridge).toHaveBeenCalledWith(mockWallets, testnetConfig.baseConfig);
162+
expect(result).toEqual({
163+
instance: expect.any(Object),
164+
store: store,
165+
});
166+
});
167+
168+
it('should handle different themes', () => {
169+
const lightThemeConfig = {
170+
baseConfig: {
171+
...mockBaseConfig,
172+
theme: 'light' as ThemeType,
173+
},
174+
wallets: mockWallets,
175+
};
176+
177+
const result = initBridge(lightThemeConfig);
178+
179+
expect(Bridge).toHaveBeenCalledWith(mockWallets, lightThemeConfig.baseConfig);
180+
expect(result).toEqual({
181+
instance: expect.any(Object),
182+
store: store,
183+
});
184+
});
185+
186+
it('should handle different sign-in designs', () => {
187+
const popupDesignConfig = {
188+
baseConfig: {
189+
...mockBaseConfig,
190+
design: SignInDesignEnum.Web2Design,
191+
},
192+
wallets: mockWallets,
193+
};
194+
195+
const result = initBridge(popupDesignConfig);
196+
197+
expect(Bridge).toHaveBeenCalledWith(mockWallets, popupDesignConfig.baseConfig);
198+
expect(result).toEqual({
199+
instance: expect.any(Object),
200+
store: store,
201+
});
202+
});
203+
204+
it('should return correct interface structure', () => {
205+
const result = initBridge(mockConfig);
206+
207+
expect(result).toHaveProperty('instance');
208+
expect(result).toHaveProperty('store');
209+
expect(typeof result.instance).toBe('object');
210+
expect(result.store).toBe(store);
211+
});
212+
213+
it('should handle console.log call', () => {
214+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
215+
216+
initBridge(mockConfig);
217+
218+
expect(consoleSpy).toHaveBeenCalledWith('init bridge');
219+
220+
consoleSpy.mockRestore();
221+
});
222+
});

0 commit comments

Comments
 (0)