Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deeplinked wallet methods #594

Merged
merged 2 commits into from
Jul 26, 2023
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
23 changes: 21 additions & 2 deletions packages/@magic-sdk/provider/src/modules/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,27 @@ export class WalletModule extends BaseModule {

/* Prompt Magic's Wallet UI (not available for users logged in with third party wallets) */
public showUI() {
const requestPayload = createJsonRpcRequestPayload(MagicPayloadMethod.ShowUI);
return this.request<boolean>(requestPayload);
return this.request<boolean>(createJsonRpcRequestPayload(MagicPayloadMethod.ShowUI));
}

public showAddress() {
return this.request<boolean>(createJsonRpcRequestPayload(MagicPayloadMethod.ShowAddress));
}

public showSendTokensUI() {
return this.request<boolean>(createJsonRpcRequestPayload(MagicPayloadMethod.ShowSendTokensUI));
}

public showOnRamp() {
return this.request<boolean>(createJsonRpcRequestPayload(MagicPayloadMethod.ShowOnRamp));
}

public showNFTs() {
return this.request<boolean>(createJsonRpcRequestPayload(MagicPayloadMethod.ShowNFTs));
}

public showBalances() {
return this.request<boolean>(createJsonRpcRequestPayload(MagicPayloadMethod.ShowBalances));
}

/* Get user info such as the wallet type they are logged in with */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import browserEnv from '@ikscodes/browser-env';
import { createMagicSDK } from '../../../factories';
import { isPromiEvent } from '../../../../src/util';

beforeEach(() => {
browserEnv.restore();
});

test('Generate JSON RPC request payload with method `magic_show_address`', async () => {
const magic = createMagicSDK();
magic.wallet.request = jest.fn();

magic.wallet.showAddress();

const requestPayload = magic.wallet.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_show_address');
expect(requestPayload.params).toEqual([]);
});

test('method should return a PromiEvent', () => {
const magic = createMagicSDK();
expect(isPromiEvent(magic.wallet.showAddress())).toBeTruthy();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import browserEnv from '@ikscodes/browser-env';
import { createMagicSDK } from '../../../factories';
import { isPromiEvent } from '../../../../src/util';

beforeEach(() => {
browserEnv.restore();
});

test('Generate JSON RPC request payload with method `magic_show_balances`', async () => {
const magic = createMagicSDK();
magic.wallet.request = jest.fn();

magic.wallet.showBalances();

const requestPayload = magic.wallet.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_show_balances');
expect(requestPayload.params).toEqual([]);
});

test('method should return a PromiEvent', () => {
const magic = createMagicSDK();
expect(isPromiEvent(magic.wallet.showBalances())).toBeTruthy();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import browserEnv from '@ikscodes/browser-env';
import { createMagicSDK } from '../../../factories';
import { isPromiEvent } from '../../../../src/util';

beforeEach(() => {
browserEnv.restore();
});

test('Generate JSON RPC request payload with method `magic_show_nfts`', async () => {
const magic = createMagicSDK();
magic.wallet.request = jest.fn();

magic.wallet.showNFTs();

const requestPayload = magic.wallet.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_show_nfts');
expect(requestPayload.params).toEqual([]);
});

test('method should return a PromiEvent', () => {
const magic = createMagicSDK();
expect(isPromiEvent(magic.wallet.showNFTs())).toBeTruthy();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import browserEnv from '@ikscodes/browser-env';
import { createMagicSDK } from '../../../factories';
import { isPromiEvent } from '../../../../src/util';

beforeEach(() => {
browserEnv.restore();
});

test('Generate JSON RPC request payload with method `magic_show_fiat_onramp`', async () => {
const magic = createMagicSDK();
magic.wallet.request = jest.fn();

magic.wallet.showOnRamp();

const requestPayload = magic.wallet.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_show_fiat_onramp');
expect(requestPayload.params).toEqual([]);
});

test('method should return a PromiEvent', () => {
const magic = createMagicSDK();
expect(isPromiEvent(magic.wallet.showOnRamp())).toBeTruthy();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import browserEnv from '@ikscodes/browser-env';
import { createMagicSDK } from '../../../factories';
import { isPromiEvent } from '../../../../src/util';

beforeEach(() => {
browserEnv.restore();
});

test('Generate JSON RPC request payload with method `magic_show_send_tokens_ui`', async () => {
const magic = createMagicSDK();
magic.wallet.request = jest.fn();

magic.wallet.showSendTokensUI();

const requestPayload = magic.wallet.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_show_send_tokens_ui');
expect(requestPayload.params).toEqual([]);
});

test('method should return a PromiEvent', () => {
const magic = createMagicSDK();
expect(isPromiEvent(magic.wallet.showSendTokensUI())).toBeTruthy();
});
5 changes: 5 additions & 0 deletions packages/@magic-sdk/types/src/core/json-rpc-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,9 @@ export enum MagicPayloadMethod {
Login = 'mc_login',
EncryptV1 = 'magic_auth_encrypt_v1',
DecryptV1 = 'magic_auth_decrypt_v1',
ShowNFTs = 'magic_show_nfts',
ShowOnRamp = 'magic_show_fiat_onramp',
ShowSendTokensUI = 'magic_show_send_tokens_ui',
ShowAddress = 'magic_show_address',
ShowBalances = 'magic_show_balances',
}
Loading