Skip to content

Commit

Permalink
TP-2952: Enable session activity check for existing users via game-br…
Browse files Browse the repository at this point in the history
…idge
  • Loading branch information
keithbro-imx committed Sep 24, 2024
1 parent 4f05d8b commit 8be1656
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
39 changes: 39 additions & 0 deletions packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,45 @@ describe('ZkEvmProvider', () => {
});
});

it('should emit accountsRequested event when the user is not authenticated', async () => {
authManager.getUser.mockResolvedValue(Promise.resolve(null));

authManager.getUserOrLogin.mockResolvedValue(mockUserZkEvm);
const provider = getProvider();
const onAccountsRequested = jest.fn();

passportEventEmitter.on(PassportEvents.ACCOUNTS_REQUESTED, onAccountsRequested);

const accounts = await provider.request({ method: 'eth_requestAccounts' });

expect(accounts).toEqual([mockUserZkEvm.zkEvm.ethAddress]);
expect(onAccountsRequested).toHaveBeenCalledWith({
environment: 'sandbox',
passportClient: 'client123',
sendTransaction: expect.any(Function),
walletAddress: '0x0000000000000000000000000000000000000001',
});
});

it('should emit accountsRequested event when the user is already authenticated', async () => {
authManager.getUser.mockResolvedValue(mockUserZkEvm);

const provider = getProvider();
const onAccountsRequested = jest.fn();

passportEventEmitter.on(PassportEvents.ACCOUNTS_REQUESTED, onAccountsRequested);

const accounts = await provider.request({ method: 'eth_requestAccounts' });

expect(accounts).toEqual([mockUserZkEvm.zkEvm.ethAddress]);
expect(onAccountsRequested).toHaveBeenCalledWith({
environment: 'sandbox',
passportClient: 'client123',
sendTransaction: expect.any(Function),
walletAddress: '0x0000000000000000000000000000000000000001',
});
});

it('should throw an error if the signer initialisation fails', async () => {
authManager.getUserOrLogin.mockReturnValue(mockUserZkEvm);
authManager.getUser.mockReturnValue(Promise.resolve(mockUserZkEvm));
Expand Down
5 changes: 4 additions & 1 deletion packages/passport/sdk/src/zkEvm/zkEvmProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ export class ZkEvmProvider implements Provider {
switch (request.method) {
case 'eth_requestAccounts': {
const zkEvmAddress = await this.#getZkEvmAddress();
if (zkEvmAddress) return [zkEvmAddress];
if (zkEvmAddress) {
this.#callSessionActivity(zkEvmAddress);
return [zkEvmAddress];
}

const flow = trackFlow('passport', 'ethRequestAccounts');

Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34907,7 +34907,7 @@ __metadata:
resolution: "seaport-core@https://github.com/immutable/seaport-core.git#commit=0633350ec34f21fcede657ff812f11cf7d19144e"
dependencies:
seaport-types: ^0.0.1
checksum: 392bce86bbfc4f7c00b65575b238825f4c696bddf5af08be7aa496862e63879375387fd4400f6e900ffee08d65c1f75cf3adad9c6c41ddcf7a3b0389cd73c3c7
checksum: d8adba0d54106c6fe9370f0775fadef2198e5eab440b36919d1f917705ce2f0a7028e4da021b6df049aa3ca35d7e673a28b78a731130f0ff9fdf7a8bd32e3b94
languageName: node
linkType: hard

Expand Down Expand Up @@ -34951,7 +34951,7 @@ __metadata:
seaport-sol: ^1.5.0
seaport-types: ^0.0.1
solady: ^0.0.84
checksum: f31a7443a50fa1c35ec03ea031743d1d10896653ae443fa15ab8e6f5b4a2ca43f6743d523ae4e1f14df867451e5b2b2130b0bfa58a1085b0bcae3fceb8dfdc9b
checksum: a77e141e4ab5d2c4bb190a38fbb6cda3011fdf5f350b250fbeb4d82ae81cf917a966a2dcb8d9e4fd1bed29e5510ede9b15941b0ac77aeb4272dab94c9f51e7ff
languageName: node
linkType: hard

Expand Down

0 comments on commit 8be1656

Please sign in to comment.