-
Notifications
You must be signed in to change notification settings - Fork 237
feat: massalabs network #741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kvhnuke
merged 30 commits into
devop/package-upgrades-2-11
from
feat/massalabs-extension
Sep 11, 2025
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
18ca58d
Support Massa in browser extension
peterjah 59761a5
add custom token support in asset view
peterjah 1c58e94
support MRC20 sending
peterjah 8ed1760
Merge pull request #739 from massalabs/extension
kvhnuke 83e5aef
devop: migrate crypto to local
kvhnuke 377ce34
fix massa signature verify
peterjah 555d271
Merge pull request #743 from massalabs/extension
kvhnuke 6bab919
fix: tests
kvhnuke 92094ed
Merge pull request #742 from enkryptcom/devop/massa-changes
kvhnuke 8660bcf
fix: tests
kvhnuke a754ac7
devop: cleanup
kvhnuke afe65f1
fix: build
kvhnuke f173a23
devop: cleanup
kvhnuke 95d0f8e
fix: build
kvhnuke 321d659
fix chrome extension build
peterjah 0900c8c
add invalid address error message
peterjah 4b2b694
ensure network is initialized before checking address
peterjah 0115ba6
Merge pull request #746 from massalabs/extension
kvhnuke da80eaf
rework sent input amount
peterjah 3b8c669
set fiat value max width in sent-input-amount
peterjah 99c6b70
Merge pull request #747 from massalabs/extension
kvhnuke 660ea08
fix: keyring error
kvhnuke 2d62693
fix transaction amount validation
peterjah 381da02
rework activity status check
peterjah 6966188
fix add massa custom token
peterjah 543105b
Merge pull request #749 from massalabs/extension
kvhnuke 776c10b
fix: name issue and blank screen issue
kvhnuke ac3c8f0
fix: minor
kvhnuke 901ece0
fix: conflicts
kvhnuke cea48fd
fix: conflicts
kvhnuke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,92 @@ | ||
| import { BaseNetwork } from '@/types/base-network'; | ||
| import getRequestProvider, { RequestClass } from '@enkryptcom/request'; | ||
| import { MiddlewareFunction, OnMessageResponse } from '@enkryptcom/types'; | ||
| import Middlewares from './methods'; | ||
| import EventEmitter from 'eventemitter3'; | ||
| import { | ||
| BackgroundProviderInterface, | ||
| ProviderName, | ||
| ProviderRPCRequest, | ||
| } from '@/types/provider'; | ||
| import GetUIPath from '@/libs/utils/get-ui-path'; | ||
| import PublicKeyRing from '@/libs/keyring/public-keyring'; | ||
| import UIRoutes from './ui/routes/names'; | ||
| import { RoutesType } from '@/types/ui'; | ||
| import massaNetworks from './networks'; | ||
| import { NetworkNames } from '@enkryptcom/types'; | ||
|
|
||
| export default class MassaProvider | ||
| extends EventEmitter | ||
| implements BackgroundProviderInterface | ||
| { | ||
| public network: BaseNetwork; | ||
| requestProvider: RequestClass; | ||
| middlewares: MiddlewareFunction[] = []; | ||
| namespace: string; | ||
| KeyRing: PublicKeyRing; | ||
| UIRoutes: RoutesType; | ||
| toWindow: (message: string) => void; | ||
|
|
||
| constructor( | ||
| toWindow: (message: string) => void, | ||
| network: BaseNetwork = massaNetworks[NetworkNames.Massa], | ||
| ) { | ||
| super(); | ||
| this.network = network; | ||
| this.toWindow = toWindow; | ||
| this.setMiddleWares(); | ||
| this.requestProvider = getRequestProvider(network.node, this.middlewares); | ||
| this.requestProvider.on('notification', (notif: any) => { | ||
| this.sendNotification(JSON.stringify(notif)); | ||
| }); | ||
| this.namespace = ProviderName.massa; | ||
| this.KeyRing = new PublicKeyRing(); | ||
|
|
||
| this.UIRoutes = UIRoutes; | ||
| } | ||
|
|
||
| private setMiddleWares(): void { | ||
| this.middlewares = Middlewares(this).map(mw => mw.bind(this)); | ||
| } | ||
|
|
||
| setRequestProvider(network: BaseNetwork): void { | ||
| const prevURL = new URL(this.network.node); | ||
| const newURL = new URL(network.node); | ||
| this.network = network; | ||
| if (prevURL.protocol === newURL.protocol) | ||
| this.requestProvider.changeNetwork(network.node); | ||
| else | ||
| this.requestProvider = getRequestProvider(network.node, this.middlewares); | ||
| } | ||
|
|
||
| async isPersistentEvent(): Promise<boolean> { | ||
| return false; | ||
| } | ||
|
|
||
| async sendNotification(notif: string): Promise<void> { | ||
| return this.toWindow(notif); | ||
| } | ||
|
|
||
| request(request: ProviderRPCRequest): Promise<OnMessageResponse> { | ||
| return this.requestProvider | ||
| .request(request) | ||
| .then(res => { | ||
| return { | ||
| result: JSON.stringify(res), | ||
| }; | ||
| }) | ||
| .catch(e => { | ||
| return { | ||
| error: JSON.stringify(e.message), | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| getUIPath(page: string): string { | ||
| return GetUIPath(page, this.namespace); | ||
| } | ||
|
|
||
| getCurrentNetwork(): BaseNetwork { | ||
| return this.network; | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
packages/extension/src/providers/massa/libs/activity-handlers/index.ts
This file contains hidden or 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,3 @@ | ||
| import MassaActivity from './massa'; | ||
|
|
||
| export { MassaActivity }; |
27 changes: 27 additions & 0 deletions
27
packages/extension/src/providers/massa/libs/activity-handlers/massa.ts
This file contains hidden or 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,27 @@ | ||
| import { BaseNetwork } from '@/types/base-network'; | ||
| import { Activity } from '@/types/activity'; | ||
| import { ActivityHandlerType } from '@/libs/activity-state/types'; | ||
| import ActivityState from '@/libs/activity-state'; | ||
|
|
||
| const MassaActivity: ActivityHandlerType = async ( | ||
| network: BaseNetwork, | ||
| address: string, | ||
| ): Promise<Activity[]> => { | ||
| try { | ||
| // Get activities from local storage | ||
| const activityState = new ActivityState(); | ||
| const activities = await activityState.getAllActivities({ | ||
| address, | ||
| network: network.name, | ||
| }); | ||
|
|
||
| // For now, return local activities | ||
| // In the future, this can be extended to fetch from Massa explorer API | ||
| return activities; | ||
| } catch (error) { | ||
| console.error('Error fetching Massa activities:', error); | ||
| return []; | ||
| } | ||
| }; | ||
|
|
||
| export default MassaActivity; |
This file contains hidden or 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,60 @@ | ||
| import { ProviderAPIInterface } from '@/types/provider'; | ||
| import { | ||
| JsonRpcPublicProvider, | ||
| MRC20, | ||
| NodeStatusInfo, | ||
| OperationStatus, | ||
| } from '@massalabs/massa-web3'; | ||
|
|
||
| export default class MassaAPI extends ProviderAPIInterface { | ||
| public provider: JsonRpcPublicProvider; | ||
| public node: string; | ||
|
|
||
| constructor(node: string) { | ||
| super(node); | ||
| this.node = node; | ||
| this.provider = JsonRpcPublicProvider.fromRPCUrl( | ||
| node, | ||
| ) as JsonRpcPublicProvider; | ||
| } | ||
|
|
||
| public get api() { | ||
| return this; | ||
| } | ||
|
|
||
| async init(): Promise<void> {} | ||
|
|
||
| async getBalance(address: string): Promise<string> { | ||
| const [account] = await this.provider.balanceOf([address], false); | ||
| if (!account) return '0'; | ||
| return account.balance.toString(); | ||
| } | ||
|
|
||
| async getBalanceMRC20(address: string, contract: string): Promise<string> { | ||
| const mrc20 = new MRC20(this.provider, contract); | ||
| const balance = await mrc20.balanceOf(address); | ||
| return balance.toString(); | ||
| } | ||
|
|
||
| async getMinimalFee(): Promise<string> { | ||
| try { | ||
| const networkInfo = await this.provider.networkInfos(); | ||
| return networkInfo.minimalFee.toString(); | ||
| } catch { | ||
| // Return a default minimal fee if network info is not available | ||
| return '10000000'; // 0.01 MAS in base units (9 decimals) | ||
| } | ||
| } | ||
|
|
||
| async getTransactionStatus(opId: string): Promise<OperationStatus | null> { | ||
| try { | ||
| return this.provider.getOperationStatus(opId); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| async getNodeStatus(): Promise<NodeStatusInfo> { | ||
| return this.provider.getNodeStatus(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.