Skip to content

Commit

Permalink
feat: initial implementation of send tokens RPC handling
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabadesso committed Feb 12, 2025
1 parent 13dbe5b commit abb2fc6
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export const types = {
REOWN_CREATE_TOKEN_STATUS_FAILED: 'REOWN_CREATE_TOKEN_STATUS_FAILED',
REOWN_CREATE_TOKEN_RETRY: 'REOWN_CREATE_TOKEN_RETRY',
REOWN_CREATE_TOKEN_RETRY_DISMISS: 'REOWN_CREATE_TOKEN_RETRY_DISMISS',
REOWN_SEND_TX_RETRY: 'REOWN_SEND_TX_RETRY',
REOWN_SEND_TX_RETRY_DISMISS: 'REOWN_SEND_TX_RETRY_DISMISS',
REOWN_ACCEPT: 'REOWN_ACCEPT',
REOWN_REJECT: 'REOWN_REJECT',
REOWN_URI_INPUTTED: 'REOWN_URI_INPUTTED',
Expand All @@ -101,6 +103,10 @@ export const types = {
SHOW_GLOBAL_MODAL: 'SHOW_GLOBAL_MODAL',
HIDE_GLOBAL_MODAL: 'HIDE_GLOBAL_MODAL',
SERVER_INFO_UPDATED: 'SERVER_INFO_UPDATED',
REOWN_SEND_TX_STATUS_LOADING: 'REOWN_SEND_TX_STATUS_LOADING',
REOWN_SEND_TX_STATUS_READY: 'REOWN_SEND_TX_STATUS_READY',
REOWN_SEND_TX_STATUS_SUCCESS: 'REOWN_SEND_TX_STATUS_SUCCESS',
REOWN_SEND_TX_STATUS_FAILURE: 'REOWN_SEND_TX_STATUS_FAILURE',
};

/**
Expand Down Expand Up @@ -847,3 +853,31 @@ export const showGlobalModal = (modalType, modalProps = {}) => ({
export const hideGlobalModal = () => ({
type: types.HIDE_GLOBAL_MODAL
});

/**
* Set send transaction status to loading
*/
export const setSendTxStatusLoading = () => ({
type: types.REOWN_SEND_TX_STATUS_LOADING,
});

/**
* Set send transaction status to ready
*/
export const setSendTxStatusReady = () => ({
type: types.REOWN_SEND_TX_STATUS_READY,
});

/**
* Set send transaction status to success
*/
export const setSendTxStatusSuccess = () => ({
type: types.REOWN_SEND_TX_STATUS_SUCCESS,
});

/**
* Set send transaction status to failure
*/
export const setSendTxStatusFailure = () => ({
type: types.REOWN_SEND_TX_STATUS_FAILURE,
});
25 changes: 25 additions & 0 deletions src/reducers/reown.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const initialState = {
connectionFailed: false,
nanoContractStatus: 'ready', // 'ready' | 'loading' | 'success' | 'failure'
createTokenStatus: 'ready', // 'ready' | 'loading' | 'success' | 'failure'
sendTxStatus: 'ready', // 'ready' | 'loading' | 'success' | 'failure'
};

export default function reownReducer(state = initialState, action) {
Expand Down Expand Up @@ -99,6 +100,30 @@ export default function reownReducer(state = initialState, action) {
createTokenStatus: 'failure',
};

case types.REOWN_SEND_TX_STATUS_LOADING:
return {
...state,
sendTxStatus: 'loading',
};

case types.REOWN_SEND_TX_STATUS_READY:
return {
...state,
sendTxStatus: 'ready',
};

case types.REOWN_SEND_TX_STATUS_SUCCESS:
return {
...state,
sendTxStatus: 'success',
};

case types.REOWN_SEND_TX_STATUS_FAILURE:
return {
...state,
sendTxStatus: 'failure',
};

default:
return state;
}
Expand Down
25 changes: 23 additions & 2 deletions src/sagas/reown.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ import {
setCreateTokenStatusReady,
setCreateTokenStatusSuccessful,
setCreateTokenStatusFailed,
setSendTxStatusLoading,
setSendTxStatusReady,
setSendTxStatusSuccess,
setSendTxStatusFailure,
showGlobalModal,
hideGlobalModal,
} from '../actions';
Expand Down Expand Up @@ -342,6 +346,10 @@ export function* processRequest(action) {
case RpcResponseTypes.CreateTokenResponse:
yield put(setCreateTokenStatusSuccessful());
break;
case RpcResponseTypes.SendTransactionResponse:
yield put(setSendTxStatusSuccess());
yield put(showGlobalModal(MODAL_TYPES.TRANSACTION_FEEDBACK, { isLoading: false, isError: false }));
break;
default:
break;
}
Expand Down Expand Up @@ -387,8 +395,21 @@ export function* processRequest(action) {
yield* processRequest(action);
}
} break;
default:
break;
default: {
yield put(setSendTxStatusFailure());
yield put(showGlobalModal(MODAL_TYPES.TRANSACTION_FEEDBACK, { isLoading: false, isError: true }));

const retry = yield call(
retryHandler,
types.REOWN_SEND_TX_RETRY,
types.REOWN_SEND_TX_RETRY_DISMISS,
);

if (retry) {
shouldAnswer = false;
yield* processRequest(action);
}
} break;
}

if (shouldAnswer) {
Expand Down

0 comments on commit abb2fc6

Please sign in to comment.