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

refactor(ramp): enable all chains #813

Closed
wants to merge 1 commit into from
Closed
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
37 changes: 5 additions & 32 deletions apps/ramp-network/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
import React, { useEffect, useState, useMemo } from 'react'
import React, { useEffect, useState } from 'react'
import { useSafeAppsSDK } from '@safe-global/safe-apps-react-sdk'
import { Title, Loader, Text } from '@gnosis.pm/safe-react-components'
import { Loader } from '@gnosis.pm/safe-react-components'
import { ChainInfo } from '@safe-global/safe-apps-sdk'
import { goBack } from './utils'
import { ASSETS_BY_CHAIN, initializeRampWidget } from './ramp'
import styled from 'styled-components'

const Container = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 30em;
`

const NetworkNotSupported = ({ name }: { name: string }): React.ReactElement => {
return (
<Container>
<Title size="md">Network not supported</Title>
<Text size="lg">Currently {name} is not supported</Text>
</Container>
)
}
import { initializeRampWidget } from './ramp'

const SafeApp = (): React.ReactElement | null => {
const { sdk, safe } = useSafeAppsSDK()
const [chainInfo, setChainInfo] = useState<ChainInfo>()

const isChainSupported = useMemo(() => {
return chainInfo && Object.keys(ASSETS_BY_CHAIN).includes(chainInfo.chainId)
}, [chainInfo])

useEffect(() => {
;(async () => {
try {
Expand All @@ -43,23 +21,18 @@ const SafeApp = (): React.ReactElement | null => {
}, [sdk])

useEffect(() => {
if (chainInfo && safe && isChainSupported) {
if (chainInfo && safe) {
initializeRampWidget({
address: safe.safeAddress,
assets: ASSETS_BY_CHAIN[chainInfo.chainId],
onClose: goBack,
})
}
}, [chainInfo, safe, isChainSupported])
}, [chainInfo, safe])

if (!chainInfo || !safe) {
return <Loader size="lg" />
}

if (!isChainSupported) {
return <NetworkNotSupported name={chainInfo.chainName} />
}

return null
}

Expand Down
18 changes: 1 addition & 17 deletions apps/ramp-network/src/ramp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,19 @@ const RINKEBY_STAGING_URL = 'https://ri-widget-staging.firebaseapp.com/'
const WIDGET_CLOSE_EVENT = 'WIDGET_CLOSE'
const PURCHASE_CREATED_EVENT = 'PURCHASE_CREATED'

export const ASSETS_BY_CHAIN: { [key: string]: string } = {
'1': 'ETH_*,ERC20_*',
'4': 'ETH_*,ERC20_*',
'56': 'BSC_*',
'137': 'MATIC_*',
'100': 'XDAI_*',
'43114': 'AVAX_*',
'8453': 'BASE_*',
'324': 'ZKSYNCERA_*',
'1101': 'POLYGONZKEVM_*',
'42161': 'ARBITRUM_*',
'42220': 'CELO_*',
}

export const getRampWidgetUrl = (chainInfo: ChainInfo) => {
return chainInfo?.chainId === '4' ? RINKEBY_STAGING_URL : ''
}

type RampWidgetInitializer = {
assets: string
address: string
onClose?: () => void
}

export const initializeRampWidget = ({ assets, address, onClose }: RampWidgetInitializer) => {
export const initializeRampWidget = ({ address, onClose }: RampWidgetInitializer) => {
return new RampInstantSDK({
hostAppName: 'Ramp Network Safe App',
hostLogoUrl: 'https://docs.ramp.network/img/logo-1.svg',
swapAsset: assets,
userAddress: address,
hostApiKey: RAMP_API_KEY,
})
Expand Down
Loading