@stellar/typescript-wallet-sdk 1.1.0-alpha.2 → 1.1.0
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.
- package/.husky/pre-commit +4 -0
- package/docs/WalletGuide.md +5 -0
- package/lib/bundle.js +30068 -4748
- package/lib/bundle.js.map +1 -1
- package/lib/index.d.ts +26 -7
- package/lib/walletSdk/Asset/index.d.ts +27 -0
- package/lib/walletSdk/Exceptions/index.d.ts +56 -0
- package/lib/walletSdk/Types/anchor.d.ts +148 -0
- package/lib/walletSdk/Types/auth.d.ts +35 -0
- package/lib/walletSdk/Types/horizon.d.ts +34 -0
- package/lib/walletSdk/Types/index.d.ts +30 -0
- package/lib/walletSdk/Types/sep24.d.ts +30 -0
- package/lib/walletSdk/Types/utils.d.ts +77 -0
- package/lib/walletSdk/Types/watcher.d.ts +30 -0
- package/lib/walletSdk/Utils/camelToSnakeCase.d.ts +2 -0
- package/lib/walletSdk/Utils/getResultCode.d.ts +1 -0
- package/lib/walletSdk/Utils/index.d.ts +3 -0
- package/lib/walletSdk/Utils/toml.d.ts +3 -0
- package/lib/walletSdk/Utils/url.d.ts +1 -0
- package/lib/walletSdk/Watcher/index.d.ts +21 -42
- package/lib/walletSdk/anchor/Sep24.d.ts +48 -0
- package/lib/walletSdk/anchor/index.d.ts +12 -75
- package/lib/walletSdk/auth/WalletSigner.d.ts +4 -3
- package/lib/walletSdk/auth/index.d.ts +14 -5
- package/lib/walletSdk/horizon/Account.d.ts +3 -6
- package/lib/walletSdk/horizon/AccountService.d.ts +46 -1
- package/lib/walletSdk/horizon/Stellar.d.ts +10 -1
- package/lib/walletSdk/horizon/index.d.ts +4 -0
- package/lib/walletSdk/horizon/transaction/TransactionBuilder.d.ts +20 -0
- package/lib/walletSdk/index.d.ts +17 -15
- package/lib/walletSdk/interactive/index.d.ts +3 -14
- package/lib/walletSdk/recovery/index.d.ts +18 -0
- package/package.json +7 -1
- package/prettier.config.js +1 -0
- package/src/index.ts +39 -17
- package/src/walletSdk/Anchor/Sep24.ts +267 -0
- package/src/walletSdk/Anchor/index.ts +32 -201
- package/src/walletSdk/Asset/index.ts +58 -0
- package/src/walletSdk/Auth/WalletSigner.ts +23 -12
- package/src/walletSdk/Auth/index.ts +96 -49
- package/src/walletSdk/Exceptions/index.ts +148 -0
- package/src/walletSdk/{horizon → Horizon}/Account.ts +7 -9
- package/src/walletSdk/Horizon/AccountService.ts +96 -0
- package/src/walletSdk/Horizon/Stellar.ts +164 -0
- package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +140 -0
- package/src/walletSdk/Horizon/index.ts +4 -0
- package/src/walletSdk/Recovery/index.ts +32 -0
- package/src/walletSdk/{Watcher/Types.ts → Types/anchor.ts} +114 -21
- package/src/walletSdk/Types/auth.ts +43 -0
- package/src/walletSdk/Types/horizon.ts +40 -0
- package/src/walletSdk/Types/index.ts +39 -0
- package/src/walletSdk/Types/sep24.ts +41 -0
- package/src/walletSdk/Types/utils.ts +77 -0
- package/src/walletSdk/Types/watcher.ts +34 -0
- package/src/walletSdk/Utils/camelToSnakeCase.ts +16 -0
- package/src/walletSdk/Utils/getResultCode.ts +5 -0
- package/src/walletSdk/Utils/index.ts +3 -0
- package/src/walletSdk/Utils/toml.ts +103 -0
- package/src/walletSdk/{util → Utils}/url.ts +1 -1
- package/src/walletSdk/Watcher/index.ts +137 -128
- package/src/walletSdk/index.ts +72 -55
- package/test/account.test.ts +19 -15
- package/test/accountService.test.ts +109 -0
- package/test/fixtures/TransactionsResponse.ts +144 -127
- package/test/stellar.test.ts +247 -0
- package/test/wallet.test.ts +196 -214
- package/tsconfig.json +3 -7
- package/webpack.config.js +2 -0
- package/lib/walletSdk/anchor/Types.d.ts +0 -75
- package/lib/walletSdk/util/sleep.d.ts +0 -1
- package/src/walletSdk/Anchor/Types.ts +0 -83
- package/src/walletSdk/exception/index.ts +0 -48
- package/src/walletSdk/horizon/AccountService.ts +0 -19
- package/src/walletSdk/horizon/Stellar.ts +0 -14
- package/src/walletSdk/horizon/constants.ts +0 -4
- package/src/walletSdk/interactive/index.ts +0 -105
- package/src/walletSdk/recovery/Recovery.ts +0 -6
- package/src/walletSdk/toml/index.ts +0 -179
- package/src/walletSdk/util/camelToSnakeCase.ts +0 -13
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { StellarTomlResolver } from "stellar-sdk";
|
|
2
|
+
|
|
3
|
+
import { TomlInfo } from "../Types";
|
|
4
|
+
|
|
5
|
+
export const parseToml = (toml: StellarTomlResolver.StellarToml): TomlInfo => {
|
|
6
|
+
const tomlDocumentation = toml["DOCUMENTATION"];
|
|
7
|
+
const documentation = {
|
|
8
|
+
orgName: tomlDocumentation["ORG_NAME"],
|
|
9
|
+
orgDba: tomlDocumentation["ORG_DBA"],
|
|
10
|
+
orgUrl: tomlDocumentation["ORG_URL"],
|
|
11
|
+
orgLogo: tomlDocumentation["ORG_LOGO"],
|
|
12
|
+
orgDescription: tomlDocumentation["ORG_DESCRIPTION"],
|
|
13
|
+
orgPhysicalAddress: tomlDocumentation["ORG_PHYSICAL_ADDRESS"],
|
|
14
|
+
orgPhysicalAddressAttestation:
|
|
15
|
+
tomlDocumentation["ORG_PHYSICAL_ADDRESS_ATTESTATION"],
|
|
16
|
+
orgPhoneNumber: tomlDocumentation["ORG_PHONE_NUMBER"],
|
|
17
|
+
orgPhoneNumberAttestation:
|
|
18
|
+
tomlDocumentation["ORG_PHONE_NUMBER_ATTESTATION"],
|
|
19
|
+
orgKeybase: tomlDocumentation["ORG_KEYBASE"],
|
|
20
|
+
orgTwitter: tomlDocumentation["ORG_TWITTER"],
|
|
21
|
+
orgGithub: tomlDocumentation["ORG_GITHUB"],
|
|
22
|
+
orgOfficialEmail: tomlDocumentation["ORG_OFFICIAL_EMAIL"],
|
|
23
|
+
orgSupportEmail: tomlDocumentation["ORG_SUPPORT_EMAIL"],
|
|
24
|
+
orgLicensingAuthority: tomlDocumentation["ORG_LICENSING_AUTHORITY"],
|
|
25
|
+
orgLicenseType: tomlDocumentation["ORG_LICENSE_TYPE"],
|
|
26
|
+
orgLicenseNumber: tomlDocumentation["ORG_LICENSE_NUMBER"],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const tomlPrincipals = toml["PRINCIPALS"] || [];
|
|
30
|
+
const principals = tomlPrincipals.map((tp) => {
|
|
31
|
+
return {
|
|
32
|
+
name: tp["name"],
|
|
33
|
+
email: tp["email"],
|
|
34
|
+
keybase: tp["keybase"],
|
|
35
|
+
telegram: tp["telegram"],
|
|
36
|
+
twitter: tp["twitter"],
|
|
37
|
+
github: tp["github"],
|
|
38
|
+
idPhotoHash: tp["id_photo_hash"],
|
|
39
|
+
verificationPhotoHash: tp["verification_photo_hash"],
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const tomlCurrencies = toml["CURRENCIES"] || [];
|
|
44
|
+
const currencies = tomlCurrencies.map((tc) => {
|
|
45
|
+
return {
|
|
46
|
+
code: tc["code"],
|
|
47
|
+
codeTemplate: tc["code_template"],
|
|
48
|
+
issuer: tc["issuer"],
|
|
49
|
+
status: tc["status"],
|
|
50
|
+
displayDecimals: tc["display_decimals"],
|
|
51
|
+
name: tc["name"],
|
|
52
|
+
desc: tc["desc"],
|
|
53
|
+
conditions: tc["conditions"],
|
|
54
|
+
image: tc["image"],
|
|
55
|
+
fixedNumber: tc["fixed_number"],
|
|
56
|
+
maxNumber: tc["max_number"],
|
|
57
|
+
isUnlimited: tc["is_unlimited"],
|
|
58
|
+
isAssetAnchored: tc["is_asset_anchored"],
|
|
59
|
+
anchorAssetType: tc["anchor_asset_type"],
|
|
60
|
+
anchorAsset: tc["anchor_asset"],
|
|
61
|
+
attestationOfReserve: tc["attestation_of_reserve"],
|
|
62
|
+
redemptionInstructions: tc["redemption_instructions"],
|
|
63
|
+
collateralAddresses: tc["collateral_addresses"],
|
|
64
|
+
collateralAddressMessages: tc["collateral_address_messages"],
|
|
65
|
+
collateralAddressSignatures: tc["collateral_address_signatures"],
|
|
66
|
+
regulated: tc["regulated"],
|
|
67
|
+
approvalServer: tc["approval_server"],
|
|
68
|
+
approvalCriteria: tc["approval_criteria"],
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const tomlValidators = toml["VALIDATORS"] || [];
|
|
73
|
+
const validators = tomlValidators.map((tv) => {
|
|
74
|
+
return {
|
|
75
|
+
alias: tv["ALIAS"],
|
|
76
|
+
displayName: tv["DISPLAY_NAME"],
|
|
77
|
+
publicKey: tv["PUBLIC_KEY"],
|
|
78
|
+
host: tv["HOST"],
|
|
79
|
+
history: tv["HISTORY"],
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
version: toml["VERSION"],
|
|
85
|
+
networkPassphrase: toml["NETWORK_PASSPHRASE"],
|
|
86
|
+
federationServer: toml["FEDERATION_SERVER"],
|
|
87
|
+
authServer: toml["AUTH_SERVER"] as string,
|
|
88
|
+
transferServer: toml["TRANSFER_SERVER"],
|
|
89
|
+
transferServerSep24: toml["TRANSFER_SERVER_SEP0024"],
|
|
90
|
+
kycServer: toml["KYC_SERVER"],
|
|
91
|
+
webAuthEndpoint: toml["WEB_AUTH_ENDPOINT"],
|
|
92
|
+
signingKey: toml["SIGNING_KEY"],
|
|
93
|
+
horizonUrl: toml["HORIZON_URL"],
|
|
94
|
+
accounts: toml["ACCOUNTS"],
|
|
95
|
+
uriRequestSigningKey: toml["URI_REQUEST_SIGNING_KEY"],
|
|
96
|
+
directPaymentServer: toml["DIRECT_PAYMENT_SERVER"],
|
|
97
|
+
anchorQuoteServer: toml["ANCHOR_QUOTE_SERVER"],
|
|
98
|
+
documentation,
|
|
99
|
+
principals,
|
|
100
|
+
currencies,
|
|
101
|
+
validators,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import isEqual from "lodash/isEqual";
|
|
2
2
|
|
|
3
|
-
import { Anchor } from "
|
|
4
|
-
import {
|
|
3
|
+
import { Anchor } from "../Anchor";
|
|
4
|
+
import {
|
|
5
|
+
AnchorTransaction,
|
|
6
|
+
TransactionStatus,
|
|
7
|
+
WatchTransactionParams,
|
|
8
|
+
WatchTransactionsParams,
|
|
9
|
+
WatcherResponse,
|
|
10
|
+
} from "../Types";
|
|
5
11
|
|
|
6
12
|
interface WatchRegistryAsset {
|
|
7
13
|
[id: string]: boolean;
|
|
@@ -30,7 +36,7 @@ export class Watcher {
|
|
|
30
36
|
private _oneTransactionWatcher: {
|
|
31
37
|
[assetCode: string]: {
|
|
32
38
|
[id: string]: ReturnType<typeof setTimeout>;
|
|
33
|
-
}
|
|
39
|
+
};
|
|
34
40
|
};
|
|
35
41
|
private _allTransactionsWatcher?: ReturnType<typeof setTimeout>;
|
|
36
42
|
private _watchOneTransactionRegistry: WatchOneTransactionRegistry;
|
|
@@ -50,41 +56,42 @@ export class Watcher {
|
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
watchAllTransactions(
|
|
65
|
-
authToken
|
|
66
|
-
assetCode
|
|
67
|
-
onMessage
|
|
68
|
-
onError
|
|
69
|
-
watchlist
|
|
70
|
-
timeout
|
|
71
|
-
isRetry
|
|
72
|
-
|
|
73
|
-
kind
|
|
74
|
-
|
|
75
|
-
}): WatcherResponse {
|
|
76
|
-
const {
|
|
59
|
+
* Watch all transactions returned from a transfer server. When new or
|
|
60
|
+
* updated transactions come in, run an `onMessage` callback.
|
|
61
|
+
*
|
|
62
|
+
* On initial load, it'll return ALL pending transactions via onMessage.
|
|
63
|
+
* Subsequent messages will be any one of these events:
|
|
64
|
+
* - Any new transaction appears
|
|
65
|
+
* - Any of the initial pending transactions change any state
|
|
66
|
+
*
|
|
67
|
+
* You may also provide an array of transaction ids, `watchlist`, and this
|
|
68
|
+
* watcher will always react to transactions whose ids are in the watchlist.
|
|
69
|
+
*/
|
|
70
|
+
watchAllTransactions({
|
|
71
|
+
authToken,
|
|
72
|
+
assetCode,
|
|
73
|
+
onMessage,
|
|
74
|
+
onError,
|
|
75
|
+
watchlist = [],
|
|
76
|
+
timeout = 5000,
|
|
77
|
+
isRetry = false,
|
|
78
|
+
lang = this.anchor.language,
|
|
79
|
+
kind,
|
|
80
|
+
noOlderThan,
|
|
81
|
+
}: WatchTransactionsParams): WatcherResponse {
|
|
82
|
+
const allParams = {
|
|
77
83
|
authToken,
|
|
78
84
|
assetCode,
|
|
79
85
|
onMessage,
|
|
80
86
|
onError,
|
|
81
|
-
watchlist
|
|
82
|
-
timeout
|
|
83
|
-
isRetry
|
|
84
|
-
lang
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
watchlist,
|
|
88
|
+
timeout,
|
|
89
|
+
isRetry,
|
|
90
|
+
lang,
|
|
91
|
+
kind,
|
|
92
|
+
noOlderThan,
|
|
93
|
+
};
|
|
94
|
+
|
|
88
95
|
// make an object map out of watchlist
|
|
89
96
|
const watchlistMap = watchlist.reduce(
|
|
90
97
|
(memo, id: string) => ({ ...memo, [id]: true }),
|
|
@@ -93,10 +100,10 @@ export class Watcher {
|
|
|
93
100
|
|
|
94
101
|
// make sure to initiate registries for the given asset code
|
|
95
102
|
// to prevent 'Cannot read properties of undefined' errors
|
|
96
|
-
if(!this._transactionsRegistry[assetCode]) {
|
|
103
|
+
if (!this._transactionsRegistry[assetCode]) {
|
|
97
104
|
this._transactionsRegistry[assetCode] = {};
|
|
98
105
|
}
|
|
99
|
-
if(!this._transactionsIgnoredRegistry[assetCode]) {
|
|
106
|
+
if (!this._transactionsIgnoredRegistry[assetCode]) {
|
|
100
107
|
this._transactionsIgnoredRegistry[assetCode] = {};
|
|
101
108
|
}
|
|
102
109
|
|
|
@@ -105,74 +112,76 @@ export class Watcher {
|
|
|
105
112
|
this._watchAllTransactionsRegistry[assetCode] = true;
|
|
106
113
|
}
|
|
107
114
|
|
|
108
|
-
this.anchor
|
|
109
|
-
.
|
|
115
|
+
this.anchor
|
|
116
|
+
.sep24()
|
|
117
|
+
.getTransactionsForAsset({
|
|
118
|
+
authToken,
|
|
119
|
+
assetCode,
|
|
120
|
+
lang,
|
|
121
|
+
kind,
|
|
122
|
+
noOlderThan,
|
|
123
|
+
})
|
|
124
|
+
.then((transactions: AnchorTransaction[]) => {
|
|
110
125
|
// make sure we're still watching
|
|
111
126
|
if (!this._watchAllTransactionsRegistry[assetCode]) {
|
|
112
127
|
return;
|
|
113
128
|
}
|
|
114
129
|
|
|
115
130
|
try {
|
|
116
|
-
const newTransactions = transactions.filter(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
if (watchlistMap[transaction.id]) {
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// if we're not in progress, then save this in an ignore reg
|
|
133
|
-
if (!isInProgress) {
|
|
134
|
-
this._transactionsIgnoredRegistry[assetCode][
|
|
135
|
-
transaction.id
|
|
136
|
-
] = transaction;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return isInProgress;
|
|
131
|
+
const newTransactions = transactions.filter((transaction) => {
|
|
132
|
+
const isInProgress =
|
|
133
|
+
transaction.status.indexOf("pending") === 0 ||
|
|
134
|
+
transaction.status === TransactionStatus.incomplete;
|
|
135
|
+
const registeredTransaction =
|
|
136
|
+
this._transactionsRegistry[assetCode][transaction.id];
|
|
137
|
+
|
|
138
|
+
// if this is the first watch, only keep the pending ones
|
|
139
|
+
if (!isRetry) {
|
|
140
|
+
// always show transactions on the watchlist
|
|
141
|
+
if (watchlistMap[transaction.id]) {
|
|
142
|
+
return true;
|
|
140
143
|
}
|
|
141
144
|
|
|
142
|
-
// if we'
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
+
// if we're not in progress, then save this in an ignore reg
|
|
146
|
+
if (!isInProgress) {
|
|
147
|
+
this._transactionsIgnoredRegistry[assetCode][transaction.id] =
|
|
148
|
+
transaction;
|
|
145
149
|
}
|
|
146
150
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
// status immediately so register that!
|
|
150
|
-
if (
|
|
151
|
-
[
|
|
152
|
-
TransactionStatus.completed,
|
|
153
|
-
TransactionStatus.refunded,
|
|
154
|
-
TransactionStatus.expired,
|
|
155
|
-
TransactionStatus.error,
|
|
156
|
-
].includes(transaction.status) &&
|
|
157
|
-
isRetry &&
|
|
158
|
-
!this._transactionsIgnoredRegistry[assetCode][transaction.id]
|
|
159
|
-
) {
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
151
|
+
return isInProgress;
|
|
152
|
+
}
|
|
162
153
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
154
|
+
// if we've had the transaction before, only report updates
|
|
155
|
+
if (registeredTransaction) {
|
|
156
|
+
return !isEqual(registeredTransaction, transaction);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// if it's NOT a registered transaction, and it's not the first
|
|
160
|
+
// roll, maybe it's a new transaction that achieved a final
|
|
161
|
+
// status immediately so register that!
|
|
162
|
+
if (
|
|
163
|
+
[
|
|
164
|
+
TransactionStatus.completed,
|
|
165
|
+
TransactionStatus.refunded,
|
|
166
|
+
TransactionStatus.expired,
|
|
167
|
+
TransactionStatus.error,
|
|
168
|
+
].includes(transaction.status) &&
|
|
169
|
+
isRetry &&
|
|
170
|
+
!this._transactionsIgnoredRegistry[assetCode][transaction.id]
|
|
171
|
+
) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// always use in progress transactions
|
|
176
|
+
if (isInProgress) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
167
179
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
);
|
|
180
|
+
return false;
|
|
181
|
+
});
|
|
171
182
|
|
|
172
183
|
newTransactions.forEach((transaction) => {
|
|
173
|
-
this._transactionsRegistry[assetCode][
|
|
174
|
-
transaction.id
|
|
175
|
-
] = transaction;
|
|
184
|
+
this._transactionsRegistry[assetCode][transaction.id] = transaction;
|
|
176
185
|
|
|
177
186
|
if (transaction.status === TransactionStatus.error) {
|
|
178
187
|
onError(transaction);
|
|
@@ -191,9 +200,9 @@ export class Watcher {
|
|
|
191
200
|
}
|
|
192
201
|
this._allTransactionsWatcher = setTimeout(() => {
|
|
193
202
|
this.watchAllTransactions({
|
|
194
|
-
...
|
|
203
|
+
...allParams,
|
|
195
204
|
isRetry: true,
|
|
196
|
-
|
|
205
|
+
});
|
|
197
206
|
}, timeout);
|
|
198
207
|
})
|
|
199
208
|
.catch((e) => {
|
|
@@ -212,9 +221,9 @@ export class Watcher {
|
|
|
212
221
|
}
|
|
213
222
|
|
|
214
223
|
this.watchAllTransactions({
|
|
215
|
-
...
|
|
224
|
+
...allParams,
|
|
216
225
|
isRetry: true,
|
|
217
|
-
|
|
226
|
+
});
|
|
218
227
|
},
|
|
219
228
|
stop: () => {
|
|
220
229
|
if (this._allTransactionsWatcher) {
|
|
@@ -228,41 +237,41 @@ export class Watcher {
|
|
|
228
237
|
}
|
|
229
238
|
|
|
230
239
|
/**
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
watchOneTransaction(
|
|
238
|
-
authToken
|
|
239
|
-
assetCode
|
|
240
|
-
id
|
|
241
|
-
onMessage
|
|
242
|
-
onSuccess
|
|
243
|
-
onError
|
|
244
|
-
timeout
|
|
245
|
-
isRetry
|
|
246
|
-
lang
|
|
247
|
-
}): WatcherResponse {
|
|
248
|
-
const {
|
|
240
|
+
* Watch a transaction until it stops pending. Takes three callbacks:
|
|
241
|
+
* * onMessage - When the transaction comes back as pending_ or incomplete.
|
|
242
|
+
* * onSuccess - When the transaction comes back as completed / refunded / expired.
|
|
243
|
+
* * onError - When there's a runtime error, or the transaction comes back as
|
|
244
|
+
* no_market / too_small / too_large / error.
|
|
245
|
+
*/
|
|
246
|
+
watchOneTransaction({
|
|
247
|
+
authToken,
|
|
248
|
+
assetCode,
|
|
249
|
+
id,
|
|
250
|
+
onMessage,
|
|
251
|
+
onSuccess,
|
|
252
|
+
onError,
|
|
253
|
+
timeout = 5000,
|
|
254
|
+
isRetry = false,
|
|
255
|
+
lang = this.anchor.language,
|
|
256
|
+
}: WatchTransactionParams): WatcherResponse {
|
|
257
|
+
const allParams = {
|
|
249
258
|
authToken,
|
|
250
259
|
assetCode,
|
|
251
260
|
id,
|
|
252
261
|
onMessage,
|
|
253
262
|
onSuccess,
|
|
254
263
|
onError,
|
|
255
|
-
timeout
|
|
256
|
-
isRetry
|
|
257
|
-
lang
|
|
258
|
-
}
|
|
264
|
+
timeout,
|
|
265
|
+
isRetry,
|
|
266
|
+
lang,
|
|
267
|
+
};
|
|
259
268
|
|
|
260
269
|
// make sure to initiate registries for the given asset code
|
|
261
270
|
// to prevent 'Cannot read properties of undefined' errors
|
|
262
|
-
if(!this._transactionsRegistry[assetCode]) {
|
|
271
|
+
if (!this._transactionsRegistry[assetCode]) {
|
|
263
272
|
this._transactionsRegistry[assetCode] = {};
|
|
264
273
|
}
|
|
265
|
-
if(!this._oneTransactionWatcher[assetCode]) {
|
|
274
|
+
if (!this._oneTransactionWatcher[assetCode]) {
|
|
266
275
|
this._oneTransactionWatcher[assetCode] = {};
|
|
267
276
|
}
|
|
268
277
|
|
|
@@ -275,16 +284,17 @@ export class Watcher {
|
|
|
275
284
|
}
|
|
276
285
|
|
|
277
286
|
// do this all asynchronously (since this func needs to return a cancel fun)
|
|
278
|
-
this.anchor
|
|
279
|
-
.
|
|
287
|
+
this.anchor
|
|
288
|
+
.sep24()
|
|
289
|
+
.getTransactionBy({ authToken, id, lang })
|
|
290
|
+
.then((transaction: AnchorTransaction) => {
|
|
280
291
|
// make sure we're still watching
|
|
281
292
|
if (!this._watchOneTransactionRegistry[assetCode]?.[id]) {
|
|
282
293
|
return;
|
|
283
294
|
}
|
|
284
295
|
|
|
285
|
-
const registeredTransaction =
|
|
286
|
-
transaction.id
|
|
287
|
-
];
|
|
296
|
+
const registeredTransaction =
|
|
297
|
+
this._transactionsRegistry[assetCode][transaction.id];
|
|
288
298
|
|
|
289
299
|
// if we've had the transaction before, only report if there is a change
|
|
290
300
|
if (
|
|
@@ -306,16 +316,16 @@ export class Watcher {
|
|
|
306
316
|
|
|
307
317
|
this._oneTransactionWatcher[assetCode][id] = setTimeout(() => {
|
|
308
318
|
this.watchOneTransaction({
|
|
309
|
-
...
|
|
319
|
+
...allParams,
|
|
310
320
|
isRetry: true,
|
|
311
321
|
});
|
|
312
322
|
}, timeout);
|
|
313
323
|
onMessage(transaction);
|
|
314
324
|
} else if (
|
|
315
325
|
[
|
|
316
|
-
TransactionStatus.completed,
|
|
326
|
+
TransactionStatus.completed,
|
|
317
327
|
TransactionStatus.refunded,
|
|
318
|
-
TransactionStatus.expired
|
|
328
|
+
TransactionStatus.expired,
|
|
319
329
|
].includes(transaction.status)
|
|
320
330
|
) {
|
|
321
331
|
onSuccess(transaction);
|
|
@@ -339,7 +349,7 @@ export class Watcher {
|
|
|
339
349
|
}
|
|
340
350
|
|
|
341
351
|
this.watchOneTransaction({
|
|
342
|
-
...
|
|
352
|
+
...allParams,
|
|
343
353
|
isRetry: true,
|
|
344
354
|
});
|
|
345
355
|
},
|
|
@@ -351,5 +361,4 @@ export class Watcher {
|
|
|
351
361
|
},
|
|
352
362
|
};
|
|
353
363
|
}
|
|
354
|
-
|
|
355
364
|
}
|