-
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.
- Loading branch information
Showing
26 changed files
with
181 additions
and
367 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
packages/snap/snap.manifest.json | ||
packages/dapp/.next | ||
|
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 was deleted.
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 was deleted.
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,72 +1,39 @@ | ||
import { CHAIN_ID, DefaultProviderUrls } from '@massalabs/massa-web3'; | ||
|
||
import { | ||
CHAIN_ID, | ||
DefaultProviderUrls, | ||
fromMAS, | ||
MAINNET, | ||
} from '@massalabs/massa-web3'; | ||
import { StateManager } from './state-manager'; | ||
import { DEFAULT_MINIMAL_FEES } from './handlers'; | ||
|
||
/** | ||
* @description Get the current network chain id | ||
* @returns Promise of the chain id as a bigint | ||
*/ | ||
export async function getActiveChainId(): Promise<bigint> { | ||
const chain = await StateManager.getState('activeChainId'); | ||
|
||
if (!chain) { | ||
await StateManager.setState('activeChainId', CHAIN_ID.MainNet.toString()); | ||
return CHAIN_ID.MainNet; | ||
} | ||
return BigInt(chain); | ||
} | ||
|
||
/** | ||
* @description Set the current network using a chain id | ||
* @param chainId - Chain id as a bigint | ||
*/ | ||
export async function setActiveChainId(chainId: bigint) { | ||
await StateManager.setState('activeChainId', chainId.toString()); | ||
} | ||
import { NetworkInfos } from './network'; | ||
|
||
/** | ||
* @description Get the current network url | ||
* @returns Promise of the url as a string | ||
*/ | ||
export async function getActiveRPC(): Promise<string> { | ||
const rpc = await StateManager.getState('activeRPC'); | ||
|
||
if (!rpc) { | ||
await setActiveRPC(DefaultProviderUrls.MAINNET); | ||
return DefaultProviderUrls.MAINNET; | ||
} | ||
|
||
return rpc; | ||
} | ||
const NETWORK_INFO_KEY = 'network_info'; | ||
|
||
export const DEFAULT_MINIMAL_FEES = fromMAS('0.01').toString(); | ||
export const DEFAULT_NETWORK = { | ||
rpcUrl: DefaultProviderUrls.MAINNET, | ||
chainId: CHAIN_ID.MainNet.toString(), | ||
minimalFees: DEFAULT_MINIMAL_FEES, | ||
networkName: MAINNET, | ||
}; | ||
/** | ||
* @description Set the current network using a rpc URL | ||
* @param chainId - Chain id as a bigint | ||
* @description Get the current network | ||
* @returns NetworkInfos | ||
*/ | ||
export async function setActiveRPC(url: string) { | ||
await StateManager.setState('activeRPC', url); | ||
} | ||
export async function getActiveNetwork(): Promise<NetworkInfos> { | ||
const infos = await StateManager.getState(NETWORK_INFO_KEY); | ||
|
||
/** | ||
* @description Get the current minimal fees | ||
* @returns Promise of the minimal fees as a string | ||
*/ | ||
export async function getActiveMinimalFees(): Promise<string> { | ||
const minimalFees = await StateManager.getState('minimalFees'); | ||
|
||
if (!minimalFees) { | ||
await setActiveMinimalFees(DEFAULT_MINIMAL_FEES); | ||
return DEFAULT_MINIMAL_FEES.toString(); | ||
if (!infos) { | ||
await setActiveNetwork(DEFAULT_NETWORK); | ||
return DEFAULT_NETWORK; | ||
} | ||
|
||
return minimalFees; | ||
return infos; | ||
} | ||
|
||
/** | ||
* @description Get the current minimal fees | ||
* @returns Promise of the minimal fees as a string | ||
* @description Set the current network | ||
* @param infos - Network infos | ||
*/ | ||
export async function setActiveMinimalFees(minimal_fees: string) { | ||
await StateManager.setState('minimalFees', minimal_fees); | ||
export async function setActiveNetwork(infos: NetworkInfos) { | ||
await StateManager.setState(NETWORK_INFO_KEY, infos); | ||
} |
Oops, something went wrong.