-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Automatically rollover if user opens app during rollover weekend.
- Loading branch information
Showing
14 changed files
with
291 additions
and
17 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
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,51 @@ | ||
import 'package:get_10101/bridge_generated/bridge_definitions.dart' as bridge; | ||
import 'package:get_10101/features/trade/domain/order.dart'; | ||
|
||
class AsyncTrade { | ||
final OrderReason orderReason; | ||
|
||
AsyncTrade({required this.orderReason}); | ||
|
||
static AsyncTrade fromApi(bridge.BackgroundTask_AsyncTrade asyncTrade) { | ||
return AsyncTrade(orderReason: OrderReason.fromApi(asyncTrade.field0)); | ||
} | ||
|
||
static bridge.BackgroundTask apiDummy() { | ||
return bridge.BackgroundTask_AsyncTrade(OrderReason.apiDummy()); | ||
} | ||
} | ||
|
||
enum TaskStatus { | ||
pending, | ||
failed, | ||
success; | ||
|
||
static TaskStatus fromApi(bridge.TaskStatus taskStatus) { | ||
switch (taskStatus) { | ||
case bridge.TaskStatus.Pending: | ||
return TaskStatus.pending; | ||
case bridge.TaskStatus.Failed: | ||
return TaskStatus.failed; | ||
case bridge.TaskStatus.Success: | ||
return TaskStatus.success; | ||
} | ||
} | ||
|
||
static bridge.TaskStatus apiDummy() { | ||
return bridge.TaskStatus.Pending; | ||
} | ||
} | ||
|
||
class Rollover { | ||
final TaskStatus taskStatus; | ||
|
||
Rollover({required this.taskStatus}); | ||
|
||
static Rollover fromApi(bridge.BackgroundTask_Rollover rollover) { | ||
return Rollover(taskStatus: TaskStatus.fromApi(rollover.field0)); | ||
} | ||
|
||
static bridge.BackgroundTask apiDummy() { | ||
return bridge.BackgroundTask_Rollover(TaskStatus.apiDummy()); | ||
} | ||
} |
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,54 @@ | ||
import 'package:f_logs/model/flog/flog.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_10101/bridge_generated/bridge_definitions.dart' as bridge; | ||
import 'package:get_10101/common/application/event_service.dart'; | ||
import 'package:get_10101/common/domain/background_task.dart'; | ||
import 'package:get_10101/common/global_keys.dart'; | ||
import 'package:get_10101/features/trade/order_submission_status_dialog.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class RolloverChangeNotifier extends ChangeNotifier implements Subscriber { | ||
late TaskStatus taskStatus; | ||
|
||
@override | ||
void notify(bridge.Event event) { | ||
if (event is bridge.Event_BackgroundNotification && | ||
event.field0 is bridge.BackgroundTask_Rollover) { | ||
Rollover rollover = Rollover.fromApi(event.field0 as bridge.BackgroundTask_Rollover); | ||
FLog.debug(text: "Received a rollover event. Status: ${rollover.taskStatus}"); | ||
|
||
taskStatus = rollover.taskStatus; | ||
|
||
if (taskStatus == TaskStatus.pending) { | ||
// initialize dialog for the pending task | ||
showDialog( | ||
context: shellNavigatorKey.currentContext!, | ||
builder: (context) { | ||
TaskStatus status = context.watch<RolloverChangeNotifier>().taskStatus; | ||
|
||
// todo(holzeis): Reusing the order submission status dialog is not nice, but it's actually suitable for any task execution that has pending, | ||
// failed and success states. We may should consider renaming this dialog for its more generic purpose. | ||
OrderSubmissionStatusDialogType type = OrderSubmissionStatusDialogType.pendingSubmit; | ||
switch (status) { | ||
case TaskStatus.pending: | ||
type = OrderSubmissionStatusDialogType.successfulSubmit; | ||
case TaskStatus.failed: | ||
type = OrderSubmissionStatusDialogType.failedFill; | ||
case TaskStatus.success: | ||
type = OrderSubmissionStatusDialogType.filled; | ||
} | ||
|
||
late Widget content = const Text("Rolling over your position"); | ||
|
||
return OrderSubmissionStatusDialog(title: "Catching up!", type: type, content: content); | ||
}, | ||
); | ||
} else { | ||
// notify dialog about changed task status | ||
notifyListeners(); | ||
} | ||
} else { | ||
FLog.warning(text: "Received unexpected event: ${event.toString()}"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.