Skip to content

Commit

Permalink
feat: use meta-transaction error toasts from dcl-dapps (decentraland#538
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cazala authored Jan 24, 2022
1 parent eeae6b0 commit 832a98a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 157 deletions.
56 changes: 20 additions & 36 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "marketplace-ui",
"version": "0.4.0",
"dependencies": {
"@dcl/schemas": "^3.4.1",
"@dcl/schemas": "^3.5.0",
"apollo-boost": "^0.4.7",
"bn.js": "^5.2.0",
"classnames": "^2.3.1",
Expand All @@ -11,9 +11,9 @@
"dcl-catalyst-client": "^5.1.1",
"dcl-catalyst-commons": "^4.0.1",
"dcl-crypto": "^2.2.0",
"decentraland-dapps": "^12.35.0",
"decentraland-dapps": "^12.36.0",
"decentraland-transactions": "^1.29.1",
"decentraland-ui": "^3.17.0",
"decentraland-ui": "^3.18.1",
"dotenv": "^10.0.0",
"graphql": "^14.7.0",
"history": "^4.10.1",
Expand Down
85 changes: 2 additions & 83 deletions webapp/src/modules/toast/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,102 +1,21 @@
import { all, takeEvery, put } from 'redux-saga/effects'
import { Network } from '@dcl/schemas'
import { ErrorCode } from 'decentraland-transactions'
import { toastSaga as baseToastSaga } from 'decentraland-dapps/dist/modules/toast/sagas'
import { showToast } from 'decentraland-dapps/dist/modules/toast/actions'
import {
GrantTokenFailureAction,
GRANT_TOKEN_FAILURE,
RevokeTokenFailureAction,
REVOKE_TOKEN_FAILURE
} from 'decentraland-dapps/dist/modules/authorization/actions'
import { getChainConfiguration } from 'decentraland-dapps/dist/lib/chainConfiguration'
import { TransferNFTFailureAction, TRANSFER_NFT_FAILURE } from '../nft/actions'
import {
CancelOrderFailureAction,
CANCEL_ORDER_FAILURE,
CreateOrderFailureAction,
CREATE_ORDER_FAILURE,
ExecuteOrderFailureAction,
EXECUTE_ORDER_FAILURE
} from '../order/actions'
import {
getMetaTransactionFailureToast,
getContractAccountFailureToast,
getStoreUpdateSucessToast
} from './toasts'
import {
isContractAccountError,
isUserDeniedSignatureError
} from '../transaction/utils'
import { getStoreUpdateSucessToast } from './toasts'
import { UPDATE_STORE_SUCCESS } from '../store/actions'

export function* toastSaga() {
yield all([baseToastSaga(), customToastSaga()])
}

function* customToastSaga() {
yield all([successToastSagas(), failureToastSagas()])
yield all([successToastSagas()])
}

function* successToastSagas() {
yield takeEvery(UPDATE_STORE_SUCCESS, handleStoreUpdateSuccess)
}

function* failureToastSagas() {
yield takeEvery(TRANSFER_NFT_FAILURE, handleNFTMetaTransactionFailure)
yield takeEvery(CREATE_ORDER_FAILURE, handleNFTMetaTransactionFailure)
yield takeEvery(EXECUTE_ORDER_FAILURE, handleNFTMetaTransactionFailure)
yield takeEvery(CANCEL_ORDER_FAILURE, handleNFTMetaTransactionFailure)

yield takeEvery(
GRANT_TOKEN_FAILURE,
handleAuthorizationMetaTransactionFailure
)
yield takeEvery(
REVOKE_TOKEN_FAILURE,
handleAuthorizationMetaTransactionFailure
)
}

function* handleNFTMetaTransactionFailure(
action:
| TransferNFTFailureAction
| CreateOrderFailureAction
| ExecuteOrderFailureAction
| CancelOrderFailureAction
) {
const { nft, errorCode } = action.payload

if (nft.network === Network.MATIC) {
switch (errorCode) {
case ErrorCode.USER_DENIED:
// do nothing
break
case ErrorCode.CONTRACT_ACCOUNT:
yield put(showToast(getContractAccountFailureToast()))
break
default:
yield put(showToast(getMetaTransactionFailureToast()))
}
}
}

function* handleAuthorizationMetaTransactionFailure(
action: GrantTokenFailureAction | RevokeTokenFailureAction
) {
const { authorization, error } = action.payload

const { network } = getChainConfiguration(authorization.chainId)

if (network === Network.MATIC && !isUserDeniedSignatureError(error)) {
if (isContractAccountError(error)) {
yield put(showToast(getContractAccountFailureToast()))
} else {
yield put(showToast(getMetaTransactionFailureToast()))
}
}
}

function* handleStoreUpdateSuccess() {
yield put(showToast(getStoreUpdateSucessToast()))
}
36 changes: 1 addition & 35 deletions webapp/src/modules/toast/toasts.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
import { ToastType } from 'decentraland-ui'
import { T, t } from 'decentraland-dapps/dist/modules/translation/utils'

const DISCORD_URL = process.env.REACT_APP_DISCORD_URL

export function getMetaTransactionFailureToast() {
return {
type: ToastType.ERROR,
title: t('toast.meta_transaction_failure.title'),
body: (
<T
id="toast.meta_transaction_failure.body"
values={{
br: <br />,
discord_link: (
<a href={DISCORD_URL} target="_blank" rel="noopener noreferrer">
Discord
</a>
)
}}
/>
),
timeout: 6000,
closable: true
}
}

export function getContractAccountFailureToast() {
return {
type: ToastType.ERROR,
title: t('toast.contract_account.title'),
body: t('toast.contract_account.body'),
timeout: 6000,
closable: true
}
}
import { t } from 'decentraland-dapps/dist/modules/translation/utils'

export function getStoreUpdateSucessToast() {
return {
Expand Down

0 comments on commit 832a98a

Please sign in to comment.