Skip to content

Commit 1db170a

Browse files
committed
feat: updates rest wallet management methods
1 parent f2587d4 commit 1db170a

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

lib/client.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export class Client {
9191
*/
9292
async getCurrencies(currencies?: string[], preferred_network?: string): Promise<{ [key: string]: Currency }> {
9393
const response = await this.get("public/currency", { currencies, preferred_network });
94-
console.log(response)
9594
return response
9695
}
9796

@@ -799,9 +798,9 @@ export class Client {
799798
/**
800799
* Get the current addresses of the user
801800
*
802-
* Requires the "Payment information" API key Access Right.
801+
* Requires the "Payment information" API key AccesrkRight.
803802
*
804-
* https://api.exchange.cryptomkt.com/#deposit-crypto-address
803+
*, network_code https://api.exchange.cryptomkt.com/#deposit-crypto-address
805804
*
806805
* @return A list of currency addresses
807806
*/
@@ -859,11 +858,12 @@ export class Client {
859858
* https://api.exchange.cryptomkt.com/#last-10-deposit-crypto-address
860859
*
861860
* @param {string} currency currency to get the list of addresses
861+
* @param {string} [network_code] Optional. network code
862862
*
863863
* @return A list of addresses
864864
*/
865-
getLast10DepositCryptoAddresses(currency: string): Promise<Address[]> {
866-
return this.get(`wallet/crypto/address/recent-deposit`, { currency });
865+
getLast10DepositCryptoAddresses(currency: string, network_code?: string): Promise<Address[]> {
866+
return this.get(`wallet/crypto/address/recent-deposit`, { currency, network_code });
867867
}
868868

869869
/**
@@ -876,11 +876,12 @@ export class Client {
876876
* https://api.exchange.cryptomkt.com/#last-10-withdrawal-crypto-addresses
877877
*
878878
* @param {string} currency currency to get the list of addresses
879+
* @param {string} [network_code] Optional. network code
879880
*
880881
* @return A list of addresses
881882
*/
882-
getLast10WithdrawalCryptoAddresses(currency: string): Promise<Address[]> {
883-
return this.get(`wallet/crypto/address/recent-withdraw`, { currency });
883+
getLast10WithdrawalCryptoAddresses(currency: string, network_code?: string): Promise<Address[]> {
884+
return this.get(`wallet/crypto/address/recent-withdraw`, { currency, network_code });
884885
}
885886

886887
/**
@@ -903,6 +904,7 @@ export class Client {
903904
* @param {string} params.currency currency code of the crypto to withdraw
904905
* @param {string} params.amount the amount to be sent to the specified address
905906
* @param {string} params.address the address identifier
907+
* @param {string} [params.network_code] Optional. network code
906908
* @param {string} [params.payment_id] Optional.
907909
* @param {boolean} [params.include_fee] Optional. If true then the total spent amount includes fees. Default false
908910
* @param {boolean} [params.auto_commit] Optional. If false then you should commit or rollback transaction in an hour. Used in two phase commit schema. Default true
@@ -916,6 +918,7 @@ Accepted values: never, optionally, required
916918
currency: string;
917919
amount: string;
918920
address: string;
921+
network_code?: string
919922
paymend_id?: string;
920923
include_fee?: boolean;
921924
auto_commit?: boolean;
@@ -1112,6 +1115,8 @@ Accepted values: wallet, spot. Must not be the same as source
11121115
* @param {TRANSACTION_TYPE[]} [params.types] Optional. List of types to query. valid types are: 'DEPOSIT', 'WITHDRAW', 'TRANSFER' and 'SWAP'
11131116
* @param {TRANSACTION_SUBTYPE[]} [params.subtypes] Optional. List of subtypes to query. valid subtypes are: 'UNCLASSIFIED', 'BLOCKCHAIN', 'AIRDROP', 'AFFILIATE', 'STAKING', 'BUY_CRYPTO', 'OFFCHAIN', 'FIAT', 'SUB_ACCOUNT', 'WALLET_TO_SPOT', 'SPOT_TO_WALLET', 'WALLET_TO_DERIVATIVES', 'DERIVATIVES_TO_WALLET', 'CHAIN_SWITCH_FROM', 'CHAIN_SWITCH_TO' and 'INSTANT_EXCHANGE'
11141117
* @param {TRANSACTION_STATUS[]} [params.statuses] Optional. List of statuses to query. valid subtypes are: 'CREATED', 'PENDING', 'FAILED', 'SUCCESS' and 'ROLLED_BACK'
1118+
* @param {string[]} [params.currencies] Optional. List of currencies of the transactions
1119+
* @param {string[]} [params.networks] Optional. List of network codes
11151120
* @param {SORT_BY} [params.order_by] Optional. Defines the sorting type.'created_at' or 'id'. Default is 'created_at'
11161121
* @param {string} [params.from] Optional. Interval initial value when ordering by 'created_at'. As Datetime
11171122
* @param {string} [params.till] Optional. Interval end value when ordering by 'created_at'. As Datetime
@@ -1120,6 +1125,7 @@ Accepted values: wallet, spot. Must not be the same as source
11201125
* @param {string} [params.sort] Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'.
11211126
* @param {number} [params.limit] Optional. Transactions per query. Defaul is 100. Max is 1000
11221127
* @param {number} [params.offset] Optional. Default is 0. Max is 100000
1128+
* @param {Boolean} [params.group_transactions] Optional. Flag indicating whether the returned transactions will be parts of a single operation
11231129
*
11241130
* @return A list of transactions
11251131
*/
@@ -1128,14 +1134,17 @@ Accepted values: wallet, spot. Must not be the same as source
11281134
types?: TRANSACTION_TYPE[];
11291135
subtypes?: TRANSACTION_SUBTYPE[];
11301136
statuses?: TRANSACTION_STATUS[];
1131-
order_by: SORT_BY;
1132-
from: string;
1137+
currencies?: string[],
1138+
networks?: string[],
1139+
order_by?: SORT_BY;
1140+
from?: string;
11331141
till?: string;
11341142
id_from?: string;
11351143
id_till?: string;
11361144
sort?: string;
11371145
limit?: number;
11381146
offset?: number;
1147+
group_transactions?:Boolean
11391148
}): Promise<Transaction[]> {
11401149
return this.get("wallet/transactions", params);
11411150
}

lib/models/Transactions.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ export interface Transaction {
77
created_at: string;
88
updated_at: string;
99
native: NativeTransaction;
10-
primetrust: any;
11-
meta: MetaTransaction;
10+
commit_risk: CommitRisk;
1211
}
1312

1413
export interface NativeTransaction {
1514
tx_id: string;
15+
wallet_id: string;
1616
index: number;
1717
currency: string;
1818
amount: number;
@@ -23,23 +23,13 @@ export interface NativeTransaction {
2323
offchain_id: string;
2424
confirmations: number;
2525
public_comment: string;
26+
error_code: string;
2627
senders: string[];
28+
operation_type: string;
2729
}
2830

29-
export interface MetaTransaction {
30-
fiat_to_crypto: JSON;
31-
id: number;
32-
provider_name: string;
33-
order_type: string;
34-
source_currency: string;
35-
target_currency: string;
36-
wallet_address: string;
37-
tx_hash: string;
38-
target_amount: string;
39-
source_amount: string;
40-
status: string;
41-
created_at: string;
42-
updated_at: string;
43-
deleted_at: string;
44-
payment_method_type: string;
31+
export interface CommitRisk {
32+
score: number;
33+
rbf: Boolean;
34+
low_fee: Boolean;
4535
}

test/rest/wallet_management.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ describe("wallet management", () => {
4646
describe("Get deposit crypto address of symbol", () => {
4747
it("", async function () {
4848
this.timeout(0);
49-
let address = await client.getDepositCryptoAddressOfCurrency("EOS");
49+
let address = await client.getDepositCryptoAddress("EOS");
5050
assert(goodAddress(address), "not good address");
5151
});
5252
});
5353
describe("create deposit crypto address", () => {
5454
it("", async function () {
5555
this.timeout(0);
56-
let oldAddress = await client.getDepositCryptoAddressOfCurrency("EOS");
56+
let oldAddress = await client.getDepositCryptoAddress("EOS");
5757
let newAddres = await client.createDepositCryptoAddress("EOS");
5858
assert(oldAddress.address !== newAddres.address, "not a new address");
5959
assert(goodAddress(newAddres), "not good address");
@@ -78,7 +78,7 @@ describe("wallet management", () => {
7878
describe("withdraw crypto and commitment/rollback", () => {
7979
it("exception amount too low", async function () {
8080
this.timeout(0);
81-
let adaAddress = await client.getDepositCryptoAddressOfCurrency("ADA");
81+
let adaAddress = await client.getDepositCryptoAddress("ADA");
8282
try {
8383
let transactionID = await client.withdrawCrypto({
8484
currency: "ADA",
@@ -94,7 +94,7 @@ describe("wallet management", () => {
9494
});
9595
it("with auto commit (default mode)", async function () {
9696
this.timeout(0);
97-
let adaAddress = await client.getDepositCryptoAddressOfCurrency("ADA");
97+
let adaAddress = await client.getDepositCryptoAddress("ADA");
9898
let transactionID = await client.withdrawCrypto({
9999
currency: "ADA",
100100
amount: "0.1",
@@ -104,7 +104,7 @@ describe("wallet management", () => {
104104
});
105105
it("with commit", async function () {
106106
this.timeout(0);
107-
let adaAddress = await client.getDepositCryptoAddressOfCurrency("ADA");
107+
let adaAddress = await client.getDepositCryptoAddress("ADA");
108108
let transactionID = await client.withdrawCrypto({
109109
currency: "ADA",
110110
amount: "0.1",
@@ -117,7 +117,7 @@ describe("wallet management", () => {
117117
});
118118
it("with rollback", async function () {
119119
this.timeout(0);
120-
let adaAddress = await client.getDepositCryptoAddressOfCurrency("ADA");
120+
let adaAddress = await client.getDepositCryptoAddress("ADA");
121121
let transactionID = await client.withdrawCrypto({
122122
currency: "ADA",
123123
amount: "0.1",
@@ -152,15 +152,15 @@ describe("wallet management", () => {
152152
describe("check if crypto address belongs to current account", () => {
153153
it("cro belongs", async function () {
154154
this.timeout(0);
155-
let croAddress = await client.getDepositCryptoAddressOfCurrency("CRO");
155+
let croAddress = await client.getDepositCryptoAddress("CRO");
156156
let result = await client.checkIfCryptoAddressBelongsToCurrentAccount(
157157
croAddress.address
158158
);
159159
assert(result === true, "does not belong");
160160
});
161161
it.skip("eos belongs", async function () {
162162
this.timeout(0);
163-
let eosAddress = await client.getDepositCryptoAddressOfCurrency("EOS");
163+
let eosAddress = await client.getDepositCryptoAddress("EOS");
164164
let result = await client.checkIfCryptoAddressBelongsToCurrentAccount(
165165
eosAddress.address
166166
);
@@ -208,7 +208,7 @@ describe("wallet management", () => {
208208
describe("get transaction history", () => {
209209
it("", async function () {
210210
this.timeout(0);
211-
let transactions = await client.getTransactionHistory();
211+
let transactions = await client.getTransactionHistory({ currencies: ["CRO", "ETH"] });
212212
assert(goodList(goodTransaction, transactions), "not good transaction");
213213
});
214214
});
@@ -221,7 +221,7 @@ describe("wallet management", () => {
221221
describe("check if offchain is available", () => {
222222
it("", async function () {
223223
this.timeout(0);
224-
let myEOSAddress = await client.getDepositCryptoAddressOfCurrency("EOS");
224+
let myEOSAddress = await client.getDepositCryptoAddress("EOS");
225225
let result = await client.checkIfOffchainIsAvailable({
226226
currency: "EOS",
227227
address: myEOSAddress.address,

0 commit comments

Comments
 (0)