-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.4.1-0.1.0: [feature] - Multi Sim (#199)
* Start refactor to use eventId * Adds multisim method * Fix type * Add multiSim method to class * Increment version * Fix error messages * Fixes type
- Loading branch information
1 parent
c0f0432
commit 0d8d26c
Showing
7 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { take, filter } from 'rxjs/operators' | ||
import { nanoid } from 'nanoid' | ||
import { SimulationTransaction, SimulationTransactionOutput } from './types' | ||
import { simulations$ } from './streams' | ||
import SDK from '.' | ||
|
||
function multiSim( | ||
this: SDK, | ||
transactions: SimulationTransaction[] | ||
): Promise<SimulationTransactionOutput[]> { | ||
if (this._destroyed) | ||
throw new Error( | ||
'The WebSocket instance has been destroyed, re-initialize to continue making requests.' | ||
) | ||
|
||
const id = nanoid() | ||
|
||
// send payload to server | ||
this._sendMessage({ | ||
categoryCode: 'simulate', | ||
eventCode: 'txSimulation', | ||
eventId: id, | ||
transaction: transactions | ||
}) | ||
|
||
return new Promise((resolve, reject) => { | ||
simulations$ | ||
.pipe( | ||
filter(({ eventId }) => { | ||
return eventId === id | ||
}), | ||
take(1) | ||
) | ||
.subscribe({ | ||
next: ({ transaction }) => | ||
resolve(transaction as SimulationTransactionOutput[]), | ||
error: ({ error }) => reject(error.message) | ||
}) | ||
}) | ||
} | ||
|
||
export default multiSim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { Subject } from 'rxjs' | ||
import { SimulationTransactionOutput } from './types' | ||
|
||
export const simulations$ = new Subject<SimulationTransactionOutput>() | ||
export const simulations$ = new Subject<{ | ||
eventId: string | ||
transaction: SimulationTransactionOutput | SimulationTransactionOutput[] | ||
}>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters