Skip to content
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

Added network store #1

Merged
merged 30 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c98d2cb
Create network model
arhtudormorar Apr 18, 2024
de506b2
Create network model
arhtudormorar Apr 26, 2024
eb4f05c
Create combined store
arhtudormorar Apr 26, 2024
20ff774
Added immer
arhtudormorar Apr 26, 2024
610db62
merged stores
arhtudormorar Apr 26, 2024
aa430e2
Not working immer
arhtudormorar Apr 27, 2024
9d0716b
Return to working version
arhtudormorar Apr 27, 2024
b0b7c40
Immer working
arhtudormorar Apr 27, 2024
95c6218
Network full state definition
arhtudormorar Apr 27, 2024
11fd7c9
Build store working
arhtudormorar Apr 27, 2024
5e0de1d
try refactor network
arhtudormorar Apr 29, 2024
37909e9
Export react store working
arhtudormorar Apr 29, 2024
b511bfa
Logger and shared slices working
arhtudormorar Apr 30, 2024
f437b49
Custom Events working
arhtudormorar Apr 30, 2024
81e38d3
Add logout to network
arhtudormorar Apr 30, 2024
393f817
Minor renamings
arhtudormorar Apr 30, 2024
56bc80c
Renamed models to slices
arhtudormorar Apr 30, 2024
eb0ceff
Migrate network related functions
arhtudormorar May 1, 2024
06299d7
Added absolute imports
arhtudormorar May 1, 2024
dd47fa2
Added storage
arhtudormorar May 1, 2024
6ff06d6
Added next tsconfig
arhtudormorar May 1, 2024
5ed8009
Fixed alpha
arhtudormorar May 1, 2024
2953489
0.0.1-alpha.0
arhtudormorar May 1, 2024
8e5d9fc
Revert 0
arhtudormorar May 1, 2024
30e4737
Revert 0
arhtudormorar May 1, 2024
5012314
0.0.0-alpha.0
arhtudormorar May 1, 2024
9588af4
Added github actions
arhtudormorar May 1, 2024
78295a0
Update changelog
arhtudormorar May 1, 2024
bcff059
Add eslint
arhtudormorar May 1, 2024
3116686
Add eslint
arhtudormorar May 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"env": {
"es2021": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
"project": "./tsconfig.json"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"],
"moduleDirectory": ["node_modules", "src/"]
},
"typescript": {
"alwaysTryTypes": true
}
}
},
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:prettier/recommended"
],
"plugins": ["prettier", "import"],
"rules": {
"import/order": [
"warn",
{
"groups": ["builtin", "external", "internal"],
"pathGroups": [
{
"pattern": "react",
"group": "external",
"position": "before"
}
],
"newlines-between": "ignore",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],
"prettier/prettier": [
"error",
{
"endOfLine": "lf"
}
],
"@typescript-eslint/indent": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-use-before-define": ["error", {"functions": false, "classes": false}],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"object-curly-newline": "off",
"arrow-body-style": "off",
"implicit-arrow-linebreak": "off",
"func-names": "off",
"curly": ["error", "all"],
"operator-linebreak": "off",
"function-paren-newline": "off",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "off"
}
}
22 changes: 22 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Issue/Feature

### Reproduce
Issue exists on version `2.` of sdk-dapp.

### Root cause

### Fix

### Additional changes

### Contains breaking changes
[x] No

[] Yes

### Updated CHANGELOG
[x] Yes

### Testing
[x] User testing
[] Unit tests
16 changes: 16 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "CHANGELOG entry secretary"
on:
pull_request:
branches: [main, development]
# The specific activity types are listed here to include "labeled" and "unlabeled"
# (which are not included by default for the "pull_request" trigger).
# This is needed to allow skipping enforcement of the changelog in PRs with specific labels,
# as defined in the (optional) "skipLabels" property.
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
# Enforces the update of a changelog file on every pull request
changelog:
runs-on: ubuntu-latest
steps:
- uses: dangoslen/changelog-enforcer@v3
52 changes: 52 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publish sdk-dapp

on:
push:
branches: [main]
repository_dispatch:
types: publish-npm
workflow_dispatch:

permissions:
contents: write

jobs:
publish-npm:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
with:
node-version: 18
registry-url: https://registry.npmjs.org/

- name: Setup yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install

- name: Run tests
run: yarn test

- name: Build project
run: yarn build

- name: Get package info
id: package
uses: andreigiura/action-nodejs-package-info@v1.0.2

- name: Publish to npmjs next version
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.package.outputs.is-prerelease == 'true'}}
run: echo ${{ steps.package.outputs.is-prerelease}} && cd dist && npm publish --tag next

- name: Publish to npmjs
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.package.outputs.is-prerelease == 'false' }}
run: cd dist && npm publish
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Change Log

All notable changes will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- [Added network store](https://github.com/multiversx/mx-sdk-dapp-core/pull/1)

## [[v0.0.0]](https://github.com/multiversx/mx-sdk-dapp-core)] - 2024-04-17
47 changes: 27 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "@multiversx/sdk-dapp-core",
"version": "0.0.0",
"version": "0.0.0-alpha.0",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"description": "A library to hold core logic for building TypeScript dApps on the MultiversX blockchain",
"author": "MultiversX",
"license": "MIT",
Expand All @@ -21,32 +22,38 @@
"scripts": {
"test": "node ./__tests__/react-library.test.js",
"compile": "npm run tsc",
"compile-next": "tsc --p tsconfig.next.json",
"tsc": "tsc -p . --outDir ./dist"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@multiversx/sdk-core": "^12.19.1",
"@multiversx/sdk-dapp-ui": "*",
"zustand": "^4.4.7",
"@multiversx/sdk-web-wallet-cross-window-provider": "0.0.37"
"@multiversx/sdk-web-wallet-cross-window-provider": "0.1.3",
"zustand": "^4.4.7"
},
"peerDependencies": {
"@multiversx/sdk-core": ">= 12.18.0",
"axios": ">=1.6.5"
},
"devDependencies": {
"@types/react": "^18.2.65",
"eslint-plugin-vitest": "^0.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.4.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^17.0.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.34.1",
"prettier": "^3.1.0"
"@multiversx/sdk-core": ">= 12.18.0",
"axios": ">=1.6.5",
"@types/node": "18.19.0",
"@typescript-eslint/eslint-plugin": "5.0.0",
"@typescript-eslint/parser": "5.14.0",
"eslint": "8.24.0",
"eslint-config-prettier": "8.5.0",
"eslint-config-standard": "17.0.0",
"eslint-import-resolver-typescript": "2.4.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-promise": "6.0.0",
"jest": "29.6.2",
"jest-environment-jsdom": "28.1.3",
"prettier": "3.1.0",
"ts-jest": "29.1.1",
"typescript": "5.0.4"
}
}
34 changes: 34 additions & 0 deletions src/apiCalls/configuration/getNetworkConfigFromApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import axios from 'axios';
import { getCleanApiAddress } from 'store/slices/network/actions/getCleanApiAddress';
import { ApiNetworkConfigType } from 'types/network.types';
import { NETWORK_CONFIG_ENDPOINT } from '../endpoints';

const urlIsValid = (url: string) => {
try {
return Boolean(new URL(url));
} catch {
return false;
}
};

export async function getNetworkConfigFromApi() {
const apiAddress = getCleanApiAddress();

if (!urlIsValid(apiAddress)) {
return null;
}

const configUrl = `${apiAddress}/${NETWORK_CONFIG_ENDPOINT}`;

try {
const { data } = await axios.get<{
data: { config: ApiNetworkConfigType };
}>(configUrl);
if (data != null) {
return data?.data?.config;
}
} catch (err) {
console.error('error fetching configuration for ', configUrl);
}
return null;
}
15 changes: 15 additions & 0 deletions src/apiCalls/configuration/getServerConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import axios from 'axios';
import { NetworkType } from 'types/network.types';
import { CONFIG_ENDPOINT } from '../endpoints';

export async function getServerConfiguration(apiAddress: string) {
const configUrl = `${apiAddress}/${CONFIG_ENDPOINT}`;

try {
const { data } = await axios.get<NetworkType>(configUrl);
return data;
} catch (err) {
console.error('error fetching configuration for ', configUrl);
}
return null;
}
25 changes: 25 additions & 0 deletions src/apiCalls/endpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const ACCOUNTS_ENDPOINT = 'accounts';
export const ADDRESS_ENDPOINT = 'address';
export const BLOCKS_ENDPOINT = 'blocks';
export const CODE_ENDPOINT = 'code';
export const COLLECTIONS_ENDPOINT = 'collections';
export const CONFIG_ENDPOINT = 'dapp/config';
export const CONTRACTS_ENDPOINT = 'contracts';
export const ECONOMICS_ENDPOINT = 'economics';
export const IDENTITIES_ENDPOINT = 'identities';
export const KEYS_ENDPOINT = 'keys';
export const LOCKED_ACCOUNTS_ENDPOINT = 'locked-accounts';
export const LOGS_ENDPOINT = 'logs';
export const MINIBLOCKS_ENDPOINT = 'miniblocks';
export const NETWORK_CONFIG_ENDPOINT = 'network/config';
export const NFTS_ENDPOINT = 'nfts';
export const NODES_ENDPOINT = 'nodes';
export const PROVIDERS_ENDPOINT = 'providers';
export const ROLES_ENDPOINT = 'roles';
export const SC_RESULTS_ENDPOINT = 'sc-results';
export const STAKE_ENDPOINT = 'stake';
export const TOKENS_ENDPOINT = 'tokens';
export const TRANSACTIONS_COUNT_ENDPOINT = 'transactions/count';
export const TRANSACTIONS_BATCH = 'batch';
export const TRANSACTIONS_ENDPOINT = 'transactions';
export const TRANSFERS_ENDPOINT = 'transfers';
Loading