const PAYOUT_RETRY_BASE = 2000;
const PAYOUT_RETRY_MULTIPLIER = 2;
const MAX_PAYOUT_RETRIES = 5;
const doAdjoePayout = () => {
doAdjoePayoutInternal(0);
const doAdjoePayoutInternal = (times) => {
if (times < 0 || times >== MAX_PAYOUT_RETRIES) {
// the payout has failed too often, which means that the user has no coins
// you should handle this case properly
// everything is fine, rewards have been paid out
.catch((reason, err) => {
if (reason === Adjoe.PAYOUT_NOT_ENOUGH_COINS) {
doAdjoePayoutInternal(times + 1);
}, PAYOUT_RETRY_BASE * PAYOUT_RETRY_MULTIPLIER^times);