openGameForChance method
Opens the game for a rewards chance the user already holds: the chance
plays directly, never a new grantChance. Anything missing (no chance,
unknown campaign, no config) is a quiet no-op, like a denied entry tap;
a game already open fails with game_open_failed(busy). Completes when
the game closes. Never throws.
Implementation
Future<void> openGameForChance(String chanceId, {String? campaignId}) async {
try {
if (chanceId.trim().isEmpty) return;
final id = (campaignId != null && campaignId.isNotEmpty)
? campaignId
: _gamification.chanceForId(chanceId)?.campaignId;
if (id == null || id.isEmpty) {
_log.w('Game skipped — unknown rewards chance (chanceId=$chanceId)');
return;
}
final found = _gamification.campaignForRewardsChance(id);
if (found == null) {
_log.w('Game skipped — unknown rewards campaign (campaignId=$id)');
return;
}
await _gamificationSurface.openGameForChance(
chanceId: chanceId,
campaign: found.campaign,
config: found.config,
);
} catch (e) {
_log.w('Game skipped — rewards open failed ($e)');
}
}