Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function*(action) {
const state: AppState = yield select();
const gamePhase = state.game.phase;
// not in correct phase
if (gamePhase === GamePhase.WAITING || gamePhase === GamePhase.DEAD) {
return;
}
const card = state.cards[action.payload.index];
const money = state.game.money;
// card doesn't exist or player can't afford
if (!card || money < card.cost) {
return;
}
function*() {
const state: AppState = yield select();
// if player not connected yet, don't try to reconnect
if (state.localPlayer.id === null) {
yield put(updateConnectionStatus(ConnectionStatus.DISCONNECTED_FINAL));
return;
}
const packet: ReconnectAuthenticatePacket = {
gameId: state.game.gameId,
playerId: state.localPlayer.id,
reconnectSecret: state.localPlayer.reconnectionSecret
};
yield put(sendPacket(ClientToServerPacketOpcodes.RECONNECT_AUTHENTICATE, packet));
}
)
function* fetchErc20Balances (api: IApi, action: IFetchErc20BalancesAction): SagaIterator {
const accounts: AddressMap[] = yield select(allAsArray);
for (const acc of accounts) {
const address = acc.get('id');
const chain = acc.get('blockchain').toLowerCase();
// Look up all known tokens for current blockchain
const _tokens = registry.all()[chain as BlockchainCode];
// Request balance for each token for current address
for (const t of _tokens) {
yield put(requestTokenBalance(chain, t, address));
}
}
}
function*(action) {
if (isGamePhaseUpdate(GamePhase.PREPARING, action) || isGamePhaseUpdate(GamePhase.READY, action)) {
// don't do anything, just cancel the old one
const pieces = (action.payload as any).payload.pieces;
yield put(BoardActions.piecesUpdated(pieces));
return;
}
const state: AppState = yield select();
const battleChannel = yield call(startBattle, turnSimulator, state.board, Constants.TURNS_IN_BATTLE);
yield takeEvery(battleChannel, function*(battleAction: BattleAction) {
switch (battleAction.type) {
case BATTLE_TURN:
yield put(BoardActions.piecesUpdated(battleAction.payload.pieces));
case BATTLE_FINISHED:
yield put(battleAction);
default:
return;
}
});
}
);
function* fetchHdPaths (api: IApi, action: IFetchHdPathsAction) {
const accounts: AddressList = yield select(all);
const hwAccounts: AddressMap[] = accounts.filter((a: any) => a.get('hardware', true)).toArray();
for (const item of hwAccounts) {
const address = item.get('id');
const chain = item.get('blockchain').toLowerCase();
const result = yield call(api.emerald.exportAccount, address, chain);
yield put({
type: ActionTypes.SET_HD_PATH,
accountId: address,
hdpath: result.crypto.hd_path,
blockchain: chain
});
}
}