@sleet-js/fastintear-custom-client-setup-with-other-custom-functions 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +43 -0
- package/TODO.md +8 -0
- package/package.json +29 -0
- package/src/createNearClient.ts +38 -0
- package/src/index.ts +27 -0
- package/src/network/README.md +11 -0
- package/src/network/index.ts +21 -0
- package/src/other/accountId.ts +13 -0
- package/src/other/key_types.ts +24 -0
- package/src/other/keys.ts +30 -0
- package/src/ref/.gitkeep +0 -0
- package/src/ref/README.md +10 -0
- package/src/ref/ref_const.ts +15 -0
- package/src/ref/ref_functions.ts +79 -0
- package/src/ref/ref_types.ts +22 -0
- package/src/svelte/button_auth.svelte +56 -0
- package/src/svelte/button_network_toggle.svelte +36 -0
- package/tsconfig.json +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 sleet.near
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# fastintear-custom-client-setup-with-other-custom-functions
|
|
2
|
+
a custom fastintear near client setup and functions for interacting with common smart contracts to assist in dapp development.
|
|
3
|
+
|
|
4
|
+
ℹ️ expected for use in browser environment
|
|
5
|
+
|
|
6
|
+
ℹ️ developed for internal use and i don't have time to documnet everything
|
|
7
|
+
|
|
8
|
+
ℹ️ no error handling
|
|
9
|
+
|
|
10
|
+
ℹ️ not an exchustive list of functions, but i can add based on request
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
develop and publish this package
|
|
15
|
+
```bash
|
|
16
|
+
bun install
|
|
17
|
+
# bun run index.ts
|
|
18
|
+
bun publish --dry-run
|
|
19
|
+
bunx npm login
|
|
20
|
+
bun publish --access public
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
### FEATURES
|
|
26
|
+
|
|
27
|
+
- dynamic network support
|
|
28
|
+
- typescript
|
|
29
|
+
- svelte auth and network button
|
|
30
|
+
|
|
31
|
+
## HOW TO USE
|
|
32
|
+
|
|
33
|
+
import
|
|
34
|
+
```js
|
|
35
|
+
import { nearClient } from '@sleet-js/fastintear-custom-client-setup-with-other-custom-functions';
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
This project was created using `bun init` in bun v1.2.12. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
|
|
42
|
+
|
|
43
|
+
copyright 2025 by sleet.near
|
package/TODO.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sleet-js/fastintear-custom-client-setup-with-other-custom-functions",
|
|
3
|
+
"description": "a custom fastintear near client setup",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"module": "src/index.ts",
|
|
6
|
+
"homepage": "https://sleet-js.near.page",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/sleet-js/fastintear-custom-client-setup-with-other-custom-functions.git"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/bun": "latest"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"typescript": "^5"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@sleet-js/ft-methods-const": "^0.0.5",
|
|
24
|
+
"@sleet-js/ref-exchange-methods-const": "^0.0.2",
|
|
25
|
+
"fastintear": "^0.3.8",
|
|
26
|
+
"svelte": "^5.46.1",
|
|
27
|
+
"zod": "^4.2.1"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/ts/fastintear/createNearClient.ts
|
|
2
|
+
// This file handles near client setup
|
|
3
|
+
// and has function to getStoredNetworkId
|
|
4
|
+
// ===========================================
|
|
5
|
+
import { createNearClient } from "fastintear";
|
|
6
|
+
import * as near from "fastintear";
|
|
7
|
+
// ===========================================
|
|
8
|
+
// used for network toggle
|
|
9
|
+
export const NETWORK_STORAGE_KEY = "network_id";
|
|
10
|
+
//
|
|
11
|
+
export function getStoredNetworkId(): "mainnet" | "testnet" {
|
|
12
|
+
const raw = localStorage.getItem(NETWORK_STORAGE_KEY);
|
|
13
|
+
const value = (raw || "mainnet").trim().toLowerCase();
|
|
14
|
+
// also global near needs to be configured. easiest to make sure right everytime we need
|
|
15
|
+
near.config({ networkId: value });
|
|
16
|
+
return value === "testnet" ? "testnet" : "mainnet";
|
|
17
|
+
}
|
|
18
|
+
// ===========================================
|
|
19
|
+
// Multiple clients with different configurations
|
|
20
|
+
const near_mainnetClient = createNearClient({ networkId: "mainnet" });
|
|
21
|
+
const near_testnetClient = createNearClient({ networkId: "testnet" });
|
|
22
|
+
//
|
|
23
|
+
export function nearClient() {
|
|
24
|
+
const networkId = getStoredNetworkId();
|
|
25
|
+
const client =
|
|
26
|
+
networkId === "testnet" ? near_testnetClient : near_mainnetClient;
|
|
27
|
+
|
|
28
|
+
console.log("[nearClient] networkId:", networkId);
|
|
29
|
+
console.log(
|
|
30
|
+
"[nearClient] client:",
|
|
31
|
+
networkId === "testnet" ? "near_testnetClient" : "near_mainnetClient",
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return client;
|
|
35
|
+
}
|
|
36
|
+
// ================================================
|
|
37
|
+
// ================================================
|
|
38
|
+
// copyright 2025 by sleet.near
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// nearClient
|
|
2
|
+
export {
|
|
3
|
+
nearClient,
|
|
4
|
+
getStoredNetworkId,
|
|
5
|
+
NETWORK_STORAGE_KEY,
|
|
6
|
+
} from "./createNearClient";
|
|
7
|
+
// network
|
|
8
|
+
export {
|
|
9
|
+
toggleNetwork,
|
|
10
|
+
setNetwork_mainnet,
|
|
11
|
+
setNetwork_testnet,
|
|
12
|
+
} from "./network/index";
|
|
13
|
+
// ref
|
|
14
|
+
export { ref_contractId_for_network } from "./ref/ref_const";
|
|
15
|
+
export {
|
|
16
|
+
ref_get_number_of_pools_function,
|
|
17
|
+
ref_get_pool_function,
|
|
18
|
+
ref_get_pools_function,
|
|
19
|
+
ref_add_simple_pool_function,
|
|
20
|
+
} from "./ref/ref_functions";
|
|
21
|
+
// other
|
|
22
|
+
export { get_nearClient_accountId } from "./other/accountId"
|
|
23
|
+
export { delete_key_fun, get_key_list_fun } from "./other/keys"
|
|
24
|
+
export type { ACCESS_KEY_INTERFACE } from "./other/key_types"
|
|
25
|
+
// ================================================
|
|
26
|
+
// ================================================
|
|
27
|
+
// copyright 2025 by sleet.near
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# network
|
|
2
|
+
|
|
3
|
+
I wanted network setting to be easy. no reloading.
|
|
4
|
+
|
|
5
|
+
the client gets the network every time we use it.
|
|
6
|
+
|
|
7
|
+
and we can set the setwork in a varity of ways, basicly however you want to set the local storge item.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
copyright 2025 by sleet.near
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NETWORK_STORAGE_KEY } from "../createNearClient";
|
|
2
|
+
// ===========================================
|
|
3
|
+
let NETWORK_ID: string;
|
|
4
|
+
//
|
|
5
|
+
export function toggleNetwork() {
|
|
6
|
+
const savedNetwork = localStorage.getItem(NETWORK_STORAGE_KEY) || "mainnet";
|
|
7
|
+
NETWORK_ID = savedNetwork;
|
|
8
|
+
const newNetwork = NETWORK_ID === "mainnet" ? "testnet" : "mainnet";
|
|
9
|
+
NETWORK_ID = newNetwork;
|
|
10
|
+
localStorage.setItem(NETWORK_STORAGE_KEY, newNetwork);
|
|
11
|
+
console.info(newNetwork);
|
|
12
|
+
}
|
|
13
|
+
//
|
|
14
|
+
export function setNetwork_mainnet() {
|
|
15
|
+
let NETWORK_ID = "mainnet";
|
|
16
|
+
localStorage.setItem(NETWORK_STORAGE_KEY, NETWORK_ID);
|
|
17
|
+
}
|
|
18
|
+
export function setNetwork_testnet() {
|
|
19
|
+
let NETWORK_ID = "testnet";
|
|
20
|
+
localStorage.setItem(NETWORK_STORAGE_KEY, NETWORK_ID);
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { nearClient } from "../createNearClient";
|
|
2
|
+
// ==========================================
|
|
3
|
+
// ==========================================
|
|
4
|
+
// handy when you need a string.
|
|
5
|
+
export function get_nearClient_accountId() {
|
|
6
|
+
const accountId: string = nearClient().accountId() ?? "";
|
|
7
|
+
console.log("accountId");
|
|
8
|
+
console.log(accountId);
|
|
9
|
+
return typeof accountId === "string" ? accountId : accountId;
|
|
10
|
+
}
|
|
11
|
+
// ================================================
|
|
12
|
+
// ================================================
|
|
13
|
+
// copyright 2025 by sleet.near
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// ACCESS_KEY_INTERFACE
|
|
2
|
+
export interface ACCESS_KEY_INTERFACE {
|
|
3
|
+
access_key: {
|
|
4
|
+
nonce: number; // large integer; if you need BigInt, change to bigint
|
|
5
|
+
permission: AccessKeyPermission;
|
|
6
|
+
};
|
|
7
|
+
public_key: string; // e.g. "ed25519:..."
|
|
8
|
+
}
|
|
9
|
+
// ===============================================
|
|
10
|
+
// Permission can be either FullAccess or FunctionCall
|
|
11
|
+
type AccessKeyPermission = FullAccessPermission | FunctionCallPermission;
|
|
12
|
+
interface FullAccessPermission {
|
|
13
|
+
// When it's full access, NEAR returns: { permission: "FullAccess" }
|
|
14
|
+
// Represented here as a discriminated union
|
|
15
|
+
FullAccess: Record<string, never>;
|
|
16
|
+
}
|
|
17
|
+
interface FunctionCallPermission {
|
|
18
|
+
FunctionCall: {
|
|
19
|
+
// On NEAR RPC these large numeric strings are yoctoNEAR, so keep as string to avoid precision loss
|
|
20
|
+
allowance?: string; // optional: sometimes not present
|
|
21
|
+
method_names: string[];
|
|
22
|
+
receiver_id: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { nearClient } from "../createNearClient";
|
|
2
|
+
import type { ACCESS_KEY_INTERFACE } from "./key_types";
|
|
3
|
+
// ==========================================
|
|
4
|
+
// args list:
|
|
5
|
+
// - publicKey
|
|
6
|
+
// - account_id
|
|
7
|
+
// ==========================================
|
|
8
|
+
// delete_key_fun
|
|
9
|
+
export async function delete_key_fun(accountId: string, publicKey: string) {
|
|
10
|
+
await nearClient().sendTx({
|
|
11
|
+
receiverId: accountId,
|
|
12
|
+
actions: [
|
|
13
|
+
nearClient().actions.deleteKey({
|
|
14
|
+
publicKey: publicKey,
|
|
15
|
+
}),
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
// ==========================================
|
|
20
|
+
// get_key_list_fun
|
|
21
|
+
export async function get_key_list_fun(account_id: string) {
|
|
22
|
+
const response = await nearClient().sendRpc("query", {
|
|
23
|
+
request_type: "view_access_key_list",
|
|
24
|
+
account_id,
|
|
25
|
+
finality: "final",
|
|
26
|
+
});
|
|
27
|
+
const keys: ACCESS_KEY_INTERFACE[] = response.result.keys;
|
|
28
|
+
return keys;
|
|
29
|
+
}
|
|
30
|
+
// ==========================================
|
package/src/ref/.gitkeep
ADDED
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ref_mainnet_contractId_const,
|
|
3
|
+
ref_testnet_contractId_const,
|
|
4
|
+
} from "@sleet-js/ref-exchange-methods-const";
|
|
5
|
+
import { getStoredNetworkId } from "../createNearClient";
|
|
6
|
+
//
|
|
7
|
+
export function ref_contractId_for_network() {
|
|
8
|
+
const networkId = getStoredNetworkId();
|
|
9
|
+
const ref_contractId =
|
|
10
|
+
networkId === "testnet"
|
|
11
|
+
? ref_testnet_contractId_const
|
|
12
|
+
: ref_mainnet_contractId_const;
|
|
13
|
+
console.log("ref contractId", ref_contractId);
|
|
14
|
+
return ref_contractId;
|
|
15
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// CLEAN REUSABLE FUNCTIONS FOR INTERACTING WITH AND GETTING DATA FROM REF CONTRACT
|
|
2
|
+
// depends on nearClient
|
|
3
|
+
import { nearClient } from "../createNearClient";
|
|
4
|
+
import { ref_exchange_methods_const } from "@sleet-js/ref-exchange-methods-const";
|
|
5
|
+
import { ref_contractId_for_network } from "./ref_const";
|
|
6
|
+
import type { REF_GET_POOL_TYPE } from "./ref_types";
|
|
7
|
+
import {
|
|
8
|
+
REF_GET_POOL_TYPE_Z_CONST,
|
|
9
|
+
REF_GET_POOLS_TYPE_Z_CONST,
|
|
10
|
+
} from "./ref_types";
|
|
11
|
+
// ================================================
|
|
12
|
+
interface ref_args_params_interface {
|
|
13
|
+
pool_id: number;
|
|
14
|
+
from_index: number;
|
|
15
|
+
limit: number;
|
|
16
|
+
fee: number;
|
|
17
|
+
tokens: string[];
|
|
18
|
+
}
|
|
19
|
+
// ================================================
|
|
20
|
+
// get_number_of_pools_function
|
|
21
|
+
// Fetch the total number of pools
|
|
22
|
+
export async function ref_get_number_of_pools_function(): Promise<number> {
|
|
23
|
+
const result = await nearClient().view({
|
|
24
|
+
contractId: ref_contractId_for_network(),
|
|
25
|
+
methodName: ref_exchange_methods_const.get_number_of_pools,
|
|
26
|
+
args: {},
|
|
27
|
+
});
|
|
28
|
+
return result as number;
|
|
29
|
+
}
|
|
30
|
+
// ================================================
|
|
31
|
+
// get_pool_function
|
|
32
|
+
export async function ref_get_pool_function(
|
|
33
|
+
pool_id: ref_args_params_interface["pool_id"],
|
|
34
|
+
): Promise<REF_GET_POOL_TYPE> {
|
|
35
|
+
const result = await nearClient().view({
|
|
36
|
+
contractId: ref_contractId_for_network(),
|
|
37
|
+
methodName: ref_exchange_methods_const.get_pool,
|
|
38
|
+
args: { pool_id: pool_id },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return REF_GET_POOL_TYPE_Z_CONST.parse(result);
|
|
42
|
+
}
|
|
43
|
+
// ================================================
|
|
44
|
+
// get_pools_function
|
|
45
|
+
export async function ref_get_pools_function(
|
|
46
|
+
from_index: ref_args_params_interface["from_index"],
|
|
47
|
+
limit: ref_args_params_interface["limit"],
|
|
48
|
+
): Promise<REF_GET_POOL_TYPE[]> {
|
|
49
|
+
const result = await nearClient().view({
|
|
50
|
+
contractId: ref_contractId_for_network(),
|
|
51
|
+
methodName: ref_exchange_methods_const.get_pools,
|
|
52
|
+
args: { from_index, limit },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return REF_GET_POOLS_TYPE_Z_CONST.parse(result);
|
|
56
|
+
}
|
|
57
|
+
// ================================================
|
|
58
|
+
// add_simple_pool_function
|
|
59
|
+
export async function ref_add_simple_pool_function(
|
|
60
|
+
fee: ref_args_params_interface["fee"],
|
|
61
|
+
tokens: ref_args_params_interface["tokens"],
|
|
62
|
+
) {
|
|
63
|
+
const result = await nearClient().sendTx({
|
|
64
|
+
receiverId: ref_contractId_for_network(),
|
|
65
|
+
actions: [
|
|
66
|
+
nearClient().actions.functionCall({
|
|
67
|
+
methodName: ref_exchange_methods_const.add_simple_pool,
|
|
68
|
+
args: { fee: fee, tokens: tokens },
|
|
69
|
+
gas: "30000000000000", // 30 TGas
|
|
70
|
+
deposit: "9000000000000000000000", // 0.009
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
console.log(result);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
// ================================================
|
|
78
|
+
// ================================================
|
|
79
|
+
// copyright 2025 by sleet.near
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
// ref types
|
|
3
|
+
// ==============================
|
|
4
|
+
// ==============================
|
|
5
|
+
export interface REF_GET_POOL_TYPE {
|
|
6
|
+
pool_kind: string;
|
|
7
|
+
token_account_ids: string[];
|
|
8
|
+
amounts: string[];
|
|
9
|
+
total_fee: number;
|
|
10
|
+
shares_total_supply: string;
|
|
11
|
+
amp: number;
|
|
12
|
+
}
|
|
13
|
+
// ==============================
|
|
14
|
+
export const REF_GET_POOL_TYPE_Z_CONST = z.object({
|
|
15
|
+
pool_kind: z.string(),
|
|
16
|
+
token_account_ids: z.array(z.string()),
|
|
17
|
+
amounts: z.array(z.string()),
|
|
18
|
+
total_fee: z.number(),
|
|
19
|
+
shares_total_supply: z.string(),
|
|
20
|
+
amp: z.number(),
|
|
21
|
+
}) satisfies z.ZodType<REF_GET_POOL_TYPE>;
|
|
22
|
+
export const REF_GET_POOLS_TYPE_Z_CONST = z.array(REF_GET_POOL_TYPE_Z_CONST);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<!-- -->
|
|
2
|
+
<!-- =========================================== -->
|
|
3
|
+
<!-- -->
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { onMount } from "svelte";
|
|
7
|
+
import { nearClient } from "../createNearClient";
|
|
8
|
+
|
|
9
|
+
let isSignedIn: boolean = false;
|
|
10
|
+
let accountId: string | null = null;
|
|
11
|
+
|
|
12
|
+
async function updateAuthStatus() {
|
|
13
|
+
const status = nearClient().authStatus();
|
|
14
|
+
isSignedIn = status === "SignedIn";
|
|
15
|
+
accountId = isSignedIn ? nearClient().accountId() : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function handleLogin() {
|
|
19
|
+
try {
|
|
20
|
+
await nearClient().requestSignIn();
|
|
21
|
+
await updateAuthStatus();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error("Login failed:", error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function handleLogout() {
|
|
28
|
+
try {
|
|
29
|
+
await nearClient().signOut();
|
|
30
|
+
await updateAuthStatus();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error("Logout failed:", error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
onMount(async () => {
|
|
37
|
+
await updateAuthStatus();
|
|
38
|
+
});
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<!-- -->
|
|
42
|
+
<!-- =========================================== -->
|
|
43
|
+
<!-- -->
|
|
44
|
+
|
|
45
|
+
<!-- AUTH_BUTTON -->
|
|
46
|
+
{#if isSignedIn}
|
|
47
|
+
<button on:click={handleLogout}>
|
|
48
|
+
LOGOUT {accountId}
|
|
49
|
+
</button>
|
|
50
|
+
{:else}
|
|
51
|
+
<button on:click={handleLogin}> LOGIN </button>
|
|
52
|
+
{/if}
|
|
53
|
+
|
|
54
|
+
<!-- -->
|
|
55
|
+
<!-- =========================================== -->
|
|
56
|
+
<!-- -->
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!-- -->
|
|
2
|
+
<!-- =========================================== -->
|
|
3
|
+
<!-- -->
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { onMount } from "svelte";
|
|
7
|
+
import { NETWORK_STORAGE_KEY } from "../createNearClient";
|
|
8
|
+
|
|
9
|
+
let NETWORK_ID: string = "mainnet";
|
|
10
|
+
|
|
11
|
+
onMount(() => {
|
|
12
|
+
// Initialize network ID from localStorage
|
|
13
|
+
const savedNetwork = localStorage.getItem("network_id") || "mainnet";
|
|
14
|
+
NETWORK_ID = savedNetwork;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function toggleNetwork() {
|
|
18
|
+
const newNetwork = NETWORK_ID === "mainnet" ? "testnet" : "mainnet";
|
|
19
|
+
NETWORK_ID = newNetwork;
|
|
20
|
+
localStorage.setItem(NETWORK_STORAGE_KEY, newNetwork);
|
|
21
|
+
console.info(newNetwork);
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<!-- -->
|
|
26
|
+
<!-- =========================================== -->
|
|
27
|
+
<!-- -->
|
|
28
|
+
|
|
29
|
+
<!-- NETWORK_BUTTON -->
|
|
30
|
+
<button on:click={toggleNetwork}>
|
|
31
|
+
{NETWORK_ID.toUpperCase()}
|
|
32
|
+
</button>
|
|
33
|
+
|
|
34
|
+
<!-- -->
|
|
35
|
+
<!-- =========================================== -->
|
|
36
|
+
<!-- -->
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
// Best practices
|
|
18
|
+
"strict": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedIndexedAccess": true,
|
|
22
|
+
|
|
23
|
+
// Some stricter flags (disabled by default)
|
|
24
|
+
"noUnusedLocals": false,
|
|
25
|
+
"noUnusedParameters": false,
|
|
26
|
+
"noPropertyAccessFromIndexSignature": false
|
|
27
|
+
},
|
|
28
|
+
"include": ["src"]
|
|
29
|
+
}
|