Skip to content

Commit 2ec2ed3

Browse files
committed
fixup! Add RampPluginManager service and RampPluginReducer
Remove RampPluginManager and Redux state management for ramp plugins
1 parent 57e58ee commit 2ec2ed3

File tree

9 files changed

+99
-113
lines changed

9 files changed

+99
-113
lines changed

src/__tests__/reducers/__snapshots__/RootReducer.test.ts.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ exports[`initialState 1`] = `
6060
"contacts": "denied",
6161
"location": "denied",
6262
},
63-
"rampPlugins": {
64-
"isLoading": true,
65-
"plugins": {},
66-
},
6763
"sortedWalletList": [],
6864
"staking": {
6965
"walletStakingMap": {},

src/components/scenes/TradeCreateScene.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import { showCountrySelectionModal } from '../../actions/CountryListActions'
1010
import { FLAG_LOGO_URL } from '../../constants/CdnConstants'
1111
import { COUNTRY_CODES, FIAT_COUNTRY } from '../../constants/CountryConstants'
1212
import { useHandler } from '../../hooks/useHandler'
13+
import { useRampPlugins } from '../../hooks/useRampPlugins'
1314
import { useRampQuotes } from '../../hooks/useRampQuotes'
1415
import { useSupportedPlugins } from '../../hooks/useSupportedPlugins'
1516
import { useWatch } from '../../hooks/useWatch'
1617
import { lstrings } from '../../locales/strings'
17-
import type { RampQuoteRequest } from '../../plugins/ramps/rampPluginTypes'
18+
import type {
19+
RampPlugin,
20+
RampQuoteRequest
21+
} from '../../plugins/ramps/rampPluginTypes'
1822
import { getDefaultFiat } from '../../selectors/SettingsSelectors'
1923
import { useDispatch, useSelector } from '../../types/reactRedux'
2024
import type { BuyTabSceneProps, NavigationBase } from '../../types/routerTypes'
@@ -124,9 +128,16 @@ export const TradeCreateScene = (props: Props): React.ReactElement => {
124128
const shouldShowRegionSelect =
125129
initialRegionCode == null && (countryCode === '' || countryData == null)
126130

127-
// Get ramp plugins directly from Redux
128-
const rampPlugins = useSelector(state => state.rampPlugins.plugins)
129-
const isPluginsLoading = useSelector(state => state.rampPlugins.isLoading)
131+
// Get ramp plugins
132+
const { data: rampPluginArray = [], isLoading: isPluginsLoading } =
133+
useRampPlugins({ account })
134+
const rampPlugins = React.useMemo(() => {
135+
const map: Record<string, RampPlugin> = {}
136+
for (const plugin of rampPluginArray) {
137+
map[plugin.pluginId] = plugin
138+
}
139+
return map
140+
}, [rampPluginArray])
130141

131142
// Use supported plugins hook
132143
const { supportedPlugins, isLoading: isCheckingSupport } =

src/components/scenes/TradeOptionSelectScene.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { sprintf } from 'sprintf-js'
44

55
// TradeOptionSelectScene - Updated layout for design requirements
66
import paymentTypeLogoApplePay from '../../assets/images/paymentTypes/paymentTypeLogoApplePay.png'
7+
import { useRampPlugins } from '../../hooks/useRampPlugins'
78
import { useRampQuotes } from '../../hooks/useRampQuotes'
89
import { useSupportedPlugins } from '../../hooks/useSupportedPlugins'
910
import { lstrings } from '../../locales/strings'
1011
import type {
12+
RampPlugin,
1113
RampQuoteRequest,
1214
RampQuoteResult,
1315
SettlementRange
@@ -42,8 +44,17 @@ export const TradeOptionSelectScene = (props: Props): React.JSX.Element => {
4244
const { rampQuoteRequest, quotes: precomputedQuotes } = route.params
4345

4446
const theme = useTheme()
45-
const rampPlugins = useSelector(state => state.rampPlugins.plugins)
46-
const isPluginsLoading = useSelector(state => state.rampPlugins.isLoading)
47+
const account = useSelector(state => state.core.account)
48+
// Get ramp plugins
49+
const { data: rampPluginArray = [], isLoading: isPluginsLoading } =
50+
useRampPlugins({ account })
51+
const rampPlugins = React.useMemo(() => {
52+
const map: Record<string, RampPlugin> = {}
53+
for (const plugin of rampPluginArray) {
54+
map[plugin.pluginId] = plugin
55+
}
56+
return map
57+
}, [rampPluginArray])
4758

4859
// Use supported plugins hook only if no precomputed quotes
4960
const { supportedPlugins } = useSupportedPlugins({

src/components/services/RampPluginManager.tsx

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/components/services/Services.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import { NetworkActivity } from './NetworkActivity'
4444
import { NotificationService } from './NotificationService'
4545
import { PasswordReminderService } from './PasswordReminderService'
4646
import { PermissionsManager } from './PermissionsManager'
47-
import { RampPluginManager } from './RampPluginManager'
4847
import { SortedWalletList } from './SortedWalletList'
4948
import { WalletConnectService } from './WalletConnectService'
5049
import { WalletLifecycle } from './WalletLifecycle'
@@ -242,7 +241,6 @@ export function Services(props: Props) {
242241
<FioService account={account} navigation={navigation} />
243242
)}
244243
<PermissionsManager />
245-
<RampPluginManager navigation={navigation} />
246244
{startLoanManager ? <LoanManagerService account={account} /> : null}
247245
<NetworkActivity />
248246
<PasswordReminderService />

src/hooks/useRampPlugins.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import type { EdgeAccount } from 'edge-core-js'
2+
import * as React from 'react'
3+
4+
import { pluginFactories } from '../plugins/ramps/allRampPlugins'
5+
import type { RampPlugin } from '../plugins/ramps/rampPluginTypes'
6+
7+
interface UseRampPluginsOptions {
8+
account: EdgeAccount
9+
}
10+
11+
export function useRampPlugins({ account }: UseRampPluginsOptions) {
12+
const [plugins, setPlugins] = React.useState<RampPlugin[]>([])
13+
const [isLoading, setIsLoading] = React.useState(true)
14+
const [error, setError] = React.useState<Error | null>(null)
15+
16+
React.useEffect(() => {
17+
let mounted = true
18+
19+
const loadPlugins = async () => {
20+
try {
21+
setIsLoading(true)
22+
setError(null)
23+
24+
const loadedPlugins: RampPlugin[] = []
25+
26+
for (const [pluginId, factory] of Object.entries(pluginFactories)) {
27+
try {
28+
// Create a minimal config for the plugin
29+
const config = {
30+
initOptions: {},
31+
account,
32+
navigation: null as any, // Navigation will be provided by components that need it
33+
onLogEvent: () => {},
34+
disklet: account.disklet
35+
}
36+
37+
const plugin = factory(config)
38+
loadedPlugins.push(plugin)
39+
} catch (error) {
40+
console.warn(`Failed to load plugin ${pluginId}:`, error)
41+
}
42+
}
43+
44+
if (mounted) {
45+
setPlugins(loadedPlugins)
46+
setIsLoading(false)
47+
}
48+
} catch (err) {
49+
if (mounted) {
50+
setError(
51+
err instanceof Error ? err : new Error('Failed to load plugins')
52+
)
53+
setIsLoading(false)
54+
}
55+
}
56+
}
57+
58+
loadPlugins().catch(console.error)
59+
60+
return () => {
61+
mounted = false
62+
}
63+
}, [account])
64+
65+
return {
66+
data: plugins,
67+
isLoading,
68+
error,
69+
isError: error != null
70+
}
71+
}

src/reducers/RampPluginReducer.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/reducers/RootReducer.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { account, type AccountState } from './AccountReducer'
2121
import { core, type CoreState } from './CoreReducer'
2222
import { network, type NetworkState } from './NetworkReducer'
2323
import { permissions, type PermissionsState } from './PermissionsReducer'
24-
import { rampPlugins, type RampPluginState } from './RampPluginReducer'
2524
import { staking, type StakingState } from './StakingReducer'
2625
import { ui, type UiState } from './uiReducer'
2726

@@ -48,7 +47,6 @@ export interface RootState {
4847
readonly actionQueue: ActionQueueState
4948
readonly core: CoreState
5049
readonly loanManager: LoanManagerState
51-
readonly rampPlugins: RampPluginState
5250
readonly staking: StakingState
5351
readonly permissions: PermissionsState
5452
readonly ui: UiState
@@ -139,7 +137,6 @@ export const rootReducer = combineReducers<RootState, Action>({
139137
core,
140138
loanManager,
141139
permissions,
142-
rampPlugins,
143140
staking,
144141
ui,
145142
network

src/types/reduxActions.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
import type { SortOption } from '../components/modals/WalletListSortModal'
1717
import type { ActionQueueAction } from '../controllers/action-queue/redux/actions'
1818
import type { LoanManagerActions } from '../controllers/loan-manager/redux/actions'
19-
import type { RampPlugin } from '../plugins/ramps/rampPluginTypes'
2019
import type { CcWalletMap } from '../reducers/FioReducer'
2120
import type { PermissionsState } from '../reducers/PermissionsReducer'
2221
import type {
@@ -187,10 +186,6 @@ export type Action =
187186
data: { fioAddress: string; ccWalletMap: CcWalletMap }
188187
}
189188
| { type: 'FIO/SET_FIO_DOMAINS'; data: { fioDomains: FioDomain[] } }
190-
| {
191-
type: 'RAMP_PLUGINS/LOADING_COMPLETE'
192-
data: { plugins: Record<string, RampPlugin> }
193-
}
194189
/*
195190
Self-Contained Package Actions:
196191

0 commit comments

Comments
 (0)