redeemCode function

Future redeemCode(
  1. String code, {
  2. int uid = 0,
})

Implementation

Future redeemCode(String code, {int uid = 0}) async {
  if (uid != 0) {
    return fetchEndpoint(
        'https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey',
        chinese: false,
        kwargs: {
          'params': {
            'uid': uid,
            'region': recognizeServer(uid),
            'cdkey': code,
            'game_biz': 'hk4e_global',
            'lang': 'en',
          },
        });
  } else {
    var accounts = await getGameAccounts();
    var higherAccounts = accounts.where((acc) => acc['level'] >= 10);
    for (var i = 0; i < higherAccounts.length; i++) {
      var account = higherAccounts[i];
      await redeemCode(code, uid: account['uid']);
    }
  }
}