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

add nft airdrop method #452

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion packages/@magic-sdk/provider/src/modules/nft.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MagicPayloadMethod, NFTCheckoutResponse } from '@magic-sdk/types';
import { MagicPayloadMethod, NFTAirdropParams, NFTCheckoutResponse } from '@magic-sdk/types';
import { BaseModule } from './base-module';
import { createJsonRpcRequestPayload } from '../core/json-rpc';

Expand All @@ -8,4 +8,9 @@ export class NFTModule extends BaseModule {
const requestPayload = createJsonRpcRequestPayload(MagicPayloadMethod.NFTCheckout);
return this.request<NFTCheckoutResponse>(requestPayload);
}

public airdrop(params: NFTAirdropParams) {
const requestPayload = createJsonRpcRequestPayload(MagicPayloadMethod.NFTAirdrop, [params]);
return this.request<boolean>(requestPayload);
}
}
23 changes: 23 additions & 0 deletions packages/@magic-sdk/provider/test/spec/modules/nft/airdrop.spec.ts
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_nft_airdrop`', async () => {
const magic = createMagicSDK();
magic.nft.request = jest.fn();

magic.nft.airdrop();

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

test('method should return a PromiEvent', () => {
const magic = createMagicSDK();
expect(isPromiEvent(magic.nft.airdrop())).toBeTruthy();
});
29 changes: 29 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 @@ -79,6 +79,34 @@ export interface NFTCheckoutResponse {
status: NFTCheckoutStatus;
}

export interface NFTAirdropParams {
contractAddress?: string;
walletAddress?: string;
email?: string;
quantity?: number;
contractArgs?: any;
mintMethod?: {
name?: string;
args?: {
to?: string;
quantity?: string;
};
payment?: {
value?: string;
currency?: string;
spender?: string;
};
};
eligibilityMethod?: {
name?: string;
args?: {
to?: string;
quantity?: string;
};
};
metadata?: any;
}

// --- Payload methods

/**
Expand Down Expand Up @@ -113,6 +141,7 @@ export enum MagicPayloadMethod {
GetInfo = 'mc_get_wallet_info',
ShowUI = 'mc_wallet',
NFTCheckout = 'magic_nft_checkout',
NFTAirdrop = 'magic_nft_airdrop',
RequestUserInfoWithUI = 'mc_request_user_info',
Disconnect = 'mc_disconnect',
}