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) {
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*() {
const { board }: TState = yield select();
const battleChannel = yield call(battleEventChannel, turnSimulator, turnDuration, board, turnCount);
yield takeEvery(battleChannel, function*(battleAction: BattleAction) {
yield put(battleAction);
});
}
);
const getResponseForAction = (socket: Socket, action: FindGameAction | JoinGameAction | CreateGameAction) => {
if (action.type === JOIN_GAME) {
return call(joinGame, socket, action.payload.name, action.payload.gameId);
}
if (action.type === FIND_GAME) {
return call(findGame, socket, action.payload.name);
}
if (action.type === CREATE_GAME) {
return call(createGame, socket, action.payload.name);
}
};
const getResponseForAction = (socket: Socket, action: FindGameAction | JoinGameAction | CreateGameAction) => {
if (action.type === JOIN_GAME) {
return call(joinGame, socket, action.payload.name, action.payload.gameId);
}
if (action.type === FIND_GAME) {
return call(findGame, socket, action.payload.name);
}
if (action.type === CREATE_GAME) {
return call(createGame, socket, action.payload.name);
}
};
export const networking = function*() {
let action: (FindGameAction | JoinGameAction | CreateGameAction)
= yield take([FIND_GAME, JOIN_GAME, CREATE_GAME]);
const socket: Socket = yield call(getSocket, action.payload.serverIP);
yield put(updateConnectionStatus(ConnectionStatus.CONNECTED));
yield fork(readPacketsToActions, socket);
while (true) {
const { error, response }: JoinLobbyResponse = yield getResponseForAction(socket, action);
if (!error) {
yield put(joinLobbyAction(
response.playerId,
response.lobbyId,
response.players,
response.startTimestamp,
response.isHost
));
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
});
}
}
function* loadPerspectiveDetails(action: LoadPerspectiveDetails) {
const evees: Evees = (yield getContext(ReduxTypes.Context)).get(EveesTypes.Evees);
const details = yield call(() => evees.getPerspectiveDetails(action.payload.perspectiveId));
const successAction: LoadPerspectiveDetailsSuccess = {
type: LOAD_PERSPECTIVE_DETAILS_SUCCESS,
payload: {
perspectiveId: action.payload.perspectiveId,
details
}
};
yield put(successAction);
}
const getResponseForAction = (socket: Socket, action: FindGameAction | JoinGameAction | CreateGameAction) => {
if (action.type === JOIN_GAME) {
return call(joinGame, socket, action.payload.name, action.payload.gameId);
}
if (action.type === FIND_GAME) {
return call(findGame, socket, action.payload.name);
}
if (action.type === CREATE_GAME) {
return call(createGame, socket, action.payload.name);
}
};