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

fix: show nfc button when nfc is available #2836

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/screens/receive.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jest.mock("react-native-nfc-manager", () => {
start: jest.fn(),
stop: jest.fn(),
},
isSupported: jest.fn(),
}
})

Expand Down
37 changes: 22 additions & 15 deletions app/screens/receive-bitcoin-screen/receive-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SetLightningAddressModal } from "@app/components/set-lightning-address-
import { GaloyCurrencyBubble } from "@app/components/atomic/galoy-currency-bubble"
import { ModalNfc } from "@app/components/modal-nfc"
import { CustomIcon } from "@app/components/custom-icon"
import nfcManager from "react-native-nfc-manager"

const ReceiveScreen = () => {
const {
Expand All @@ -37,21 +38,27 @@ const ReceiveScreen = () => {
const [displayReceiveNfc, setDisplayReceiveNfc] = useState(false)

useEffect(() => {
if (request?.type === "Lightning" && request?.state === "Created")
navigation.setOptions({
headerRight: () => (
<TouchableOpacity
style={styles.nfcIcon}
onPress={() => setDisplayReceiveNfc(true)}
>
<Text type="p2">{LL.ReceiveScreen.nfc()}</Text>
<CustomIcon name="nfc" color={colors.black} />
</TouchableOpacity>
),
})
else {
navigation.setOptions({ headerRight: () => <></> })
}
;(async () => {
if (
request?.type === "Lightning" &&
request?.state === "Created" &&
(await nfcManager.isSupported())
)
navigation.setOptions({
headerRight: () => (
<TouchableOpacity
style={styles.nfcIcon}
onPress={() => setDisplayReceiveNfc(true)}
>
<Text type="p2">{LL.ReceiveScreen.nfc()}</Text>
<CustomIcon name="nfc" color={colors.black} />
</TouchableOpacity>
),
})
else {
navigation.setOptions({ headerRight: () => <></> })
}
})()
}, [
LL.ReceiveScreen,
colors.black,
Expand Down