forked from decentraland/marketplace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use meta-transaction error toasts from dcl-dapps (decentraland#538
- Loading branch information
Showing
4 changed files
with
26 additions
and
157 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters