@suilend/sui-fe-next 3.0.9 → 3.1.0
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/README.md +110 -5
- package/contexts/SettingsContext.d.ts +8 -1
- package/contexts/SettingsContext.jsx +55 -51
- package/contexts/WalletContext.d.ts +1 -1
- package/contexts/WalletContext.jsx +330 -463
- package/fetchers/useFetchBalances.js +32 -92
- package/hooks/keypair.d.ts +1 -1
- package/hooks/keypair.js +7 -7
- package/hooks/useCoinMetadataMap.js +12 -69
- package/hooks/useIsAndroid.jsx +1 -1
- package/hooks/useIsTouchscreen.jsx +3 -5
- package/hooks/useIsiOS.jsx +4 -6
- package/hooks/useLedgerHashDialog.js +16 -61
- package/hooks/useRefreshOnBalancesChange.js +28 -81
- package/lib/connector.js +32 -77
- package/lib/router.d.ts +1 -1
- package/lib/router.js +2 -2
- package/lib/toasts.jsx +32 -40
- package/lib/track.js +3 -3
- package/package.json +85 -1
- package/tsconfig.tsbuildinfo +0 -1
package/lib/toasts.jsx
CHANGED
|
@@ -1,49 +1,41 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import BigNumber from "bignumber.js";
|
|
13
2
|
import { toast as sonnerToast } from "sonner";
|
|
14
3
|
import { TOAST_DURATION_MS, TX_TOAST_DURATION as TX_TOAST_DURATION_MS, formatToken, } from "@suilend/sui-fe";
|
|
15
|
-
|
|
16
|
-
for (
|
|
4
|
+
const onDismiss = (callback) => {
|
|
5
|
+
for (let i = 0; i < 10; i++)
|
|
17
6
|
sonnerToast.dismiss();
|
|
18
|
-
setTimeout(
|
|
7
|
+
setTimeout(() => {
|
|
19
8
|
callback();
|
|
20
9
|
}, 250);
|
|
21
10
|
};
|
|
22
|
-
export
|
|
11
|
+
export const showSuccessToast = (title, data, isTxn) => {
|
|
23
12
|
console.log(title, data);
|
|
24
|
-
onDismiss(
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
onDismiss(() => sonnerToast.success(title, {
|
|
14
|
+
...(data || {}),
|
|
15
|
+
duration: isTxn ? TX_TOAST_DURATION_MS : TOAST_DURATION_MS,
|
|
16
|
+
}));
|
|
27
17
|
};
|
|
28
|
-
export
|
|
18
|
+
export const showInfoToast = (title, data) => {
|
|
29
19
|
console.log(title, data);
|
|
30
|
-
onDismiss(
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
onDismiss(() => sonnerToast.info(title, {
|
|
21
|
+
...(data || {}),
|
|
22
|
+
duration: TOAST_DURATION_MS,
|
|
23
|
+
}));
|
|
33
24
|
};
|
|
34
|
-
export
|
|
25
|
+
export const showWarningToast = (title, data) => {
|
|
35
26
|
console.warn(title, data);
|
|
36
|
-
onDismiss(
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
onDismiss(() => sonnerToast.warning(title, {
|
|
28
|
+
...(data || {}),
|
|
29
|
+
duration: TOAST_DURATION_MS,
|
|
30
|
+
}));
|
|
39
31
|
};
|
|
40
|
-
export
|
|
32
|
+
export const showErrorToast = (title, err, data, isTxn) => {
|
|
41
33
|
console.error(err);
|
|
42
|
-
|
|
34
|
+
let description = err?.message || "An unknown error occurred";
|
|
43
35
|
// RPC errors
|
|
44
36
|
if (description.toLowerCase().includes("Invalid u256 value".toLowerCase()))
|
|
45
37
|
return;
|
|
46
|
-
|
|
38
|
+
const RPC_ERROR_PATTERNS = [
|
|
47
39
|
"failed to fetch",
|
|
48
40
|
"networkerror",
|
|
49
41
|
"network request failed",
|
|
@@ -56,27 +48,27 @@ export var showErrorToast = function (title, err, data, isTxn) {
|
|
|
56
48
|
"etimedout",
|
|
57
49
|
"err_network",
|
|
58
50
|
];
|
|
59
|
-
if (RPC_ERROR_PATTERNS.some(
|
|
60
|
-
return description.toLowerCase().includes(pattern);
|
|
61
|
-
})) {
|
|
51
|
+
if (RPC_ERROR_PATTERNS.some((pattern) => description.toLowerCase().includes(pattern))) {
|
|
62
52
|
description = "Try switching RPC provider in Settings";
|
|
63
53
|
}
|
|
64
54
|
// Insufficient SUI balance to pay for gas
|
|
65
55
|
if (description.toLowerCase().includes("Balance of gas object".toLowerCase())) {
|
|
66
|
-
|
|
56
|
+
const match = description.match(/Balance of gas object (\d+) is lower than the needed amount: (\d+)/);
|
|
67
57
|
if (match) {
|
|
68
|
-
|
|
69
|
-
description =
|
|
58
|
+
const [, balanceRaw, neededAmountRaw] = match;
|
|
59
|
+
description = `Insufficient SUI balance to pay for gas. Balance: ${formatToken(new BigNumber(balanceRaw).div(10 ** 9), { dp: 9, trimTrailingZeros: true })} SUI. Required: ${formatToken(new BigNumber(neededAmountRaw).div(10 ** 9), { dp: 9, trimTrailingZeros: true })} SUI`;
|
|
70
60
|
}
|
|
71
61
|
}
|
|
72
62
|
// Ledger
|
|
73
63
|
if (description.toLowerCase() ===
|
|
74
64
|
"Make sure the Sui app is open on your device.".toLowerCase()) {
|
|
75
|
-
description =
|
|
65
|
+
description = `${description.slice(0, -1)} and set 'Using a Ledger' to ON in Settings.`;
|
|
76
66
|
}
|
|
77
67
|
if (description[0].toLowerCase() === description[0])
|
|
78
|
-
description =
|
|
79
|
-
onDismiss(
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
description = `${description[0].toUpperCase()}${description.slice(1)}`;
|
|
69
|
+
onDismiss(() => sonnerToast.error(title, {
|
|
70
|
+
...(data || {}),
|
|
71
|
+
description,
|
|
72
|
+
duration: isTxn ? TX_TOAST_DURATION_MS : TOAST_DURATION_MS,
|
|
73
|
+
}));
|
|
82
74
|
};
|
package/lib/track.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import mixpanel from "mixpanel-browser";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const track = (eventName, properties) => {
|
|
3
|
+
const projectToken = process.env.NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN;
|
|
4
4
|
if (!projectToken)
|
|
5
5
|
return;
|
|
6
6
|
try {
|
|
7
|
-
setTimeout(
|
|
7
|
+
setTimeout(() => {
|
|
8
8
|
mixpanel.track(eventName, properties);
|
|
9
9
|
}, 250);
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1 +1,85 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@suilend/sui-fe-next",
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "A collection of TypeScript frontend libraries for Next.js",
|
|
6
|
+
"author": "Suilend",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"main": "./index.js",
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./index.js",
|
|
14
|
+
"./contexts/SettingsContext": "./contexts/SettingsContext.jsx",
|
|
15
|
+
"./contexts/WalletContext": "./contexts/WalletContext.jsx",
|
|
16
|
+
"./contexts": "./contexts/index.js",
|
|
17
|
+
"./fetchers": "./fetchers/index.js",
|
|
18
|
+
"./fetchers/useFetchBalances": "./fetchers/useFetchBalances.js",
|
|
19
|
+
"./hooks": "./hooks/index.js",
|
|
20
|
+
"./hooks/keypair": "./hooks/keypair.js",
|
|
21
|
+
"./hooks/useCoinMetadataMap": "./hooks/useCoinMetadataMap.js",
|
|
22
|
+
"./hooks/useIsAndroid": "./hooks/useIsAndroid.jsx",
|
|
23
|
+
"./hooks/useIsTouchscreen": "./hooks/useIsTouchscreen.jsx",
|
|
24
|
+
"./hooks/useIsiOS": "./hooks/useIsiOS.jsx",
|
|
25
|
+
"./hooks/useLedgerHashDialog": "./hooks/useLedgerHashDialog.js",
|
|
26
|
+
"./hooks/useRefreshOnBalancesChange": "./hooks/useRefreshOnBalancesChange.js",
|
|
27
|
+
"./lib/connector": "./lib/connector.js",
|
|
28
|
+
"./lib": "./lib/index.js",
|
|
29
|
+
"./lib/router": "./lib/router.js",
|
|
30
|
+
"./lib/toasts": "./lib/toasts.jsx",
|
|
31
|
+
"./lib/track": "./lib/track.js"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "rm -rf ./dist ./tsconfig.tsbuildinfo && tsc",
|
|
35
|
+
"typecheck": "tsgo --noEmit",
|
|
36
|
+
"lint": "eslint . --fix",
|
|
37
|
+
"lint:ci": "eslint .",
|
|
38
|
+
"format": "prettier --write ./src/**/*.{ts,tsx}",
|
|
39
|
+
"clear": "rm -rf .turbo && rm -rf dist && rm -rf tsconfig.tsbuildinfo && rm -rf node_modules",
|
|
40
|
+
"release": "yarn build && node ../../scripts/prepare-npm-dist.mjs && cd ./dist && npm publish --access public"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/fireflyprotocol/perpetual-ui.git",
|
|
45
|
+
"directory": "packages/sui-fe-next"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@reown/appkit-universal-connector": "1.8.10",
|
|
49
|
+
"@suilend/sui-fe": "^3.0.14",
|
|
50
|
+
"bignumber.js": "9.3.1",
|
|
51
|
+
"launchdarkly-react-client-sdk": "3.9.2",
|
|
52
|
+
"lodash": "4.18.1",
|
|
53
|
+
"mixpanel-browser": "2.81.0",
|
|
54
|
+
"react-responsive": "10.0.1",
|
|
55
|
+
"sonner": "1.4.41",
|
|
56
|
+
"swr": "2.4.2",
|
|
57
|
+
"tailwind-merge": "2.6.1",
|
|
58
|
+
"usehooks-ts": "3.1.1"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@bluefin/eslint-config": "*",
|
|
62
|
+
"@tsconfig/next": "2.0.6",
|
|
63
|
+
"@types/lodash": "4.17.16",
|
|
64
|
+
"@types/mixpanel-browser": "2.60.0",
|
|
65
|
+
"@types/node": "20.17.46",
|
|
66
|
+
"@types/react": "19.2.14",
|
|
67
|
+
"@types/react-dom": "19.2.3",
|
|
68
|
+
"@typescript/native-preview": "7.0.0-dev.20260421.2",
|
|
69
|
+
"eslint": "9.25.1",
|
|
70
|
+
"globals": "15.15.0",
|
|
71
|
+
"next": "15.5.18",
|
|
72
|
+
"prettier": "3.5.3",
|
|
73
|
+
"typescript": "6.0.3",
|
|
74
|
+
"typescript-eslint": "8.31.0"
|
|
75
|
+
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"@mysten/dapp-kit-core": ">=1.3.0",
|
|
78
|
+
"@mysten/dapp-kit-react": ">=2.0.1",
|
|
79
|
+
"@mysten/sui": ">=2.17.0 <3",
|
|
80
|
+
"@mysten/wallet-standard": ">=0.20.0",
|
|
81
|
+
"next": ">=15",
|
|
82
|
+
"react": "19.2.3",
|
|
83
|
+
"react-dom": "19.2.3"
|
|
84
|
+
}
|
|
85
|
+
}
|