diff --git a/src/features/browser/BrowserWebViewScreen.tsx b/src/features/browser/BrowserWebViewScreen.tsx index 72a6c9612..775dbf2f1 100644 --- a/src/features/browser/BrowserWebViewScreen.tsx +++ b/src/features/browser/BrowserWebViewScreen.tsx @@ -99,7 +99,7 @@ const BrowserWebViewScreen = () => { const decision = await walletSignBottomSheetRef.current?.show({ type, url: currentUrl, - serializedTxs: undefined, + serializedTxs: [], }) if (!decision) { @@ -122,7 +122,7 @@ const BrowserWebViewScreen = () => { const decision = await walletSignBottomSheetRef?.current?.show({ type, url: currentUrl, - serializedTxs: undefined, + serializedTxs: [], }) if (!decision) { @@ -254,12 +254,13 @@ const BrowserWebViewScreen = () => { ), ) - const txBuffers: Buffer[] = inputs.map( - ({ transaction }: SolanaSignAndSendTransactionInput) => - new Uint8Array( + const txBuffers: { tx: Buffer }[] = inputs.map( + ({ transaction }: SolanaSignAndSendTransactionInput) => ({ + tx: new Uint8Array( // eslint-disable-next-line @typescript-eslint/no-explicit-any Object.keys(transaction).map((k) => (transaction as any)[k]), ), + }), ) const decision = await walletSignBottomSheetRef.current?.show({ @@ -329,7 +330,7 @@ const BrowserWebViewScreen = () => { const decision = await walletSignBottomSheetRef.current?.show({ type, url: currentUrl, - serializedTxs: undefined, + serializedTxs: [], }) if (!decision) { diff --git a/src/features/collectables/AssertLocationScreen.tsx b/src/features/collectables/AssertLocationScreen.tsx index ae58c7c3c..032123b09 100644 --- a/src/features/collectables/AssertLocationScreen.tsx +++ b/src/features/collectables/AssertLocationScreen.tsx @@ -21,7 +21,7 @@ import useAlert from '@hooks/useAlert' import { useForwardGeo } from '@hooks/useForwardGeo' import { useReverseGeo } from '@hooks/useReverseGeo' import useSubmitTxn from '@hooks/useSubmitTxn' -import { RouteProp, useRoute } from '@react-navigation/native' +import { RouteProp, useNavigation, useRoute } from '@react-navigation/native' import MapboxGL from '@rnmapbox/maps' import turfBbox from '@turf/bbox' import { points } from '@turf/helpers' @@ -82,6 +82,7 @@ const AssertLocationScreen = () => { const reverseGeo = useReverseGeo(mapCenter) const forwardGeo = useForwardGeo() const { submitUpdateEntityInfo } = useSubmitTxn() + const nav = useNavigation() const { content: { metadata }, @@ -260,6 +261,12 @@ const AssertLocationScreen = () => { decimalGain: gain, }) setAsserting(false) + + await showOKAlert({ + title: t('assertLocationScreen.success.title'), + message: t('assertLocationScreen.success.message'), + }) + nav.goBack() } catch (error) { setAsserting(false) Logger.error(error) @@ -267,15 +274,15 @@ const AssertLocationScreen = () => { } }, [ - entityKey, mapCenter, - elevation, - gain, + entityKey, hideElevGain, - setAsserting, - setTransactionError, submitUpdateEntityInfo, - // nav, + elevation, + gain, + showOKAlert, + t, + nav, ], ) diff --git a/src/hooks/useSubmitTxn.ts b/src/hooks/useSubmitTxn.ts index 263df8a50..b4f7b0d65 100644 --- a/src/hooks/useSubmitTxn.ts +++ b/src/hooks/useSubmitTxn.ts @@ -71,11 +71,11 @@ export default () => { type: WalletStandardMessageTypes.signTransaction, url: '', additionalMessage: t('transactions.signPaymentTxn'), - serializedTxs: txns.map((tx) => - tx.serialize({ + serializedTxs: txns.map((tx) => ({ + tx: tx.serialize({ requireAllSignatures: false, }), - ), + })), }) if (!decision) { @@ -138,7 +138,7 @@ export default () => { type: WalletStandardMessageTypes.signTransaction, url: '', additionalMessage: t('transactions.signTransferCollectableTxn'), - serializedTxs: [Buffer.from(serializedTx)], + serializedTxs: [{ tx: Buffer.from(serializedTx) }], }) if (!decision) { @@ -191,7 +191,7 @@ export default () => { url: '', warning: recipientExists ? '' : t('transactions.recipientNonExistent'), additionalMessage: t('transactions.signSwapTxn'), - serializedTxs: [Buffer.from(serializedTx)], + serializedTxs: [{ tx: Buffer.from(serializedTx) }], }) if (!decision) { @@ -230,7 +230,7 @@ export default () => { type: WalletStandardMessageTypes.signTransaction, url: '', additionalMessage: t('transactions.signGenericTxn'), - serializedTxs: [Buffer.from(serializedTx)], + serializedTxs: [{ tx: Buffer.from(serializedTx) }], }) if (!decision) { @@ -272,7 +272,7 @@ export default () => { type: WalletStandardMessageTypes.signTransaction, url: '', additionalMessage: t('transactions.signClaimRewardsTxn'), - serializedTxs: serializedTxs.map(Buffer.from), + serializedTxs: serializedTxs.map((tx) => ({ tx: Buffer.from(tx) })), }) if (!decision) { @@ -361,7 +361,7 @@ export default () => { url: '', warning: recipientExists ? '' : t('transactions.recipientNonExistent'), additionalMessage: t('transactions.signMintDataCreditsTxn'), - serializedTxs: [Buffer.from(serializedTx)], + serializedTxs: [{ tx: Buffer.from(serializedTx) }], }) if (!decision) { @@ -413,7 +413,7 @@ export default () => { type: WalletStandardMessageTypes.signTransaction, url: '', additionalMessage: t('transactions.signDelegateDCTxn'), - serializedTxs: [Buffer.from(serializedTx)], + serializedTxs: [{ tx: Buffer.from(serializedTx) }], }) if (!decision) { @@ -472,9 +472,13 @@ export default () => { throw new Error('Failed to get assert data') } - const serializedTxs = assertData.solanaTransactions.map((txn) => - Buffer.from(txn, 'base64'), - ) + // If there's more than one txn, the first item is the burn txn. We only want to check for insufficient funds on it + const includesBurn = assertData.solanaTransactions.length > 1 + + const serializedTxs = assertData.solanaTransactions.map((txn, index) => ({ + tx: Buffer.from(txn, 'base64'), + ignoreInsufficientFunds: includesBurn && index !== 0, + })) const decision = await walletSignBottomSheetRef.show({ type: WalletStandardMessageTypes.signTransaction, @@ -487,7 +491,7 @@ export default () => { throw new Error('User rejected transaction') } - const txns = serializedTxs.map((tx) => Transaction.from(tx)) + const txns = serializedTxs.map((tx) => Transaction.from(tx.tx)) if (type === 'IOT') { await dispatch( diff --git a/src/locales/en.ts b/src/locales/en.ts index db630f4d0..601d3bcc1 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -323,6 +323,10 @@ export default { elevationPlaceholder: 'Elevation (meters)', locationNotFound: 'Location not found, Please try again.', mobileTitle: 'MOBILE', + success: { + title: 'Location Asserted!', + message: 'Location has successfully been asserted.', + }, }, antennaSetupScreen: { title: 'Antenna Setup', diff --git a/src/solana/WalletSignBottomSheet.tsx b/src/solana/WalletSignBottomSheet.tsx index 2eebe573a..8b56f81c2 100644 --- a/src/solana/WalletSignBottomSheet.tsx +++ b/src/solana/WalletSignBottomSheet.tsx @@ -61,19 +61,19 @@ const WalletSignBottomSheet = forwardRef( type: WalletStandardMessageTypes.connect, url: '', additionalMessage: '', - serializedTxs: undefined, + serializedTxs: [], }) const itemsPerPage = 5 const [currentPage, setCurrentPage] = useState(1) const [currentTxs, hasMore] = useMemo(() => { const totalPages = Math.ceil( - (walletSignOpts?.serializedTxs?.length || 0) / itemsPerPage, + (walletSignOpts.serializedTxs.length || 0) / itemsPerPage, ) const more = currentPage < totalPages - let scopedTxs + let scopedTxs: { tx: Buffer; ignoreInsufficientFunds?: boolean }[] = [] - if (walletSignOpts.serializedTxs) { + if (walletSignOpts.serializedTxs.length) { const endIndex = currentPage * itemsPerPage scopedTxs = walletSignOpts.serializedTxs.slice(0, endIndex) } @@ -88,7 +88,7 @@ const WalletSignBottomSheet = forwardRef( const estimatedTotalSolByLamports = useMemo(() => { const { serializedTxs } = walletSignOpts - if (serializedTxs) { + if (serializedTxs.length) { if (currentTxs && currentTxs.length < serializedTxs.length) { // we have unsimulated transactions, do rough estimate const diff = serializedTxs.length - currentTxs.length @@ -255,7 +255,7 @@ const WalletSignBottomSheet = forwardRef( color="secondaryText" textAlign="center" > - {walletSignOpts?.url || ''} + {walletSignOpts.url || ''} @@ -359,9 +359,7 @@ const WalletSignBottomSheet = forwardRef( 1 - ? 214 - : 180 + (walletSignOpts.serializedTxs.length || 0) > 1 ? 214 : 180 } paddingTop="m" > @@ -384,21 +382,23 @@ const WalletSignBottomSheet = forwardRef( {isVisible && currentTxs && ( 1 + (walletSignOpts.serializedTxs.length || 0) > 1 } > {currentTxs.map((tx, idx) => ( ))} diff --git a/src/solana/WalletSignBottomSheetTransaction.tsx b/src/solana/WalletSignBottomSheetTransaction.tsx index fde0b60e8..1f8af0e89 100644 --- a/src/solana/WalletSignBottomSheetTransaction.tsx +++ b/src/solana/WalletSignBottomSheetTransaction.tsx @@ -18,7 +18,7 @@ const WalletSignBottomSheetTransaction = ({ transactionIdx: number totalTransactions: number incrementTotalSolFee: (fee: number) => void - setNestedInsufficentFunds: React.Dispatch> + setNestedInsufficentFunds?: React.Dispatch> }) => { const { anchorProvider } = useSolana() const { t } = useTranslation() @@ -33,7 +33,7 @@ const WalletSignBottomSheetTransaction = ({ useEffect(() => { if (insufficientFunds) { - setNestedInsufficentFunds(true) + setNestedInsufficentFunds?.(true) } }, [insufficientFunds, setNestedInsufficentFunds]) diff --git a/src/solana/walletSignBottomSheetTypes.tsx b/src/solana/walletSignBottomSheetTypes.tsx index cd538500a..259d21a61 100644 --- a/src/solana/walletSignBottomSheetTypes.tsx +++ b/src/solana/walletSignBottomSheetTypes.tsx @@ -16,7 +16,7 @@ export type BalanceChange = { export type WalletSignOpts = { type: WalletStandardMessageTypes url: string - serializedTxs: Buffer[] | undefined + serializedTxs: { tx: Buffer; ignoreInsufficientFunds?: boolean }[] warning?: string additionalMessage?: string }