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

Set device type when creating hotspot in example project. #88

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 41 additions & 2 deletions example/src/CreateSolanaHotspot/CreateSolanaHotspot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const CreateSolanaHotspot = () => {
const [deepLinkScheme, setDeepLinkScheme] = useState('makerappscheme://')
const [submitted, setSubmitted] = useState(false)
const { txn, create } = useCreateHotspot()
const [deviceType, setDeviceType] = useState<
'Cbrs' | 'WifiIndoor' | 'WifiOutdoor' | 'IOT'
>('IOT')

useEffect(() => {
getAddressStr().then(setOwnerAddress)
Expand All @@ -44,15 +47,50 @@ const CreateSolanaHotspot = () => {
const createHotspot = useCallback(async () => {
setSubmitted(true)
try {
await create({ makerAddress, authorization, ownerAddress })
await create({
makerAddress,
authorization,
ownerAddress,
deviceType,
})
} catch (e) {
console.error(e)
}
setSubmitted(false)
}, [authorization, create, makerAddress, ownerAddress])
}, [authorization, create, makerAddress, ownerAddress, deviceType])

const updateDeviceType = useCallback(
(nextType: 'Cbrs' | 'WifiIndoor' | 'WifiOutdoor' | 'IOT') => () => {
setDeviceType(nextType)
},
[]
)

return (
<View style={styles.container}>
<Text>Device Type</Text>
<View style={styles.row}>
<Button
title="Cbrs"
color={deviceType === 'Cbrs' ? undefined : 'black'}
onPress={updateDeviceType('Cbrs')}
/>
<Button
title="IOT"
color={deviceType === 'IOT' ? undefined : 'black'}
onPress={updateDeviceType('IOT')}
/>
<Button
title="WifiIndoor"
color={deviceType === 'WifiIndoor' ? undefined : 'black'}
onPress={updateDeviceType('WifiIndoor')}
/>
<Button
title="WifiOutdoor"
color={deviceType === 'WifiOutdoor' ? undefined : 'black'}
onPress={updateDeviceType('WifiOutdoor')}
/>
</View>
<Input
title="Maker Address"
style={styles.innnerContainer}
Expand Down Expand Up @@ -126,6 +164,7 @@ const CreateSolanaHotspot = () => {
}

const styles = StyleSheet.create({
row: { flexDirection: 'row' },
container: {
margin: 24,
},
Expand Down
3 changes: 3 additions & 0 deletions example/src/CreateSolanaHotspot/useCreateHotspot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ const useCreateHotspot = () => {
authorization,
makerAddress,
ownerAddress,
deviceType,
}: {
ownerAddress?: string
makerAddress: string
authorization: string
deviceType: 'Cbrs' | 'WifiIndoor' | 'WifiOutdoor' | 'IOT'
}) => {
const gateway = await Keypair.makeRandom()
const maker = Address.fromB58(makerAddress)
Expand All @@ -45,6 +47,7 @@ const useCreateHotspot = () => {
rpiSerial: random(10),
heliumSerial: random(10),
batch: 'example-batch',
deviceType: deviceType === 'IOT' ? null : deviceType,
},
{
headers: {
Expand Down