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

feat(#547): Add ability to pay onboarding fees if maker has no DC #552

Merged
merged 6 commits into from
Dec 13, 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 .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
jest: true,
},
rules: {
'import/no-cycle': 0,
'import/no-named-as-default': 0,
'prefer-exponentiation-operator': 'off',
'prettier/prettier': 'error',
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ target 'HeliumWallet' do
target.build_configurations.each do |config|
config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
end
end

end
end

Expand All @@ -110,4 +110,4 @@ end

target 'HeliumWalletWidgetExtension' do
pod 'react-native-config/Extension', :path => '../node_modules/react-native-config'
end
end
8 changes: 4 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ PODS:
- ReactCommon/turbomodule/core (= 0.71.5)
- fmt (6.2.1)
- glog (0.3.5)
- helium-react-native-sdk (3.0.0):
- helium-react-native-sdk (3.0.1):
- React-Core
- hermes-engine (0.71.5):
- hermes-engine/Pre-built (= 0.71.5)
Expand Down Expand Up @@ -875,7 +875,7 @@ SPEC CHECKSUMS:
FBReactNativeSpec: 627fd07f1b9d498c9fa572e76d7f1a6b1ee9a444
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
helium-react-native-sdk: 17b612b2dacebc8f10c18ba5611f200a81c940f9
helium-react-native-sdk: d78defa39b0340669bb7d2bbd05db3b00e393f2d
hermes-engine: 0784cadad14b011580615c496f77e0ae112eed75
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
lottie-ios: 25e7b2675dad5c3ddad369ac9baab03560c5bfdd
Expand Down Expand Up @@ -955,6 +955,6 @@ SPEC CHECKSUMS:
Yoga: cd7d7f509dbfac14ee7f31a6c750acb957cd5022
ZXingObjC: 8898711ab495761b2dbbdec76d90164a6d7e14c5

PODFILE CHECKSUM: 5b4d3c6d9c5a303c84f0b5427958ba4a25671e76
PODFILE CHECKSUM: ca81fc3ff2cc73a5ab3e1674a7d2281321c928fb

COCOAPODS: 1.12.1
COCOAPODS: 1.11.3
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"@helium/http": "4.7.5",
"@helium/idls": "^0.4.0",
"@helium/lazy-distributor-sdk": "^0.4.0",
"@helium/onboarding": "4.9.0",
"@helium/onboarding": "^4.10.3",
"@helium/proto-ble": "4.0.0",
"@helium/react-native-sdk": "^3.0.0",
"@helium/react-native-sdk": "^3.0.2",
"@helium/spl-utils": "^0.4.0",
"@helium/transactions": "4.8.1",
"@helium/treasury-management-sdk": "^0.4.0",
Expand Down
49 changes: 49 additions & 0 deletions src/components/RadioButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Box from '@components/Box'
import Text from '@components/Text'
import TouchableOpacityBox from '@components/TouchableOpacityBox'
import React from 'react'

type RadioButtonProps = {
label: string
selected: boolean
onClick: () => void
}

const RadioButton: React.FC<RadioButtonProps> = ({
label,
selected,
onClick,
}) => {
return (
<Box
mt="l"
flexDirection="row"
alignItems="flex-start"
justifyContent="flex-start"
>
<TouchableOpacityBox
mr="s"
height={20}
width={20}
borderRadius="round"
borderWidth={2}
borderColor="blueBright500"
alignItems="center"
justifyContent="center"
onPress={() => onClick()}
>
<Box
width={10}
height={10}
borderRadius="round"
backgroundColor={selected ? 'blueBright500' : 'transparent'}
/>
</TouchableOpacityBox>
<Text width="90%" onPress={() => onClick()} color="white">
{label}
</Text>
</Box>
)
}

export default RadioButton
2 changes: 1 addition & 1 deletion src/features/collectables/AntennaSetupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const AntennaSetupScreen = () => {
setUpdating(true)
try {
await submitUpdateEntityInfo({
type: 'iot',
type: 'IOT',
entityKey,
lng: iotLocation[0],
lat: iotLocation[1],
Expand Down
87 changes: 81 additions & 6 deletions src/features/collectables/AssertLocationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ import {
} from '@components'
import TouchableOpacityBox from '@components/TouchableOpacityBox'
import { HotspotType } from '@helium/onboarding'
import { IOT_MINT, MOBILE_MINT } from '@helium/spl-utils'
import useAlert from '@hooks/useAlert'
import { useCurrentWallet } from '@hooks/useCurrentWallet'
import { useEntityKey } from '@hooks/useEntityKey'
import { useForwardGeo } from '@hooks/useForwardGeo'
import { useImplicitBurn } from '@hooks/useImplicitBurn'
import { useIotInfo } from '@hooks/useIotInfo'
import { useMobileInfo } from '@hooks/useMobileInfo'
import { useOnboardingBalnces } from '@hooks/useOnboardingBalances'
import { useReverseGeo } from '@hooks/useReverseGeo'
import useSubmitTxn from '@hooks/useSubmitTxn'
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'
Expand All @@ -31,6 +35,7 @@ import { parseH3BNLocation } from '@utils/h3'
import { removeDashAndCapitalize } from '@utils/hotspotNftsUtils'
import * as Logger from '@utils/logger'
import { MAX_MAP_ZOOM, MIN_MAP_ZOOM } from '@utils/mapbox'
import BN from 'bn.js'
import debounce from 'lodash/debounce'
import React, {
memo,
Expand Down Expand Up @@ -83,7 +88,17 @@ const AssertLocationScreen = () => {
const forwardGeo = useForwardGeo()
const { submitUpdateEntityInfo } = useSubmitTxn()
const collectNav = useNavigation<CollectableNavigationProp>()

const {
maker,
makerDc,
myDcWithHnt,
loadingMyDc,
loadingMakerDc,
locationAssertDcRequirements,
loadingLocationAssertDcRequirements,
} = useOnboardingBalnces(entityKey)
const { implicitBurn } = useImplicitBurn()
const wallet = useCurrentWallet()
const {
content: { metadata },
} = collectable
Expand Down Expand Up @@ -219,19 +234,55 @@ const AssertLocationScreen = () => {

const assertLocation = useCallback(
async (type: HotspotType) => {
if (!mapCenter || !entityKey) return
if (
!mapCenter ||
!entityKey ||
loadingMakerDc ||
loadingLocationAssertDcRequirements ||
!wallet
)
return

setTransactionError(undefined)
setAsserting(true)
try {
hideElevGain()
const requiredDc =
locationAssertDcRequirements[
type === 'IOT' ? IOT_MINT.toBase58() : MOBILE_MINT.toBase58()
]
const insufficientMakerDcBal = (makerDc || new BN(0)).lt(requiredDc)
const insufficientMyDcBal =
!loadingMyDc && (myDcWithHnt || new BN(0)).lt(requiredDc)

let numLocationChanges = 0
if (type === 'IOT') {
numLocationChanges = iotInfoAcc?.numLocationAsserts || 0
} else {
numLocationChanges = mobileInfoAcc?.numLocationAsserts || 0
}
const isPayer =
insufficientMakerDcBal ||
!maker ||
numLocationChanges >= maker.locationNonceLimit
if (isPayer && insufficientMyDcBal) {
throw new Error(
t('assertLocationScreen.error.insufficientFunds', {
usd: requiredDc.toNumber() / 100000,
}),
)
}
if (isPayer) {
await implicitBurn(requiredDc.toNumber())
}
await submitUpdateEntityInfo({
type,
entityKey,
lng: mapCenter[0],
lat: mapCenter[1],
elevation,
decimalGain: gain,
payer: isPayer ? wallet.toBase58() : undefined,
})
setAsserting(false)

Expand All @@ -247,16 +298,27 @@ const AssertLocationScreen = () => {
}
},
[
maker,
implicitBurn,
wallet,
mapCenter,
entityKey,
loadingMakerDc,
loadingLocationAssertDcRequirements,
hideElevGain,
locationAssertDcRequirements,
makerDc,
loadingMyDc,
myDcWithHnt,
submitUpdateEntityInfo,
elevation,
gain,
showOKAlert,
t,
collectNav,
collectable,
iotInfoAcc?.numLocationAsserts,
mobileInfoAcc?.numLocationAsserts,
],
)

Expand All @@ -272,7 +334,7 @@ const AssertLocationScreen = () => {
},
{
text: 'Mobile',
onPress: async () => assertLocation('mobile'),
onPress: async () => assertLocation('MOBILE'),
},
{
text: t('generic.cancel'),
Expand All @@ -283,7 +345,7 @@ const AssertLocationScreen = () => {
} else {
// elevGainVisible
// we can assume user is asserting location from elevGain UI
await assertLocation('iot')
await assertLocation('IOT')
}
}, [t, elevGainVisible, assertLocation])

Expand All @@ -292,8 +354,21 @@ const AssertLocationScreen = () => {
}, [transactionError])

const disabled = useMemo(
() => !mapCenter || reverseGeo.loading || asserting,
[asserting, mapCenter, reverseGeo.loading],
() =>
!mapCenter ||
reverseGeo.loading ||
asserting ||
loadingLocationAssertDcRequirements ||
loadingMakerDc ||
loadingMyDc,
[
asserting,
mapCenter,
reverseGeo.loading,
loadingLocationAssertDcRequirements,
loadingMakerDc,
loadingMyDc,
],
)
const [debouncedDisabled] = useDebounce(disabled, 300)
const [reverseGeoLoading] = useDebounce(reverseGeo.loading, 300)
Expand Down
6 changes: 3 additions & 3 deletions src/features/collectables/HotspotDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,22 @@ const HotspotDetailsScreen = () => {
return
}
setOptionsOpen(false)
const hotspotType: 'iot' | 'mobile' | undefined = await new Promise(
const hotspotType: 'IOT' | 'MOBILE' | undefined = await new Promise(
(resolve) => {
const options: AlertButton[] = []
if (!iotInfoAcc?.info) {
options.push({
text: 'IOT',
onPress: () => {
resolve('iot')
resolve('IOT')
},
})
}
if (!mobileInfoAcc?.info) {
options.push({
text: 'MOBILE',
onPress: () => {
resolve('mobile')
resolve('MOBILE')
},
})
}
Expand Down
Loading
Loading