-
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.
Showing
98 changed files
with
3,379 additions
and
739 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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "@multiversx/sdk-dapp-core", | ||
"version": "0.0.0-alpha.1", | ||
"main": "out/index.js", | ||
"module": "out/index.mjs", | ||
"module": "out/index.js", | ||
"types": "out/index.d.ts", | ||
"description": "A library to hold core logic for building TypeScript dApps on the MultiversX blockchain", | ||
"author": "MultiversX", | ||
|
@@ -20,32 +20,43 @@ | |
}, | ||
"scripts": { | ||
"compile": "tsc && tsc-alias", | ||
"compile-next": "rimraf out && tsc --p tsconfig.next.json && tsc-alias --project tsconfig.next.json", | ||
"build-esbuild": "rimraf out && node esbuild.js", | ||
"publish-verdaccio": "npm unpublish --registry http://localhost:4873 @multiversx/[email protected] && rimraf out && yarn compile && npm publish --registry http://localhost:4873", | ||
"build": "yarn build-esbuild && yarn compile", | ||
"test": "jest" | ||
"test": "jest", | ||
"compile-next": "rimraf out && tsc --p tsconfig.next.json && tsc-alias --project tsconfig.next.json" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@multiversx/sdk-web-wallet-cross-window-provider": "0.1.3", | ||
"@multiversx/sdk-native-auth-client": "^1.0.8", | ||
"@multiversx/sdk-web-wallet-cross-window-provider": "0.2.0", | ||
"@types/lodash": "^4.17.4", | ||
"isomorphic-fetch": "^3.0.0", | ||
"lodash": "^4.17.21", | ||
"zustand": "^4.4.7" | ||
}, | ||
"peerDependencies": { | ||
"@multiversx/sdk-core": ">= 13.0.0", | ||
"@multiversx/sdk-dapp-utils": "^0.0.1", | ||
"@multiversx/sdk-core": ">= 12.18.0", | ||
"axios": ">=1.6.5" | ||
"axios": ">=1.6.5", | ||
"bignumber.js": "9.x" | ||
}, | ||
"resolutions": { | ||
"string-width": "4.1.0" | ||
}, | ||
"devDependencies": { | ||
"@multiversx/sdk-core": ">= 13.0.0", | ||
"@multiversx/sdk-dapp-utils": "^0.0.1", | ||
"@multiversx/sdk-core": ">= 12.18.0", | ||
"@swc/core": "^1.4.17", | ||
"@swc/jest": "^0.2.36", | ||
"@types/node": "20.12.8", | ||
"@typescript-eslint/eslint-plugin": "7.8.0", | ||
"@typescript-eslint/parser": "7.8.0", | ||
"axios": ">=1.6.5", | ||
"axios-mock-adapter": "^1.22.0", | ||
"bignumber.js": "9.x", | ||
"esbuild": "^0.21.1", | ||
"eslint": "9.1.1", | ||
"eslint-config-prettier": "9.1.0", | ||
|
@@ -59,7 +70,7 @@ | |
"immer": "^10.1.1", | ||
"jest": "29.7.0", | ||
"jest-environment-jsdom": "29.7.0", | ||
"lit": "^3.1.3", | ||
"msw": "1.3.1", | ||
"prettier": "3.2.5", | ||
"protobufjs": "^7.3.0", | ||
"react": "^18.3.1", | ||
|
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,11 @@ | ||
import { fallbackNetworkConfigurations } from 'constants/network'; | ||
import { EnvironmentsEnum } from 'types'; | ||
|
||
export const testAddress = | ||
'erd1dm9uxpf5awkn7uhju7zjn9lde0dhahy0qaxqqlu26xcuuw27qqrsqfmej3'; | ||
|
||
export const testNetwork = | ||
fallbackNetworkConfigurations[EnvironmentsEnum.devnet]; | ||
|
||
export const testReceiver = | ||
'erd1qqqqqqqqqqqqqpgqp699jngundfqw07d8jzkepucvpzush6k3wvqyc44rx'; |
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,10 @@ | ||
export const account = { | ||
address: 'erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx', | ||
balance: '116893786890813785912', | ||
nonce: 12320, | ||
shard: 0, | ||
rootHash: 'wICKVeNpCg/TsBRyRyZMMMhcW1KENpAbopfinRVyENQ=', | ||
txCount: 12655, | ||
scrCount: 14084, | ||
developerReward: '0' | ||
}; |
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 const blocks = [ | ||
{ | ||
hash: 'fff67d31476ad920d53093a3a4c2178e198179b35656eeefa419107fa718b780', | ||
timestamp: 1671204768 | ||
} | ||
]; |
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,16 @@ | ||
export const dappConfig = { | ||
id: 'devnet', | ||
name: 'Devnet', | ||
egldLabel: 'xEGLD', | ||
decimals: '4', | ||
egldDenomination: '18', | ||
gasPerDataByte: '1500', | ||
apiTimeout: '4000', | ||
walletConnectDeepLink: | ||
'https://maiar.page.link/?apn=com.elrond.maiar.wallet&isi=1519405832&ibi=com.elrond.maiar.wallet&link=https://xportal.com/', | ||
walletConnectBridgeAddresses: ['https://bridge.walletconnect.org'], | ||
walletAddress: 'https://devnet-wallet.multiversx.com', | ||
apiAddress: 'https://devnet-api.multiversx.com', | ||
explorerAddress: 'http://devnet-explorer.multiversx.com', | ||
chainId: 'D' | ||
}; |
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,7 @@ | ||
export * from './account'; | ||
export * from './blocks'; | ||
export * from './networkConfig'; | ||
export * from './dappConfig'; | ||
export * from './socketResponse'; | ||
export * from './websocketConfig'; | ||
export * from './blocks'; |
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,28 @@ | ||
export const networkConfig = { | ||
data: { | ||
config: { | ||
erd_adaptivity: 'false', | ||
erd_chain_id: 'D', | ||
erd_denomination: 18, | ||
erd_gas_per_data_byte: 1500, | ||
erd_gas_price_modifier: '0.01', | ||
erd_hysteresis: '0.200000', | ||
erd_latest_tag_software_version: 'D1.3.50.0-hf01', | ||
erd_max_gas_per_transaction: 600000000, | ||
erd_meta_consensus_group_size: 58, | ||
erd_min_gas_limit: 50000, | ||
erd_min_gas_price: 1000000000, | ||
erd_min_transaction_version: 1, | ||
erd_num_metachain_nodes: 58, | ||
erd_num_nodes_in_shard: 58, | ||
erd_num_shards_without_meta: 3, | ||
erd_rewards_top_up_gradient_point: '2000000000000000000000000', | ||
erd_round_duration: 6000, | ||
erd_rounds_per_epoch: 1200, | ||
erd_shard_consensus_group_size: 21, | ||
erd_start_time: 1648551600, | ||
erd_top_up_factor: '0.500000' | ||
} | ||
}, | ||
code: 'successful' | ||
}; |
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,7 @@ | ||
export const socketResponse = { | ||
sid: 'RlV7upxKjiJRyIhRAKb5', | ||
upgrades: ['websocket'], | ||
pingInterval: 25000, | ||
pingTimeout: 20000, | ||
maxPayload: 1000000 | ||
}; |
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 @@ | ||
export const websocketConfig = { url: 'devnet-socket-api.multiversx.com' }; |
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,3 @@ | ||
export * from './accountConfig'; | ||
export * from './server'; | ||
export * from './utils'; |
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,55 @@ | ||
import { | ||
DefaultBodyType, | ||
PathParams, | ||
ResponseComposition, | ||
rest, | ||
RestContext, | ||
RestRequest | ||
} from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import { testAddress, testNetwork } from './accountConfig'; | ||
import { | ||
account, | ||
blocks, | ||
dappConfig, | ||
networkConfig, | ||
socketResponse, | ||
websocketConfig | ||
} from './data'; | ||
|
||
export const mockResponse = | ||
<T extends DefaultBodyType>(body: T) => | ||
( | ||
_req: RestRequest<never, PathParams<string>>, | ||
res: ResponseComposition<DefaultBodyType>, | ||
ctx: RestContext | ||
) => { | ||
return res(ctx.status(200), ctx.json(body)); | ||
}; | ||
|
||
const handlers = [ | ||
rest.get(`${testNetwork.apiAddress}/dapp/config`, mockResponse(dappConfig)), | ||
|
||
rest.get( | ||
`${testNetwork.apiAddress}/network/config`, | ||
mockResponse(networkConfig) | ||
), | ||
rest.get( | ||
`https://${websocketConfig.url}/socket.io/`, | ||
mockResponse(socketResponse) | ||
), | ||
rest.get( | ||
`${testNetwork.apiAddress}/websocket/config`, | ||
mockResponse(websocketConfig) | ||
), | ||
rest.get( | ||
`${testNetwork.apiAddress}/accounts/${testAddress}`, | ||
mockResponse(account) | ||
), | ||
rest.get(`${testNetwork.apiAddress}/blocks`, mockResponse(blocks)) | ||
]; | ||
|
||
// This configures a request mocking server with the given request handlers. | ||
const server = setupServer(...handlers); | ||
|
||
export { server, rest }; |
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,2 @@ | ||
export * from './mockWindowLocation'; | ||
export * from './mockWindowHistory'; |
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,24 @@ | ||
export const mockWindowHistory = () => { | ||
if (!window) { | ||
return; | ||
} | ||
|
||
const history = window.history; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
delete window.history; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
window.history = Object.defineProperties( | ||
{}, | ||
{ | ||
...Object.getOwnPropertyDescriptors(history), | ||
pushState: { | ||
configurable: true, | ||
value: jest.fn() | ||
} | ||
} | ||
); | ||
}; |
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,24 @@ | ||
export const mockWindowLocation = () => { | ||
if (!window) { | ||
return; | ||
} | ||
|
||
const location = window.location; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
delete window.location; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
window.location = Object.defineProperties( | ||
{}, | ||
{ | ||
...Object.getOwnPropertyDescriptors(location), | ||
assign: { | ||
configurable: true, | ||
value: jest.fn() | ||
} | ||
} | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './network'; | ||
export * from './placeholders'; | ||
export * from './storage'; | ||
export * from './window'; |
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,8 @@ | ||
/** | ||
* Not Applicable | ||
* @value N/A | ||
*/ | ||
export const N_A = 'N/A'; | ||
|
||
export const ZERO = '0'; | ||
export const ELLIPSIS = '...'; |
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,2 @@ | ||
export const safeWindow = | ||
export const safeWindow: Window = | ||
typeof window !== 'undefined' ? window : ({} as Window); |
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 @@ | ||
export * from './nativeAuth'; |
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,40 @@ | ||
import isString from 'lodash/isString'; | ||
import { decodeBase64 } from 'utils/decoders/base64Utils'; | ||
|
||
export interface DecodedLoginTokenType { | ||
blockHash: string; | ||
extraInfo?: { timestamp: number }; | ||
origin: string; | ||
ttl: number; | ||
} | ||
|
||
export const decodeLoginToken = ( | ||
loginToken: string | ||
): DecodedLoginTokenType | null => { | ||
if (!loginToken || !isString(loginToken)) { | ||
return null; | ||
} | ||
|
||
const parts = loginToken.split('.'); | ||
|
||
if (parts.length !== 4) { | ||
return null; | ||
} | ||
|
||
try { | ||
const [origin, blockHash, ttl, extraInfo] = parts; | ||
const parsedExtraInfo = JSON.parse(decodeBase64(extraInfo)); | ||
const parsedOrigin = decodeBase64(origin); | ||
|
||
return { | ||
ttl: Number(ttl), | ||
extraInfo: parsedExtraInfo, | ||
origin: parsedOrigin, | ||
blockHash | ||
}; | ||
} catch (e) { | ||
console.error(`Error trying to decode ${loginToken}:`, e); | ||
|
||
return null; | ||
} | ||
}; |
Oops, something went wrong.