Skip to content

Commit

Permalink
Merge pull request #4707 from EdgeApp/paul/fiatPluginCamera
Browse files Browse the repository at this point in the history
Get camera permission for paybis and banxa
  • Loading branch information
paullinator authored Jan 12, 2024
2 parents adfe6bd + 9e3b8a0 commit 729d2f9
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/actions/DeepLinkingActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function retryPendingDeepLink(navigation: NavigationBase): ThunkAction<vo
* Launches a link if it app is able to do so.
*/
export async function handleLink(navigation: NavigationBase, dispatch: Dispatch, state: RootState, link: DeepLink): Promise<boolean> {
const { account } = state.core
const { account, disklet } = state.core
const { accountReferral } = state.account
const { activeWalletIds, currencyWallets } = account
const deviceId = base58ToUuid(state.core.context.clientId)
Expand Down Expand Up @@ -123,6 +123,7 @@ export async function handleLink(navigation: NavigationBase, dispatch: Dispatch,
accountReferral,
deviceId,
disablePlugins: disableProviders,
disklet,
guiPlugin: plugin,
direction,
regionCode: { countryCode: state.ui.settings.countryCode },
Expand Down
3 changes: 2 additions & 1 deletion src/actions/PluginActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { base58ToUuid } from '../util/utils'
export function executePluginAction(navigation: NavigationBase, pluginId: string, direction: 'buy' | 'sell'): ThunkAction<Promise<void>> {
return async (dispatch, getState) => {
const state = getState()
const { account, context } = state.core
const { account, context, disklet } = state.core
const { accountReferral } = state.account
const deviceId = base58ToUuid(context.clientId)

Expand All @@ -16,6 +16,7 @@ export function executePluginAction(navigation: NavigationBase, pluginId: string
accountReferral,
deviceId,
direction: 'sell',
disklet,
guiPlugin: guiPlugins[pluginId],
navigation,
regionCode: { countryCode: 'US' }
Expand Down
3 changes: 2 additions & 1 deletion src/components/scenes/GuiPluginListScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class GuiPluginList extends React.PureComponent<Props, State> {
* Launch the provided plugin, including pre-flight checks.
*/
async openPlugin(listRow: GuiPluginRow, longPress: boolean = false) {
const { accountReferral, countryCode, deviceId, disablePlugins, navigation, account } = this.props
const { accountReferral, coreDisklet, countryCode, deviceId, disablePlugins, navigation, account } = this.props
const { pluginId, paymentType, deepQuery = {} } = listRow
const plugin = guiPlugins[pluginId]

Expand Down Expand Up @@ -274,6 +274,7 @@ class GuiPluginList extends React.PureComponent<Props, State> {
deviceId,
direction,
disablePlugins: disableProviders,
disklet: coreDisklet,
guiPlugin: plugin,
longPress,
navigation,
Expand Down
1 change: 1 addition & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,7 @@ const strings = {
fiat_plugin_sell_cancelled: 'Sell order cancelled',
fiat_plugin_sell_failed_try_again: 'Sell order failed. Please try again.',
fiat_plugin_sell_failed_to_send_try_again: 'Failed to send funds for sell transaction. Please try again.',
fiat_plugin_cannot_continue_camera_permission: 'Cannot continue. Camera permission needed for ID verifications',

// Wallet List Modal
select_recv_wallet: 'Select Receiving Wallet',
Expand Down
1 change: 1 addition & 0 deletions src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@
"fiat_plugin_sell_cancelled": "Sell order cancelled",
"fiat_plugin_sell_failed_try_again": "Sell order failed. Please try again.",
"fiat_plugin_sell_failed_to_send_try_again": "Failed to send funds for sell transaction. Please try again.",
"fiat_plugin_cannot_continue_camera_permission": "Cannot continue. Camera permission needed for ID verifications",
"select_recv_wallet": "Select Receiving Wallet",
"select_src_wallet": "Select Source Wallet",
"deposit_to_bank": "Deposit to Bank",
Expand Down
14 changes: 14 additions & 0 deletions src/plugins/gui/fiatPlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Clipboard from '@react-native-clipboard/clipboard'
import { Disklet } from 'disklet'
import { EdgeAccount, EdgeTransaction } from 'edge-core-js'
import * as React from 'react'
import { Platform } from 'react-native'
Expand All @@ -14,6 +15,7 @@ import { RadioListModal } from '../../components/modals/RadioListModal'
import { WalletListModal, WalletListResult } from '../../components/modals/WalletListModal'
import { SendScene2Params } from '../../components/scenes/SendScene2'
import { Airship, showError, showToast, showToastSpinner } from '../../components/services/AirshipInstance'
import { requestPermissionOnSettings } from '../../components/services/PermissionsManager'
import { HomeAddress, SepaInfo } from '../../types/FormTypes'
import { GuiPlugin } from '../../types/GuiPluginTypes'
import { AccountReferral } from '../../types/ReferralTypes'
Expand All @@ -24,6 +26,7 @@ import {
FiatPaymentType,
FiatPluginAddressFormParams,
FiatPluginListModalParams,
FiatPluginPermissions,
FiatPluginRegionCode,
FiatPluginSepaFormParams,
FiatPluginSepaTransferParams,
Expand All @@ -40,6 +43,7 @@ export const SendErrorBackPressed = 'SendErrorBackPressed'
export const executePlugin = async (params: {
account: EdgeAccount
accountReferral: AccountReferral
disklet: Disklet
deviceId: string
direction: 'buy' | 'sell'
disablePlugins?: NestedDisableMap
Expand All @@ -56,6 +60,7 @@ export const executePlugin = async (params: {
accountReferral,
deviceId,
direction,
disklet,
guiPlugin,
longPress = false,
navigation,
Expand Down Expand Up @@ -124,6 +129,15 @@ export const executePlugin = async (params: {
})
})
},
requestPermission: async (permissions: FiatPluginPermissions, displayName: string, mandatory: boolean = true) => {
for (const permission of permissions) {
const deniedPermission = await requestPermissionOnSettings(disklet, permission, displayName, mandatory)
if (deniedPermission) {
return false
}
}
return true
},
async rewardsCardDashboard(params) {
maybeNavigateToCorrectTabScene()
navigation.navigate('rewardsCardDashboard', params)
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/gui/fiatPluginTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DisablePluginMap } from '../../actions/ExchangeInfoActions'
import { LaunchPaymentProtoParams } from '../../actions/PaymentProtoActions'
import { ButtonInfo, ButtonModalProps } from '../../components/modals/ButtonsModal'
import { SendScene2Params } from '../../components/scenes/SendScene2'
import { Permission } from '../../reducers/PermissionsReducer'
import { HomeAddress, SepaInfo } from '../../types/FormTypes'
import { GuiPlugin } from '../../types/GuiPluginTypes'
import { AppParamList } from '../../types/routerTypes'
Expand Down Expand Up @@ -116,6 +117,9 @@ export interface SaveTxActionParams {
savedAction: EdgeTxAction
assetAction: EdgeAssetAction
}

export type FiatPluginPermissions = Permission[]

export interface FiatPluginUi {
addressWarnings: (parsedUri: any, currencyCode: string) => Promise<boolean>
buttonModal: <Buttons extends { [key: string]: ButtonInfo }>(params: Omit<ButtonModalProps<Buttons>, 'bridge'>) => Promise<keyof Buttons | undefined>
Expand All @@ -127,6 +131,7 @@ export interface FiatPluginUi {
listModal: (params: FiatPluginListModalParams) => Promise<string | undefined>
enterAmount: (params: AppParamList['guiPluginEnterAmount']) => void
addressForm: (params: FiatPluginAddressFormParams) => Promise<HomeAddress>
requestPermission: (permissions: FiatPluginPermissions, displayName: string, mandatory: boolean) => Promise<boolean>
rewardsCardDashboard: (params: RewardsCardDashboardParams) => Promise<void>
rewardsCardWelcome: (params: RewardsCardWelcomeParams) => Promise<void>
saveTxAction: (params: SaveTxActionParams) => Promise<void>
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/gui/providers/banxaProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ export const banxaProvider: FiatProviderFactory = {
expirationDate: new Date(Date.now() + 50000),
approveQuote: async (approveParams: FiatProviderApproveQuoteParams): Promise<void> => {
const { showUi, coreWallet } = approveParams
const success = await showUi.requestPermission(['camera'], pluginDisplayName, true)
if (!success) {
await showUi.showError(new Error(lstrings.fiat_plugin_cannot_continue_camera_permission))
}
const receiveAddress = await coreWallet.getReceiveAddress({ tokenId: null })

const bodyParams: any = {
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/gui/providers/paybisProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ export const paybisProvider: FiatProviderFactory = {
paymentTypes,
approveQuote: async (approveParams: FiatProviderApproveQuoteParams): Promise<void> => {
const { coreWallet, showUi } = approveParams
const success = await showUi.requestPermission(['camera'], pluginDisplayName, true)
if (!success) {
await showUi.showError(new Error(lstrings.fiat_plugin_cannot_continue_camera_permission))
}
const receiveAddress = await coreWallet.getReceiveAddress({ tokenId: null })

let bodyParams
Expand Down

0 comments on commit 729d2f9

Please sign in to comment.