Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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* handleCreateNewTemplate(action) {
const { data } = action;
try {
const template = yield newTemplate(DEFAULT_USER_NAME, data);
yield put({
type: POST_TYPE.POST_SUCCESS,
templateData: template,
});
} catch (error) {
console.error(error);
}
}
function* filterPerspectiveEntity(action: LoadEntitySuccess) {
const perspectivePattern: PerspectiveEntity = (yield getContext(ReduxTypes.Context)).get(
EveesTypes.PerspectivePattern
);
if (perspectivePattern.recognize(action.payload.entity)) {
const loadPerspectiveDetailsAction: LoadPerspectiveDetails = {
type: LOAD_PERSPECTIVE_DETAILS,
payload: { perspectiveId: action.payload.hash }
};
yield put(loadPerspectiveDetailsAction);
}
}
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
));
break;
}
if (totalInstances < PIECES_TO_EVOLVE) {
return;
}
const newBoard = board.filter(p => p.id !== piece.id && pieceIsMatching(p) === false);
const newBench = bench.filter(p => p.id !== piece.id && pieceIsMatching(p) === false);
const slot = getFirstEmptyBenchSlot(newBench);
const newPiece = {
...piece,
stage: nextStageIndex,
position: createTileCoordinates(slot, null)
};
yield put(BoardActions.piecesUpdated(newBoard));
yield put(BenchActions.benchPiecesUpdated(newBench));
yield put(BenchActions.benchPieceAdded(newPiece));
}
)
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
));
break;
}
yield put(joinGameError(error));
action = yield take([FIND_GAME, JOIN_GAME, CREATE_GAME]);
}
yield fork(writeActionsToPackets);
yield fork(writePacketsToSocket, socket);
};
}
const newBoard = board.filter(p => p.id !== piece.id && pieceIsMatching(p) === false);
const newBench = bench.filter(p => p.id !== piece.id && pieceIsMatching(p) === false);
const slot = getFirstEmptyBenchSlot(newBench);
const newPiece = {
...piece,
stage: nextStageIndex,
position: createTileCoordinates(slot, null)
};
yield put(BoardActions.piecesUpdated(newBoard));
yield put(BenchActions.benchPiecesUpdated(newBench));
yield put(BenchActions.benchPieceAdded(newPiece));
}
)
yield takeLatest(GAME_PHASE_UPDATE, function*(action) {
const phaseLength = Constants.PHASE_LENGTHS[action.payload.phase];
if (phaseLength) {
yield put(phaseTimerUpdated(phaseLength));
const channel = yield call(countdown, phaseLength);
yield takeEvery(channel, function*(secs: number) {
yield put(phaseTimerUpdated(secs));
});
}
});
};
function*(action) {
const pieces = (action.payload as any).payload.pieces;
yield put(BoardActions.piecesUpdated(pieces));
yield put(LockEvolutionActions.lockEvolutionAction());
}
),
function* filterUpdatableEntity(action: LoadEntitySuccess) {
const recognizer: PatternRecognizer = (yield getContext(ReduxTypes.Context)).get(
PatternTypes.Recognizer
);
const updatable: Updatable | undefined = recognizer.recognizeUniqueProperty(
action.payload.entity,
prop => !!(prop as Updatable).update
);
if (updatable) {
const accessControlAction: LoadAccessControl = {
type: LOAD_ACCESS_CONTROL,
payload: action.payload
};
yield put(accessControlAction);
}
}