Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wallet_switchStarknetChain request method #656

Merged
merged 6 commits into from
May 23, 2022
Merged
Prev Previous commit
Next Next commit
refactor: make onReject and onSubmit reusable with useCallback
  • Loading branch information
dhruvkelawala committed May 23, 2022
commit 537b937d087ec39b35e8627c32cd7e428a476d0a
87 changes: 26 additions & 61 deletions packages/extension/src/ui/features/actions/ActionScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from "react"
import { FC, useCallback } from "react"
import { useNavigate } from "react-router-dom"

import { waitForMessage } from "../../../shared/messages"
Expand All @@ -22,23 +22,28 @@ export const ActionScreen: FC = () => {

const [action] = actions
const isLastAction = actions.length === 1

const onSubmit = useCallback(async () => {
await approve(action)
if (isPopup && isLastAction) {
window.close()
}
}, [])

const onReject = useCallback(async () => {
await reject(action)
if (isPopup && isLastAction) {
window.close()
}
}, [])

switch (action.type) {
case "CONNECT_DAPP":
return (
<ConnectDappScreen
host={action.payload.host}
onReject={async () => {
await reject(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onSubmit={async () => {
await approve(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onReject={onReject}
onSubmit={onSubmit}
/>
)

Expand All @@ -47,18 +52,8 @@ export const ActionScreen: FC = () => {
<AddTokenScreen
defaultToken={action.payload}
hideBackButton
onSubmit={async () => {
await approve(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onReject={async () => {
await reject(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onSubmit={onSubmit}
onReject={onReject}
/>
)

Expand All @@ -67,18 +62,8 @@ export const ActionScreen: FC = () => {
<AddNetworkScreen
requestedNetwork={action.payload}
hideBackButton
onSubmit={async () => {
await approve(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onReject={async () => {
await reject(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onSubmit={onSubmit}
onReject={onReject}
/>
)

Expand All @@ -88,18 +73,8 @@ export const ActionScreen: FC = () => {
requestedNetwork={action.payload}
mode={"switch"}
delaaxe marked this conversation as resolved.
Show resolved Hide resolved
hideBackButton
onSubmit={async () => {
await approve(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onReject={async () => {
await reject(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onSubmit={onSubmit}
onReject={onReject}
/>
)

Expand Down Expand Up @@ -134,12 +109,7 @@ export const ActionScreen: FC = () => {
useAppState.setState({ isLoading: false })
}
}}
onReject={async () => {
await reject(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onReject={onReject}
selectedAccount={account}
/>
)
Expand All @@ -160,12 +130,7 @@ export const ActionScreen: FC = () => {
}
useAppState.setState({ isLoading: false })
}}
onReject={async () => {
await reject(action)
if (isPopup && isLastAction) {
window.close()
}
}}
onReject={onReject}
selectedAccount={account}
/>
)
Expand Down