Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Allow arbitrary params for withdraws / deposits (#81)
Browse files Browse the repository at this point in the history
Anchors might ask for various metadata during transfers, so allow them.

Also, only allow snake-cased arguments, and warn if they provide assetCode / destExtra instead.
  • Loading branch information
Morley Zhi authored Jul 17, 2019
1 parent 1b2e928 commit 703d864
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/wallet-sdk",
"version": "0.0.3-rc.11",
"version": "0.0.3-rc.12",
"description": "Libraries to help you write Stellar-enabled wallets in Javascript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
15 changes: 8 additions & 7 deletions src/transfers/DepositProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ import { TransferProvider } from "./TransferProvider";
*/
export class DepositProvider extends TransferProvider {
public async deposit(args: DepositRequest): Promise<TransferResponse> {
const search = queryString.stringify({
asset_code: args.assetCode || args.asset_code,
account: args.account,
memo: args.memo,
email_address: args.emailAddress || args.email_address,
type: args.type,
});
// warn about camel-cased props
if (args.assetCode && !args.asset_code) {
throw new Error(
"You provided `assetCode` instead of the correct `asset_code`",
);
}

const search = queryString.stringify(args);
const response = await fetch(`${this.transferServer}/deposit?${search}`);
const json = (await response.json()) as TransferResponse;

Expand Down
22 changes: 14 additions & 8 deletions src/transfers/WithdrawProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ import { TransferProvider } from "./TransferProvider";
*/
export class WithdrawProvider extends TransferProvider {
public async withdraw(args: WithdrawRequest): Promise<TransferResponse> {
const search = queryString.stringify({
type: args.type,
asset_code: args.assetCode,
dest: args.dest,
dest_extra: args.destExtra,
account: args.account,
memo: args.memo,
});
// warn about camel-cased props
if (args.assetCode && !args.asset_code) {
throw new Error(
"You provided `assetCode` instead of the correct `asset_code`",
);
}
if (args.destExtra && !args.dest_extra) {
throw new Error(
"You provided `destExtra` instead of the correct `dest_extra`",
);
}

const search = queryString.stringify(args);

const response = await fetch(`${this.transferServer}/withdraw?${search}`);
const json = (await response.json()) as TransferResponse;

Expand Down
12 changes: 7 additions & 5 deletions src/types/transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,23 @@ export interface DepositInfo {

export interface WithdrawRequest {
type: string;
assetCode: string;
asset_code: string;
dest: string;
destExtra?: string;
dest_extra: string;
account?: string;
memo?: Memo;
memo_type?: string;
[key: string]: any;
}

export interface DepositRequest {
assetCode?: string;
asset_code?: string;
asset_code: string;
account: string;
memo?: Memo;
emailAddress?: string;
memo_type?: string;
email_address?: string;
type?: string;
[key: string]: any;
}

export interface TransferResponse {
Expand Down

0 comments on commit 703d864

Please sign in to comment.