connected-react-router#push TypeScript Examples
The following examples show how to use
connected-react-router#push.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateLandingPage.tsx From msteams-meetings-template with MIT License | 6 votes |
mapDispatchToProps = (dispatch: Dispatch) => ({
checkForSignedInUser: () =>
dispatch({
type: CHECK_FOR_SIGNEDIN_USER_COMMAND
}),
onNewMeeting: () => {
dispatch({
type: SET_MEETING_COMMAND,
meeting: createDefaultMeetingInput()
} as SetMeetingCommand);
dispatch(push('/createMeeting'));
}
})
Example #2
Source File: middleware.ts From msteams-meetings-template with MIT License | 6 votes |
export function createMeetingMiddleware(): Middleware {
const service = createMeetingService();
return store => next => action => {
if (action.type === CREATE_MEETING_COMMAND) {
service
.createMeeting(action.meeting)
.then(meeting => {
store.dispatch({
type: MEETING_CREATED_EVENT,
meeting
});
})
.catch(error => {
console.error('Create meeting failed: ', error);
store.dispatch(push('/error'));
});
}
if (action.type === MEETING_CREATED_EVENT) {
store.dispatch(push('/copyMeeting'));
}
next(action);
};
}
Example #3
Source File: saga.ts From rusty-chat with MIT License | 6 votes |
function* handleJoin(action: JoinUserAction): Generator<StrictEffect> {
yield put(apiActions.write(apiProto.join(action.payload.name)));
while (true) {
const read = (yield take(ApiActionType.Read)) as ReadApiAction;
if (read.payload.type === OutputType.Error) {
yield put(userActions.joined({ error: true, code: read.payload.payload.code }));
break;
} else if (read.payload.type === OutputType.Joined) {
const output = read.payload.payload;
yield put(userActions.joined({
error: false,
user: output.user,
others: output.others,
messages: output.messages,
}));
break;
}
}
yield put(push('/feed'));
}
Example #4
Source File: LeftMenuSidebar.tsx From rewind with MIT License | 5 votes |
export function LeftMenuSidebar() {
// const LinkBehavior = React.forwardRef((props, ref) => <Link ref={ref} to="/" {...props} role={undefined} />);
const dispatch = useAppDispatch();
const pathname = useAppSelector((state) => state.router.location.pathname);
const handleLinkClick = (to: string) => () => dispatch(push(to));
const buttonColor = (name: string) => (name === pathname ? "primary" : "default");
const updateState = useCheckForUpdate();
return (
<Stack
sx={{
width: (theme) => theme.spacing(10),
paddingBottom: 2,
}}
gap={1}
p={1}
alignItems={"center"}
component={"nav"}
>
<Box onClick={handleLinkClick("/home")} sx={{ cursor: "pointer" }}>
<RewindLogo />
</Box>
<Divider orientation={"horizontal"} sx={{ borderWidth: 1, width: "80%" }} />
<Tooltip title={"Overview"} placement={"right"}>
<IconButton color={buttonColor("/home")} onClick={handleLinkClick("/home")}>
<Home />
</IconButton>
</Tooltip>
<Tooltip title={"Analyzer"} placement={"right"}>
<IconButton
// These are not centered
onClick={handleLinkClick("/analyzer")}
color={buttonColor("/analyzer")}
>
<FaMicroscope height={"0.75em"} />
</IconButton>
</Tooltip>
{/*Nothing*/}
<Box flexGrow={1} />
{updateState.hasNewUpdate && (
<Tooltip title={`New version ${updateState.latestVersion} available!`} placement={"right"}>
<IconButton onClick={() => window.open(latestReleaseUrl)}>
<Badge variant={"dot"} color={"error"}>
<UpdateIcon />
</Badge>
</IconButton>
</Tooltip>
)}
</Stack>
);
}
Example #5
Source File: RootSaga.ts From rewind with MIT License | 5 votes |
function* watchForBackendReady(theater: RewindTheater): SagaIterator {
const { common, analyzer } = theater;
yield call(waitForBackendState, "READY");
yield call(common.initialize.bind(common));
yield call(analyzer.startWatching.bind(analyzer));
yield put(push("/analyzer")); // Theater
}
Example #6
Source File: RootSaga.ts From rewind with MIT License | 5 votes |
function* watchForBackendMissingSetup(): SagaIterator {
yield call(waitForBackendState, "SETUP_MISSING");
yield put(push("/setup"));
}
Example #7
Source File: main.tsx From rewind with MIT License | 5 votes |
async function initialize() {
let api: FrontendPreloadAPI;
if (window.api) {
api = window.api;
} else {
api = {
getAppVersion: () => Promise.resolve(environment.appVersion),
getPlatform: () => Promise.resolve(environment.platform),
reboot: () => console.log("Rebooting ..."),
selectDirectory: () => Promise.resolve("C:\\Mocked\\Path"),
selectFile: () => Promise.resolve("C:\\Mocked\\File.osr"),
onManualReplayOpen: (listener) => console.log(`Registered a listener for opening replay files manually`),
};
}
const [appVersion, platform] = await Promise.all([api.getAppVersion(), api.getPlatform()]);
const appInfo = { appVersion, platform };
console.log(`Initializing with version=${appVersion} on platform=${platform}`);
api.onManualReplayOpen((file) => {
// todo: refactor
// Changes to the analyzer page
store.dispatch(push("/analyzer"));
theater.analyzer.loadReplay(`local:${file}`);
});
ReactDOM.render(
<StrictMode>
<AppInfoProvider appInfo={appInfo}>
<Provider store={store}>
<ConnectedRouter history={history}>
<ThemeProvider theme={RewindTheme}>
<CssBaseline />
<TheaterProvider theater={theater}>
<RewindApp />
</TheaterProvider>
</ThemeProvider>
</ConnectedRouter>
</Provider>
</AppInfoProvider>
</StrictMode>,
document.getElementById("root"),
);
// This starts off with /splash -> Maybe do it somewhere else?
store.dispatch(push("/splash"));
}
Example #8
Source File: notificationsMiddleware.ts From multisig-react with MIT License | 5 votes |
onNotificationClicked = (dispatch, notificationKey, safeAddress) => () => {
dispatch(closeSnackbarAction({ key: notificationKey }))
dispatch(push(`/safes/${safeAddress}/transactions`))
}
Example #9
Source File: index.tsx From multisig-react with MIT License | 5 votes |
EllipsisTransactionDetails = ({
address,
knownAddress,
sendModalOpenHandler,
}: EllipsisTransactionDetailsProps): React.ReactElement => {
const classes = useStyles()
const [anchorEl, setAnchorEl] = React.useState(null)
const dispatch = useDispatch()
const currentSafeAddress = useSelector(safeParamAddressFromStateSelector)
const handleClick = (event) => setAnchorEl(event.currentTarget)
const closeMenuHandler = () => setAnchorEl(null)
const addOrEditEntryHandler = () => {
dispatch(push(`${SAFELIST_ADDRESS}/${currentSafeAddress}/address-book?entryAddress=${address}`))
closeMenuHandler()
}
return (
<ClickAwayListener onClickAway={closeMenuHandler}>
<div className={classes.container} role="menu" tabIndex={0}>
<MoreHorizIcon onClick={handleClick} onKeyDown={handleClick} />
<Menu anchorEl={anchorEl} id="simple-menu" keepMounted onClose={closeMenuHandler} open={Boolean(anchorEl)}>
{sendModalOpenHandler
? [
<MenuItem key="send-again-button" onClick={sendModalOpenHandler}>
Send Again
</MenuItem>,
<Divider key="divider" />,
]
: null}
{knownAddress ? (
<MenuItem onClick={addOrEditEntryHandler}>Edit Address book Entry</MenuItem>
) : (
<MenuItem onClick={addOrEditEntryHandler}>Add to address book</MenuItem>
)}
</Menu>
</div>
</ClickAwayListener>
)
}
Example #10
Source File: index.tsx From nouns-monorepo with GNU General Public License v3.0 | 5 votes |
ChainSubscriber: React.FC = () => {
const dispatch = useAppDispatch();
const loadState = async () => {
const wsProvider = new WebSocketProvider(config.app.wsRpcUri);
const nounsAuctionHouseContract = NounsAuctionHouseFactory.connect(
config.addresses.nounsAuctionHouseProxy,
wsProvider,
);
const bidFilter = nounsAuctionHouseContract.filters.AuctionBid(null, null, null, null);
const extendedFilter = nounsAuctionHouseContract.filters.AuctionExtended(null, null);
const createdFilter = nounsAuctionHouseContract.filters.AuctionCreated(null, null, null);
const settledFilter = nounsAuctionHouseContract.filters.AuctionSettled(null, null, null);
const processBidFilter = async (
nounId: BigNumberish,
sender: string,
value: BigNumberish,
extended: boolean,
event: any,
) => {
const timestamp = (await event.getBlock()).timestamp;
const transactionHash = event.transactionHash;
dispatch(
appendBid(reduxSafeBid({ nounId, sender, value, extended, transactionHash, timestamp })),
);
};
const processAuctionCreated = (
nounId: BigNumberish,
startTime: BigNumberish,
endTime: BigNumberish,
) => {
dispatch(
setActiveAuction(reduxSafeNewAuction({ nounId, startTime, endTime, settled: false })),
);
const nounIdNumber = BigNumber.from(nounId).toNumber();
dispatch(push(nounPath(nounIdNumber)));
dispatch(setOnDisplayAuctionNounId(nounIdNumber));
dispatch(setLastAuctionNounId(nounIdNumber));
};
const processAuctionExtended = (nounId: BigNumberish, endTime: BigNumberish) => {
dispatch(setAuctionExtended({ nounId, endTime }));
};
const processAuctionSettled = (nounId: BigNumberish, winner: string, amount: BigNumberish) => {
dispatch(setAuctionSettled({ nounId, amount, winner }));
};
// Fetch the current auction
const currentAuction = await nounsAuctionHouseContract.auction();
dispatch(setFullAuction(reduxSafeAuction(currentAuction)));
dispatch(setLastAuctionNounId(currentAuction.nounId.toNumber()));
// Fetch the previous 24hours of bids
const previousBids = await nounsAuctionHouseContract.queryFilter(bidFilter, 0 - BLOCKS_PER_DAY);
for (let event of previousBids) {
if (event.args === undefined) return;
processBidFilter(...(event.args as [BigNumber, string, BigNumber, boolean]), event);
}
nounsAuctionHouseContract.on(bidFilter, (nounId, sender, value, extended, event) =>
processBidFilter(nounId, sender, value, extended, event),
);
nounsAuctionHouseContract.on(createdFilter, (nounId, startTime, endTime) =>
processAuctionCreated(nounId, startTime, endTime),
);
nounsAuctionHouseContract.on(extendedFilter, (nounId, endTime) =>
processAuctionExtended(nounId, endTime),
);
nounsAuctionHouseContract.on(settledFilter, (nounId, winner, amount) =>
processAuctionSettled(nounId, winner, amount),
);
};
loadState();
return <></>;
}
Example #11
Source File: index.tsx From nouns-monorepo with GNU General Public License v3.0 | 5 votes |
AuctionPage: React.FC<AuctionPageProps> = props => {
const { initialAuctionId } = props;
const onDisplayAuction = useOnDisplayAuction();
const lastAuctionNounId = useAppSelector(state => state.onDisplayAuction.lastAuctionNounId);
const onDisplayAuctionNounId = onDisplayAuction?.nounId.toNumber();
const dispatch = useAppDispatch();
useEffect(() => {
if (!lastAuctionNounId) return;
if (initialAuctionId !== undefined) {
// handle out of bounds noun path ids
if (initialAuctionId > lastAuctionNounId || initialAuctionId < 0) {
dispatch(setOnDisplayAuctionNounId(lastAuctionNounId));
dispatch(push(nounPath(lastAuctionNounId)));
} else {
if (onDisplayAuction === undefined) {
// handle regular noun path ids on first load
dispatch(setOnDisplayAuctionNounId(initialAuctionId));
}
}
} else {
// no noun path id set
if (lastAuctionNounId) {
dispatch(setOnDisplayAuctionNounId(lastAuctionNounId));
}
}
}, [lastAuctionNounId, dispatch, initialAuctionId, onDisplayAuction]);
return (
<>
<Auction auction={onDisplayAuction} />
{onDisplayAuctionNounId !== undefined && onDisplayAuctionNounId !== lastAuctionNounId ? (
<ProfileActivityFeed nounId={onDisplayAuctionNounId} />
) : (
<Banner />
)}
<Documentation />
</>
);
}
Example #12
Source File: createTransaction.ts From multisig-react with MIT License | 4 votes |
createTransaction = (
{
safeAddress,
to,
valueInWei,
txData = EMPTY_DATA,
notifiedTransaction,
txNonce,
operation = CALL,
navigateToTransactionsTab = true,
origin = null,
safeTxGas: safeTxGasArg,
}: CreateTransactionArgs,
onUserConfirm?: ConfirmEventHandler,
onError?: ErrorEventHandler,
): CreateTransactionAction => async (dispatch: Dispatch, getState: () => AppReduxState): Promise<DispatchReturn> => {
const state = getState()
if (navigateToTransactionsTab) {
dispatch(push(`${SAFELIST_ADDRESS}/${safeAddress}/transactions`))
}
const ready = await onboardUser()
if (!ready) return
const { account: from, hardwareWallet, smartContractWallet } = providerSelector(state)
const safeInstance = await getGnosisSafeInstanceAt(safeAddress)
const lastTx = await getLastTx(safeAddress)
const nonce = txNonce ? txNonce.toString() : await getNewTxNonce(lastTx, safeInstance)
const isExecution = await shouldExecuteTransaction(safeInstance, nonce, lastTx)
const safeVersion = await getCurrentSafeVersion(safeInstance)
let safeTxGas
try {
safeTxGas =
safeTxGasArg || (await estimateGasForTransactionCreation(safeAddress, txData, to, valueInWei, operation))
} catch (error) {
safeTxGas = safeTxGasArg || 0
}
const sigs = getPreValidatedSignatures(from)
const notificationsQueue = getNotificationsFromTxType(notifiedTransaction, origin)
const beforeExecutionKey = dispatch(enqueueSnackbar(notificationsQueue.beforeExecution))
let pendingExecutionKey
let txHash
const txArgs: TxArgs = {
safeInstance,
to,
valueInWei,
data: txData,
operation,
nonce: Number.parseInt(nonce),
safeTxGas,
baseGas: 0,
gasPrice: '0',
gasToken: ZERO_ADDRESS,
refundReceiver: ZERO_ADDRESS,
sender: from,
sigs,
}
const safeTxHash = generateSafeTxHash(safeAddress, txArgs)
try {
if (checkIfOffChainSignatureIsPossible(isExecution, smartContractWallet, safeVersion)) {
const signature = await tryOffchainSigning(safeTxHash, { ...txArgs, safeAddress }, hardwareWallet)
if (signature) {
dispatch(closeSnackbarAction({ key: beforeExecutionKey }))
dispatch(enqueueSnackbar(notificationsQueue.afterExecution.moreConfirmationsNeeded))
dispatch(fetchTransactions(safeAddress))
await saveTxToHistory({ ...txArgs, signature, origin })
onUserConfirm?.(safeTxHash)
return
}
}
const tx = isExecution ? getExecutionTransaction(txArgs) : getApprovalTransaction(safeInstance, safeTxHash)
const sendParams: PayableTx = { from, value: 0 }
// if not set owner management tests will fail on ganache
if (process.env.NODE_ENV === 'test') {
sendParams.gas = '7000000'
}
const txToMock: TxToMock = {
...txArgs,
confirmations: [], // this is used to determine if a tx is pending or not. See `calculateTransactionStatus` helper
value: txArgs.valueInWei,
safeTxHash,
dataDecoded: decodeMethods(txArgs.data),
submissionDate: new Date().toISOString(),
}
const mockedTx = await mockTransaction(txToMock, safeAddress, state)
await tx
.send(sendParams)
.once('transactionHash', async (hash) => {
onUserConfirm?.(safeTxHash)
try {
txHash = hash
dispatch(closeSnackbarAction({ key: beforeExecutionKey }))
pendingExecutionKey = dispatch(enqueueSnackbar(notificationsQueue.pendingExecution))
await Promise.all([
saveTxToHistory({ ...txArgs, txHash, origin }),
storeSignedTx({ transaction: mockedTx, from, isExecution, safeAddress, dispatch, state }),
])
dispatch(fetchTransactions(safeAddress))
} catch (e) {
removeTxFromStore(mockedTx, safeAddress, dispatch, state)
}
})
.on('error', (error) => {
dispatch(closeSnackbarAction({ key: pendingExecutionKey }))
removeTxFromStore(mockedTx, safeAddress, dispatch, state)
console.error('Tx error: ', error)
onError?.()
})
.then(async (receipt) => {
if (pendingExecutionKey) {
dispatch(closeSnackbarAction({ key: pendingExecutionKey }))
}
dispatch(
enqueueSnackbar(
isExecution
? notificationsQueue.afterExecution.noMoreConfirmationsNeeded
: notificationsQueue.afterExecution.moreConfirmationsNeeded,
),
)
await storeExecutedTx({ transaction: mockedTx, from, safeAddress, isExecution, receipt, dispatch, state })
dispatch(fetchTransactions(safeAddress))
return receipt.transactionHash
})
} catch (err) {
const errorMsg = err.message
? `${notificationsQueue.afterExecutionError.message} - ${err.message}`
: notificationsQueue.afterExecutionError.message
dispatch(closeSnackbarAction({ key: beforeExecutionKey }))
if (pendingExecutionKey) {
dispatch(closeSnackbarAction({ key: pendingExecutionKey }))
}
dispatch(enqueueSnackbar({ key: err.code, message: errorMsg, options: { persist: true, variant: 'error' } }))
if (err.code !== METAMASK_REJECT_CONFIRM_TX_ERROR_CODE) {
const executeDataUsedSignatures = safeInstance.methods
.execTransaction(to, valueInWei, txData, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs)
.encodeABI()
const errMsg = await getErrorMessage(safeInstance.options.address, 0, executeDataUsedSignatures, from)
console.error(`Error creating the TX - an attempt to get the error message: ${errMsg}`)
}
}
return txHash
}
Example #13
Source File: notificationsMiddleware.ts From multisig-react with MIT License | 4 votes |
notificationsMiddleware = (store) => (next) => async (action) => {
const handledAction = next(action)
const { dispatch } = store
if (watchedActions.includes(action.type)) {
const state = store.getState()
switch (action.type) {
case ADD_OR_UPDATE_TRANSACTIONS: {
const { safeAddress, transactions } = action.payload
const userAddress: string = userAccountSelector(state)
const cancellationTransactions = safeCancellationTransactionsSelector(state)
const awaitingTransactions = getAwaitingTransactions(transactions, cancellationTransactions, userAddress)
const awaitingTxsSubmissionDateList = awaitingTransactions.map((tx) => tx.submissionDate)
const safes = safesMapSelector(state)
const currentSafe = safes.get(safeAddress)
if (!currentSafe || !isUserAnOwner(currentSafe, userAddress) || awaitingTransactions.size === 0) {
break
}
const notificationKey = `${safeAddress}-awaiting`
await sendAwaitingTransactionNotification(
dispatch,
safeAddress,
awaitingTxsSubmissionDateList,
notificationKey,
onNotificationClicked(dispatch, notificationKey, safeAddress),
)
break
}
case ADD_INCOMING_TRANSACTIONS: {
action.payload.forEach((incomingTransactions, safeAddress) => {
const { latestIncomingTxBlock } = state.safes.get('safes').get(safeAddress, {})
const viewedSafes = state.currentSession['viewedSafes']
const recurringUser = viewedSafes?.includes(safeAddress)
const newIncomingTransactions = incomingTransactions.filter((tx) => tx.blockNumber > latestIncomingTxBlock)
const { message, ...TX_INCOMING_MSG } = NOTIFICATIONS.TX_INCOMING_MSG
if (recurringUser) {
if (newIncomingTransactions.size > 3) {
dispatch(
enqueueSnackbar(
enhanceSnackbarForAction({
...TX_INCOMING_MSG,
message: 'Multiple incoming transfers',
}),
),
)
} else {
newIncomingTransactions.forEach((tx) => {
dispatch(
enqueueSnackbar(
enhanceSnackbarForAction({
...TX_INCOMING_MSG,
message: `${message}${getIncomingTxAmount(tx)}`,
}),
),
)
})
}
}
dispatch(
updateSafe({
address: safeAddress,
latestIncomingTxBlock: newIncomingTransactions.size
? newIncomingTransactions.first().blockNumber
: latestIncomingTxBlock,
}),
)
})
break
}
case ADD_OR_UPDATE_SAFE: {
const state = store.getState()
const { safe } = action.payload
const currentSafeAddress = safeParamAddressFromStateSelector(state) || safe.address
if (!currentSafeAddress) {
break
}
const isUserOwner = grantedSelector(state)
const { needUpdate } = await getSafeVersionInfo(currentSafeAddress)
const notificationKey = `${currentSafeAddress}`
const onNotificationClicked = () => {
dispatch(closeSnackbarAction({ key: notificationKey }))
dispatch(push(`/safes/${currentSafeAddress}/settings`))
}
if (needUpdate && isUserOwner) {
dispatch(
enqueueSnackbar(
enhanceSnackbarForAction(
NOTIFICATIONS.SAFE_NEW_VERSION_AVAILABLE,
notificationKey,
onNotificationClicked,
),
),
)
}
break
}
default:
break
}
}
return handledAction
}