-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: rename MassaStation to MassaWallet in wallet components * refactor: update translation key for MassaWallet in i18n file * chore: update @massalabs/massa-web3 version to 5.1.1-dev.20250110163508 in package.json and package-lock.json * feat: implement useHandleOperation and refactor useWriteSmartContract for improved operation handling * chore: update @massalabs/massa-web3 to version 5.1.1 and @massalabs/wallet-provider to version 3.1.1 in package.json and package-lock.json * chore: bump version of @massalabs/react-ui-kit to 1.0.1 in package.json and package-lock.json * refactor: update import paths for massaToken and constants; introduce operationHandler for better operation management * chore: update GitHub Actions to use checkout@v4 and setup-node@v4 * refactor: rename executeOperation to processOperation and update code according to review * refactor: replace setState calls with updateOpState
- Loading branch information
Showing
21 changed files
with
240 additions
and
106 deletions.
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { OperationStatus } from '@massalabs/massa-web3'; | ||
|
||
export const ERROR_STATUSES = [ | ||
OperationStatus.Error, | ||
OperationStatus.SpeculativeError, | ||
]; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type ToasterMessage = { | ||
pending: string; | ||
success: string; | ||
error: string; | ||
timeout?: string; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useState } from 'react'; | ||
import { CHAIN_ID, Operation } from '@massalabs/massa-web3'; | ||
import { ToasterMessage } from './types'; | ||
import { | ||
processOperation, | ||
OperationState, | ||
updateOpState, | ||
} from '../utils/operationHandler'; | ||
|
||
export function useHandleOperation() { | ||
const [state, setState] = useState<OperationState>({ | ||
isOpPending: false, | ||
isPending: false, | ||
isSuccess: false, | ||
isError: false, | ||
opId: undefined, | ||
}); | ||
|
||
async function handleOperation( | ||
operation: Operation, | ||
messages: ToasterMessage, | ||
final = false, | ||
): Promise<void> { | ||
const { chainId } = await operation.provider.networkInfos(); | ||
const isMainnet = chainId === CHAIN_ID.Mainnet; | ||
|
||
if (state.isOpPending) { | ||
throw new Error('Operation is already pending'); | ||
} | ||
|
||
updateOpState(setState, { | ||
isOpPending: true, | ||
isPending: true, | ||
isSuccess: false, | ||
isError: false, | ||
opId: undefined, | ||
}); | ||
|
||
await processOperation(operation, messages, final, isMainnet, setState); | ||
} | ||
|
||
return { | ||
opId: state.opId, | ||
isOpPending: state.isOpPending, | ||
isPending: state.isPending, | ||
isSuccess: state.isSuccess, | ||
isError: state.isError, | ||
handleOperation, | ||
}; | ||
} |
Oops, something went wrong.