Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Request Safe info from Safe apps
Browse files Browse the repository at this point in the history
  • Loading branch information
germartinez committed Jul 15, 2020
1 parent 1aa94ed commit 4f8be8f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/routes/safe/components/Apps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ const IframeCoverLoading = styled.div`
background: white;
`
const operations = {
SEND_TRANSACTIONS: 'SEND_TRANSACTIONS',
ON_SAFE_INFO: 'ON_SAFE_INFO',
GET_SAFE_INFO: 'GET_SAFE_INFO',
SEND_TRANSACTIONS: 'SEND_TRANSACTIONS',
}

function Apps({ closeModal, closeSnackbar, enqueueSnackbar, openModal }) {
Expand Down Expand Up @@ -218,6 +219,11 @@ function Apps({ closeModal, closeSnackbar, enqueueSnackbar, openModal }) {

const getEnabledApps = () => appList.filter((a) => !a.disabled)

const sendMessageToIframe = useCallback((messageId, data) => {
const app = getSelectedApp()
iframeEl.contentWindow.postMessage({ messageId, data }, app.url)
})

// handle messages from iframe
useEffect(() => {
const handleIframeMessage = (data) => {
Expand All @@ -230,7 +236,6 @@ function Apps({ closeModal, closeSnackbar, enqueueSnackbar, openModal }) {
case operations.SEND_TRANSACTIONS: {
const onConfirm = async () => {
closeModal()

await sendTransactions(
dispatch,
safeAddress,
Expand All @@ -252,7 +257,15 @@ function Apps({ closeModal, closeSnackbar, enqueueSnackbar, openModal }) {
closeModal,
onConfirm,
)
break
}

case operations.GET_SAFE_INFO: {
sendMessageToIframe(operations.ON_SAFE_INFO, {
safeAddress,
network,
ethBalance,
})
break
}

Expand Down Expand Up @@ -343,10 +356,6 @@ function Apps({ closeModal, closeSnackbar, enqueueSnackbar, openModal }) {

// on iframe change
useEffect(() => {
const sendMessageToIframe = (messageId, data) => {
const app = getSelectedApp()
iframeEl.contentWindow.postMessage({ messageId, data }, app.url)
}
const onIframeLoaded = () => {
setAppIsLoading(false)
sendMessageToIframe(operations.ON_SAFE_INFO, {
Expand All @@ -366,7 +375,7 @@ function Apps({ closeModal, closeSnackbar, enqueueSnackbar, openModal }) {
return () => {
iframeEl.removeEventListener('load', onIframeLoaded)
}
}, [ethBalance, getSelectedApp, iframeEl, network, safeAddress, selectedApp])
}, [ethBalance, getSelectedApp, iframeEl, network, safeAddress, selectedApp, sendMessageToIframe])

if (loading) {
return <Loader size="md" />
Expand Down

0 comments on commit 4f8be8f

Please sign in to comment.