@@ -143,7 +143,7 @@ const makeThorchainPlugin = (info: ThorchainInfo): PartnerPlugin => {
143
143
}
144
144
145
145
// See if the transaction exists already
146
- const matchTx = standardTxs . find (
146
+ const previousTxIndex = standardTxs . findIndex (
147
147
tx =>
148
148
tx . orderId === standardTx . orderId &&
149
149
tx . timestamp === standardTx . timestamp &&
@@ -152,10 +152,21 @@ const makeThorchainPlugin = (info: ThorchainInfo): PartnerPlugin => {
152
152
tx . payoutAmount === standardTx . payoutAmount &&
153
153
tx . depositAmount !== standardTx . depositAmount
154
154
)
155
- if ( matchTx == null ) {
155
+ if ( previousTxIndex === - 1 ) {
156
156
standardTxs . push ( standardTx )
157
157
} else {
158
- matchTx . depositAmount += standardTx . depositAmount
158
+ const previousTx = standardTxs [ previousTxIndex ]
159
+ const previousRawTxs : unknown [ ] = Array . isArray ( previousTx . rawTx )
160
+ ? previousTx . rawTx
161
+ : [ previousTx . rawTx ]
162
+ const updatedStandardTx = processThorchainTx (
163
+ [ ...previousRawTxs , standardTx . rawTx ] ,
164
+ info ,
165
+ pluginParamsClean
166
+ )
167
+ if ( updatedStandardTx != null ) {
168
+ standardTxs . splice ( previousTxIndex , 1 , updatedStandardTx )
169
+ }
159
170
}
160
171
if ( standardTx . isoDate > latestIsoDate ) {
161
172
latestIsoDate = standardTx . isoDate
@@ -209,7 +220,14 @@ export function processThorchainTx(
209
220
) : StandardTx | null {
210
221
const { pluginId } = info
211
222
const { affiliateAddress, thorchainAddress } = pluginParams . apiKeys
212
- const tx = asThorchainTx ( rawTx )
223
+
224
+ const rawTxs : unknown [ ] = Array . isArray ( rawTx ) ? rawTx : [ rawTx ]
225
+ const txs = asArray ( asThorchainTx ) ( rawTxs )
226
+ const tx = txs [ 0 ]
227
+
228
+ if ( tx == null ) {
229
+ throw new Error ( `${ pluginId } : Missing rawTx` )
230
+ }
213
231
214
232
const { swap } = tx . metadata
215
233
if ( swap ?. affiliateAddress !== affiliateAddress ) {
@@ -238,13 +256,15 @@ export function processThorchainTx(
238
256
`${ pluginId } : Unexpected ${ txIn . coins . length } txIn.coins. Expected 1`
239
257
)
240
258
}
241
- const coin = txIn . coins [ 0 ]
242
- const srcAsset = coin . asset
243
- const depositAmount = Number ( coin . amount ) / THORCHAIN_MULTIPLIER
259
+ const depositAmount = txs . reduce ( ( sum , txInternal ) => {
260
+ const amount =
261
+ Number ( txInternal . in [ 0 ] . coins [ 0 ] . amount ) / THORCHAIN_MULTIPLIER
262
+ return sum + amount
263
+ } , 0 )
244
264
245
265
const srcDestMatch = tx . out . some ( o => {
246
266
const match = o . coins . some (
247
- c => c . asset === srcAsset && o . affiliate !== true
267
+ c => c . asset === txIn . coins [ 0 ] . asset && o . affiliate !== true
248
268
)
249
269
return match
250
270
} )
@@ -258,7 +278,7 @@ export function processThorchainTx(
258
278
const timestampMs = div ( tx . date , '1000000' , 16 )
259
279
const { timestamp, isoDate } = smartIsoDateFromTimestamp ( Number ( timestampMs ) )
260
280
261
- const [ chainAsset ] = srcAsset . split ( '-' )
281
+ const [ chainAsset ] = txIn . coins [ 0 ] . asset . split ( '-' )
262
282
const [ , asset ] = chainAsset . split ( '.' )
263
283
264
284
// Find the first output that does not match the affiliate address
0 commit comments