@zebec-network/exchange-card-sdk 1.1.10-beta.2 → 1.1.10-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseTransaction, SubmittableTransaction, Transaction, TxResponse } from "xrpl";
|
|
1
|
+
import { BaseTransaction, Client, SubmittableTransaction, Transaction, TxResponse } from "xrpl";
|
|
2
2
|
import { APIConfig } from "../helpers/apiHelpers";
|
|
3
3
|
import { Quote } from "../types";
|
|
4
4
|
export interface XRPLWallet {
|
|
@@ -8,7 +8,7 @@ export interface XRPLWallet {
|
|
|
8
8
|
export declare class XRPLService {
|
|
9
9
|
readonly wallet: XRPLWallet;
|
|
10
10
|
private apiService;
|
|
11
|
-
|
|
11
|
+
readonly client: Client;
|
|
12
12
|
constructor(wallet: XRPLWallet, apiConfig: APIConfig, options?: {
|
|
13
13
|
sandbox?: boolean;
|
|
14
14
|
});
|
|
@@ -37,14 +37,19 @@ export declare class XRPLService {
|
|
|
37
37
|
token: {
|
|
38
38
|
currency: string;
|
|
39
39
|
issuer: string;
|
|
40
|
-
ticker: number;
|
|
41
40
|
};
|
|
42
41
|
}): Promise<TxResponse<Transaction>>;
|
|
43
|
-
|
|
42
|
+
createTrustLine(params: {
|
|
43
|
+
walletAddress?: string;
|
|
44
|
+
amount: string;
|
|
45
|
+
token: {
|
|
46
|
+
currency: string;
|
|
47
|
+
issuer: string;
|
|
48
|
+
};
|
|
49
|
+
}): Promise<TxResponse<Transaction>>;
|
|
44
50
|
getTokenBalances(walletAddress?: string): Promise<{
|
|
45
51
|
value: string;
|
|
46
52
|
currency: string;
|
|
47
53
|
issuer?: string | undefined;
|
|
48
54
|
}[]>;
|
|
49
|
-
getDecimalsOfCurrency(currencyHolder: string, currency: string): Promise<number>;
|
|
50
55
|
}
|
|
@@ -78,16 +78,13 @@ class XRPLService {
|
|
|
78
78
|
if (!(0, xrpl_1.isValidAddress)(destination)) {
|
|
79
79
|
throw new Error("Invalid destination address");
|
|
80
80
|
}
|
|
81
|
-
const amount = BigNumber(params.amount)
|
|
82
|
-
.times(BigNumber(10).pow(params.token.ticker))
|
|
83
|
-
.toFixed(0);
|
|
84
81
|
const transaction = {
|
|
85
82
|
TransactionType: "Payment",
|
|
86
83
|
Account: walletAddress,
|
|
87
84
|
Destination: destination,
|
|
88
85
|
Amount: {
|
|
89
86
|
currency: params.token.currency,
|
|
90
|
-
value: amount,
|
|
87
|
+
value: params.amount,
|
|
91
88
|
issuer: params.token.issuer,
|
|
92
89
|
},
|
|
93
90
|
};
|
|
@@ -105,17 +102,26 @@ class XRPLService {
|
|
|
105
102
|
await this.client.disconnect();
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
|
-
async
|
|
109
|
-
const
|
|
110
|
-
if (!(0, xrpl_1.isValidAddress)(
|
|
105
|
+
async createTrustLine(params) {
|
|
106
|
+
const walletAddress = params.walletAddress ? params.walletAddress : this.wallet.address;
|
|
107
|
+
if (!(0, xrpl_1.isValidAddress)(walletAddress)) {
|
|
111
108
|
throw new Error("Invalid wallet address");
|
|
112
109
|
}
|
|
110
|
+
const transaction = {
|
|
111
|
+
TransactionType: "TrustSet",
|
|
112
|
+
Account: walletAddress,
|
|
113
|
+
LimitAmount: {
|
|
114
|
+
currency: params.token.currency,
|
|
115
|
+
issuer: params.token.issuer,
|
|
116
|
+
value: params.amount,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
113
119
|
await this.client.connect();
|
|
114
120
|
try {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return
|
|
121
|
+
const preparedTx = await this.client.autofill(transaction);
|
|
122
|
+
const signedTx = await this.wallet.signTransaction(preparedTx);
|
|
123
|
+
const response = await this.client.submitAndWait(signedTx);
|
|
124
|
+
return response;
|
|
119
125
|
}
|
|
120
126
|
catch (error) {
|
|
121
127
|
throw error;
|
|
@@ -143,26 +149,5 @@ class XRPLService {
|
|
|
143
149
|
await this.client.disconnect();
|
|
144
150
|
}
|
|
145
151
|
}
|
|
146
|
-
async getDecimalsOfCurrency(currencyHolder, currency) {
|
|
147
|
-
await this.client.connect();
|
|
148
|
-
try {
|
|
149
|
-
const response = await this.client.getBalances(currencyHolder, {
|
|
150
|
-
ledger_index: "validated",
|
|
151
|
-
});
|
|
152
|
-
const row = response.find((l) => l.currency === currency);
|
|
153
|
-
if (!row) {
|
|
154
|
-
throw new Error("Currency not found in holders account");
|
|
155
|
-
}
|
|
156
|
-
// just a work around. change this if found a better way to get decimals
|
|
157
|
-
const splits = row.value.split(".");
|
|
158
|
-
return splits.length === 2 ? splits[1].length : 0; // if it returns zero, then it is a whole number and it's a problem !!!
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
163
|
-
finally {
|
|
164
|
-
await this.client.disconnect();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
152
|
}
|
|
168
153
|
exports.XRPLService = XRPLService;
|