Skip to content

Commit

Permalink
fix(fdc3) - Add factory methods for creating channels if necessary, f…
Browse files Browse the repository at this point in the history
…ixed example dialog, added MessageRouterDuplicatEndpointException, added descriptions, removed comments, and todos
  • Loading branch information
lilla28 committed Sep 4, 2024
1 parent 6d7d650 commit 1a67434
Show file tree
Hide file tree
Showing 32 changed files with 229 additions and 1,616 deletions.
869 changes: 16 additions & 853 deletions examples/fdc3-appdirectory/apps.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/fdc3-chart-and-grid/js-chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function requestData() {
currentChannel = await window.fdc3.getCurrentChannel();

if(!currentChannel) {
await window.fdc3.joinUserChannel("default");
await window.fdc3.joinUserChannel("fdc3.channel.1");
}

contextListener = await window.fdc3.addContextListener(ContextTypes.Instrument, (context, metadata) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ export class MockDataService{
private connecting: Promise<void>;

constructor(){
this.market = new Market();
this.connecting = new Promise(async(resolve, reject) => {
try{
resolve(await this.checkFdc3Connection());
} catch(err) {
reject(err);
};
});
this.market = new Market();
this.connecting = new Promise(async(resolve, reject) => {
try{
resolve(await this.checkFdc3Connection());
} catch(err) {
reject(err);
};
});

interval(1000).subscribe(() => {
this.marketData = this.market.generateNewMarketNumbers();
this.subject.next(this.marketData);
});
interval(1000).subscribe(() => {
this.marketData = this.market.generateNewMarketNumbers();
this.subject.next(this.marketData);
});
}

private async checkFdc3Connection(): Promise<void> {
if(!this.connected) {
this.currentChannel = await window.fdc3.getCurrentChannel();
if (!this.currentChannel) {
await window.fdc3.joinUserChannel("default");
await window.fdc3.joinUserChannel("fdc3.channel.1");
}
this.connected = true;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/fdc3-pricing-and-chat/js-chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ window.app = function () {
window.addEventListener('load', async function () {
intentListener = await window.fdc3.addIntentListener("StartChat", window.app.handleChatIntent);

await window.fdc3.joinUserChannel("default");
await window.fdc3.joinUserChannel("fdc3.channel.1");
});
2 changes: 1 addition & 1 deletion examples/fdc3-pricing-and-chat/js-pricing/pricing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import "bootstrap/dist/css/bootstrap.css";

window.addEventListener('load', async function () {
const pricingForm = document.querySelector("#pricing");
await this.window.fdc3.joinUserChannel("default");
await this.window.fdc3.joinUserChannel("fdc3.channel.1");
pricingForm.addEventListener('submit', app.submitPrice);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
type: topic,
result: {
success: false,
<<<<<<< HEAD
action: "BUY",
=======
>>>>>>> f312aa3 (feat(app-channels) - Implement fdc3.getOrCreateChannel(), stopping started instances in the tests, refactored channel tests)
error: "No symbol found."
}
});
Expand All @@ -244,8 +241,6 @@ export class MarketWatchComponent implements OnInit, OnDestroy{

if (data.action === 'BUY') {
const sumQuantity = symbols.reduce((sum, current) => {
console.log(current);
console.log(sum);
if (current.Children && current.Children.length > 0) {
let s: number = current.Children.reduce((t, currentSymbol) => {
if(currentSymbol.AskSize) {
Expand All @@ -259,18 +254,14 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
return sum + 0;
}, 0);

console.log("Sum of the available symbols on the market:", sumQuantity);

if (sumQuantity < data.quantity) {
await this.channel!.broadcast(
{
type: topic,
result: {
success: false,
<<<<<<< HEAD
action: "BUY",
=======
>>>>>>> f312aa3 (feat(app-channels) - Implement fdc3.getOrCreateChannel(), stopping started instances in the tests, refactored channel tests)
error: "Too much ticks were requested; not enough symbols are available on the target."
}
});
Expand All @@ -281,7 +272,6 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
let price: number = 0;
let size = data.quantity;
for (let element of ELEMENT_DATA) {
console.log("current size:", size);
if (size == 0) {
break;
}
Expand All @@ -300,10 +290,7 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
type: topic,
result: {
success: true,
<<<<<<< HEAD
action: "BUY",
=======
>>>>>>> f312aa3 (feat(app-channels) - Implement fdc3.getOrCreateChannel(), stopping started instances in the tests, refactored channel tests)
tradePrice: price
}
});
Expand All @@ -312,7 +299,6 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
}

for (let innerElement of element.Children) {
console.log("current size:", size);
if (innerElement.Symbol != data.symbol) {
continue;
}
Expand All @@ -327,7 +313,6 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
price = price + innerElement.AskSize * (innerElement.AskPrice == undefined ? 0 : innerElement.AskPrice);
size = size - innerElement.AskSize;
innerElement.AskSize = 0;
console.log("current size: hello", size);
innerElement.LastTrade = data.timestamp;
}
}
Expand All @@ -337,10 +322,7 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
type: topic,
result: {
success: true,
<<<<<<< HEAD
action: "BUY",
=======
>>>>>>> f312aa3 (feat(app-channels) - Implement fdc3.getOrCreateChannel(), stopping started instances in the tests, refactored channel tests)
tradePrice: price
}
});
Expand Down Expand Up @@ -376,7 +358,6 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
if(symbolElement) {
symbolElement.BidSize = symbolElement.BidSize + data.quantity;
symbolElement.LastTrade = data.timestamp;
<<<<<<< HEAD
await this.channel!.broadcast(
{
type: topic,
Expand All @@ -385,14 +366,11 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
action: "SELL",
}
});
=======
>>>>>>> f312aa3 (feat(app-channels) - Implement fdc3.getOrCreateChannel(), stopping started instances in the tests, refactored channel tests)
this.subject.next(
{
Symbol: data.symbol,
DataSource: [...ELEMENT_DATA]
});
<<<<<<< HEAD
} else {
await this.channel!.broadcast(
{
Expand All @@ -403,8 +381,6 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
error: "Trader is not able to place its symbol for selling."
}
});
=======
>>>>>>> f312aa3 (feat(app-channels) - Implement fdc3.getOrCreateChannel(), stopping started instances in the tests, refactored channel tests)
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ <h2 mat-dialog-title>Hi {{data.trader}}</h2>
<p>Please confirm your intent to this symbol {{data.symbol}} with quantity: {{data.quantity}}</p>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button [mat-dialog-close]="'BUY'" cdkFocusInitial>Buy</button>
<button mat-button [mat-dialog-close]="'SELL'">Sell</button>
<button class="dialog-close" mat-button mat-dialog-close [style.color]="'red'" [style.position]="'absolute'" [style.right]="'20px'">Cancel</button>
<button mat-button [mat-dialog-close]="true" cdkFocusInitial>Confirm</button>
<button class="dialog-close" mat-button [mat-dialog-close]="false" [style.color]="'red'" [style.position]="'absolute'" [style.right]="'20px'">Cancel</button>
</mat-dialog-actions>
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ <h1>Trading App</h1>
</mat-select>
</mat-form-field>

<button mat-icon-button class="sendButton" (click)="broadcastTradeIdea()">
<mat-icon>send</mat-icon>
</button>
<button mat-button class="buyButton" cdkFocusInitial (click)="buySymbol()">Buy</button>
<button mat-button class="sellButton" (click)="sellSymbol()">Sell</button>

<div class="feedback">{{ feedback }}</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class TradeIdeaGeneratorComponent implements OnDestroy {
}

async ngOnDestroy() {
this.listeners.forEach(async (listener, _) => {
await listener.unsubscribe();
this.listeners.forEach((listener, _) => {
listener.unsubscribe();
});

this.listeners.clear();
Expand Down Expand Up @@ -130,7 +130,7 @@ export class TradeIdeaGeneratorComponent implements OnDestroy {
return !this.wrapValue && inputValue >= this.maximumValue;
}

public async broadcastTradeIdea() : Promise<void> {
private async broadcastTradeIdea(action: string) : Promise<void> {
if (!this.currentValue || this.currentValue <= 0) {
this.feedbackSubject.next('Please select at least 1 quantity.');
return;
Expand All @@ -150,13 +150,11 @@ export class TradeIdeaGeneratorComponent implements OnDestroy {
data: {trader: this.trader!, quantity: this.currentValue, symbol: this.symbols.value as string}
});

dialogRef.afterClosed().subscribe(async result => {
dialogRef.afterClosed().subscribe(async (result: boolean) => {
if (!result) {
return;
}

const action = result as string;

const context: Context = {
type: "fdc3.trade",
data: {
Expand All @@ -182,19 +180,13 @@ export class TradeIdeaGeneratorComponent implements OnDestroy {
return;
}

<<<<<<< HEAD
const result = context['result'];
if (result.action as string == "BUY") {
const price: number = result.tradePrice as number;
this.feedbackSubject.next(this.trader + " has bought " + this.currentValue + " symbol of: " + this.symbols.value as string + " for $" + price + ".");
} else {
this.feedbackSubject.next(this.trader + " has indicated that " + this.currentValue + " symbol of: " + this.symbols.value as string + " is/are available for buying.");
}
=======
const price: number = context['result'].tradePrice as number;
this.feedbackSubject.next(this.trader + " has bought " + this.currentValue + " symbol of: " + this.symbols.value as string + " for $" + price + ".");
console.log(this.feedback);
>>>>>>> f312aa3 (feat(app-channels) - Implement fdc3.getOrCreateChannel(), stopping started instances in the tests, refactored channel tests)
});
this.listeners.set(topic, listener);
}
Expand All @@ -207,6 +199,14 @@ export class TradeIdeaGeneratorComponent implements OnDestroy {
}
});
}

public async buySymbol() : Promise<void> {
await this.broadcastTradeIdea("BUY");
}

public async sellSymbol() : Promise<void> {
await this.broadcastTradeIdea("SELL");
}
}

@Component({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"examples/js-chart-and-grid-messagerouter/js-*",
"examples/fdc3-chart-and-grid/js-*",
"examples/fdc3-pricing-and-chat/js-*",
"examples/fdc3-trade-simulator/js-*",
"examples/fdc3-trade-simulator/js-*",
"src/messaging/js/*",
"src/shell/js/*",
"src/fdc3/js/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public async ValueTask Connect()

await MessagingService.ConnectAsync();

await MessagingService.RegisterServiceAsync(_topics.GetCurrentContext, GetCurrentContext);

var broadcastHandler = new Func<IMessageBuffer, ValueTask>(HandleBroadcast);
var broadcastSubscription = MessagingService.SubscribeAsync(_topics.Broadcast, broadcastHandler);

await MessagingService.RegisterServiceAsync(_topics.GetCurrentContext, GetCurrentContext);
_broadcastSubscription = await broadcastSubscription;


LogConnected();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

using Microsoft.Extensions.Options;
using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol;

namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection;

Expand All @@ -28,6 +29,11 @@ public sealed class Fdc3DesktopAgentOptions : IOptions<Fdc3DesktopAgentOptions>
/// </summary>
public Uri? UserChannelConfigFile { get; set; }

/// <summary>
/// Sets the UserChannel set.
/// </summary>
public ChannelItem[]? UserChannelConfig { get; set; }

/// <summary>
/// Indicates a timeout value for getting the IntentResult from the backend in milliseconds.
/// When set to any value, it sets the timeout for the getResult() client calls, which should wait either for this timeout or the task which gets the appropriate resolved IntentResolution.
Expand Down
Loading

0 comments on commit 1a67434

Please sign in to comment.