@unisat/wallet-state 1.0.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.
@@ -0,0 +1,255 @@
1
+ import { Inscription } from '@/shared/types'
2
+ import { createSlice } from '@reduxjs/toolkit'
3
+ import { UnspentOutput } from '@unisat/tx-helpers/types'
4
+
5
+ import { updateVersion } from '../global/actions'
6
+
7
+ export interface BitcoinTx {
8
+ fromAddress: string
9
+ toAddress: string
10
+ toSatoshis: number
11
+ rawtx: string
12
+ txid: string
13
+ fee: number
14
+ estimateFee: number
15
+ changeSatoshis: number
16
+ sending: boolean
17
+ autoAdjust: boolean
18
+ psbtHex: string
19
+ feeRate: number
20
+ toDomain: string
21
+ enableRBF: boolean
22
+ }
23
+
24
+ export interface OrdinalsTx {
25
+ fromAddress: string
26
+ toAddress: string
27
+ inscription: Inscription
28
+ rawtx: string
29
+ txid: string
30
+ fee: number
31
+ estimateFee: number
32
+ changeSatoshis: number
33
+ sending: boolean
34
+ psbtHex: string
35
+ feeRate: number
36
+ toDomain: string
37
+ outputValue: number
38
+ enableRBF: boolean
39
+ }
40
+
41
+ export interface RunesTx {
42
+ fromAddress: string
43
+ toAddress: string
44
+ rawtx: string
45
+ txid: string
46
+ fee: number
47
+ estimateFee: number
48
+ changeSatoshis: number
49
+ sending: boolean
50
+ psbtHex: string
51
+ feeRate: number
52
+ toDomain: string
53
+ outputValue: number
54
+ enableRBF: boolean
55
+ runeid?: string
56
+ runeAmount?: string
57
+ }
58
+
59
+ export interface TransactionsState {
60
+ bitcoinTx: BitcoinTx
61
+ ordinalsTx: OrdinalsTx
62
+ runesTx: RunesTx
63
+ utxos: UnspentOutput[]
64
+ spendUnavailableUtxos: UnspentOutput[]
65
+ assetUtxos_inscriptions: UnspentOutput[]
66
+ assetUtxos_runes: UnspentOutput[]
67
+ }
68
+
69
+ export const initialState: TransactionsState = {
70
+ bitcoinTx: {
71
+ fromAddress: '',
72
+ toAddress: '',
73
+ toSatoshis: 0,
74
+ rawtx: '',
75
+ txid: '',
76
+ fee: 0,
77
+ estimateFee: 0,
78
+ changeSatoshis: 0,
79
+ sending: false,
80
+ autoAdjust: false,
81
+ psbtHex: '',
82
+ feeRate: 5,
83
+ toDomain: '',
84
+ enableRBF: false,
85
+ },
86
+ ordinalsTx: {
87
+ fromAddress: '',
88
+ toAddress: '',
89
+ inscription: {
90
+ inscriptionId: '',
91
+ inscriptionNumber: 0,
92
+ address: '',
93
+ outputValue: 0,
94
+ preview: '',
95
+ content: '',
96
+ contentType: '',
97
+ contentLength: 0,
98
+ timestamp: 0,
99
+ genesisTransaction: '',
100
+ location: '',
101
+ output: '',
102
+ offset: 0,
103
+ contentBody: '',
104
+ utxoHeight: 0,
105
+ utxoConfirmation: 0,
106
+ },
107
+ rawtx: '',
108
+ txid: '',
109
+ fee: 0,
110
+ estimateFee: 0,
111
+ changeSatoshis: 0,
112
+ sending: false,
113
+ psbtHex: '',
114
+ feeRate: 5,
115
+ toDomain: '',
116
+ outputValue: 10000,
117
+ enableRBF: false,
118
+ },
119
+
120
+ runesTx: {
121
+ fromAddress: '',
122
+ toAddress: '',
123
+ rawtx: '',
124
+ txid: '',
125
+ fee: 0,
126
+ estimateFee: 0,
127
+ changeSatoshis: 0,
128
+ sending: false,
129
+ psbtHex: '',
130
+ feeRate: 5,
131
+ toDomain: '',
132
+ outputValue: 10000,
133
+ enableRBF: false,
134
+ },
135
+ utxos: [],
136
+ spendUnavailableUtxos: [],
137
+ assetUtxos_inscriptions: [],
138
+ assetUtxos_runes: [],
139
+ }
140
+
141
+ const slice = createSlice({
142
+ name: 'transactions',
143
+ initialState,
144
+ reducers: {
145
+ updateBitcoinTx(
146
+ state,
147
+ action: {
148
+ payload: {
149
+ fromAddress?: string
150
+ toAddress?: string
151
+ toSatoshis?: number
152
+ changeSatoshis?: number
153
+ rawtx?: string
154
+ txid?: string
155
+ fee?: number
156
+ estimateFee?: number
157
+ sending?: boolean
158
+ autoAdjust?: boolean
159
+ psbtHex?: string
160
+ feeRate?: number
161
+ toDomain?: string
162
+ enableRBF?: boolean
163
+ }
164
+ }
165
+ ) {
166
+ const { payload } = action
167
+ state.bitcoinTx = Object.assign({}, state.bitcoinTx, payload)
168
+ },
169
+ updateOrdinalsTx(
170
+ state,
171
+ action: {
172
+ payload: {
173
+ fromAddress?: string
174
+ toAddress?: string
175
+ inscription?: Inscription
176
+ changeSatoshis?: number
177
+ rawtx?: string
178
+ txid?: string
179
+ fee?: number
180
+ estimateFee?: number
181
+ sending?: boolean
182
+ psbtHex?: string
183
+ feeRate?: number
184
+ toDomain?: string
185
+ outputValue?: number
186
+ enableRBF?: boolean
187
+ }
188
+ }
189
+ ) {
190
+ const { payload } = action
191
+ state.ordinalsTx = Object.assign({}, state.ordinalsTx, payload)
192
+ },
193
+
194
+ updateRunesTx(
195
+ state,
196
+ action: {
197
+ payload: {
198
+ fromAddress?: string
199
+ toAddress?: string
200
+ changeSatoshis?: number
201
+ rawtx?: string
202
+ txid?: string
203
+ fee?: number
204
+ estimateFee?: number
205
+ sending?: boolean
206
+ psbtHex?: string
207
+ feeRate?: number
208
+ toDomain?: string
209
+ outputValue?: number
210
+ enableRBF?: boolean
211
+ runeid?: string
212
+ runeAmount?: string
213
+ }
214
+ }
215
+ ) {
216
+ const { payload } = action
217
+ state.runesTx = Object.assign({}, state.runesTx, payload)
218
+ },
219
+ setUtxos(state, action: { payload: UnspentOutput[] }) {
220
+ state.utxos = action.payload
221
+ },
222
+ setSpendUnavailableUtxos(state, action: { payload: UnspentOutput[] }) {
223
+ state.spendUnavailableUtxos = action.payload
224
+ },
225
+
226
+ setAssetUtxosInscriptions(state, action: { payload: UnspentOutput[] }) {
227
+ state.assetUtxos_inscriptions = action.payload
228
+ },
229
+ setAssetUtxosRunes(state, action: { payload: UnspentOutput[] }) {
230
+ state.assetUtxos_runes = action.payload
231
+ },
232
+ reset(state) {
233
+ return initialState
234
+ },
235
+ },
236
+
237
+ extraReducers: builder => {
238
+ builder.addCase(updateVersion, state => {
239
+ if (!state.assetUtxos_inscriptions) {
240
+ state.assetUtxos_inscriptions = []
241
+ }
242
+
243
+ if (!state.spendUnavailableUtxos) {
244
+ state.spendUnavailableUtxos = []
245
+ }
246
+
247
+ if (!state.assetUtxos_runes) {
248
+ state.assetUtxos_runes = []
249
+ }
250
+ })
251
+ },
252
+ })
253
+
254
+ export const transactionsActions = slice.actions
255
+ export default slice.reducer
@@ -0,0 +1,203 @@
1
+ import { Inscription } from '@/shared/types'
2
+ import { createSlice } from '@reduxjs/toolkit'
3
+
4
+ import { updateVersion } from '../global/actions'
5
+
6
+ export interface UIState {
7
+ assetTabKey: AssetTabKey
8
+ ordinalsAssetTabKey: OrdinalsAssetTabKey
9
+ catAssetTabKey: CATAssetTabKey
10
+ alkanesAssetTabKey: AlkanesAssetTabKey
11
+ uiTxCreateScreen: {
12
+ toInfo: {
13
+ address: string
14
+ domain: string
15
+ inscription?: Inscription
16
+ }
17
+ inputAmount: string
18
+ enableRBF: boolean
19
+ feeRate: number
20
+ }
21
+ babylonSendScreen: {
22
+ inputAmount: string
23
+ memo: string
24
+ }
25
+ navigationSource: NavigationSource
26
+ isBalanceHidden: boolean
27
+ }
28
+
29
+ export enum AssetTabKey {
30
+ ORDINALS = 0,
31
+ ATOMICALS = 1, // IGNORED
32
+ RUNES = 2,
33
+ CAT = 3,
34
+ ALKANES = 4,
35
+ }
36
+
37
+ export enum OrdinalsAssetTabKey {
38
+ ALL = 0,
39
+ BRC20 = 1,
40
+ BRC20_6BYTE = 2,
41
+ }
42
+
43
+ export enum CATAssetTabKey {
44
+ CAT20,
45
+ CAT721,
46
+ CAT20_V2,
47
+ CAT721_V2,
48
+ }
49
+
50
+ export enum AlkanesAssetTabKey {
51
+ TOKEN,
52
+ COLLECTION,
53
+ }
54
+
55
+ export enum NavigationSource {
56
+ BACK,
57
+ NORMAL,
58
+ }
59
+
60
+ export const initialState: UIState = {
61
+ assetTabKey: AssetTabKey.ORDINALS,
62
+ ordinalsAssetTabKey: OrdinalsAssetTabKey.ALL,
63
+ catAssetTabKey: CATAssetTabKey.CAT20,
64
+ alkanesAssetTabKey: AlkanesAssetTabKey.TOKEN,
65
+ uiTxCreateScreen: {
66
+ toInfo: {
67
+ address: '',
68
+ domain: '',
69
+ inscription: undefined,
70
+ },
71
+ inputAmount: '',
72
+ enableRBF: false,
73
+ feeRate: 1,
74
+ },
75
+ babylonSendScreen: {
76
+ inputAmount: '',
77
+ memo: '',
78
+ },
79
+ navigationSource: NavigationSource.NORMAL,
80
+ isBalanceHidden: false,
81
+ }
82
+
83
+ const slice = createSlice({
84
+ name: 'ui',
85
+ initialState,
86
+ reducers: {
87
+ reset(state) {
88
+ return initialState
89
+ },
90
+ updateAssetTabScreen(
91
+ state,
92
+ action: {
93
+ payload: {
94
+ assetTabKey?: AssetTabKey
95
+ ordinalsAssetTabKey?: OrdinalsAssetTabKey
96
+ catAssetTabKey?: CATAssetTabKey
97
+ alkanesAssetTabKey?: AlkanesAssetTabKey
98
+ }
99
+ }
100
+ ) {
101
+ const { payload } = action
102
+ if (payload.assetTabKey !== undefined) {
103
+ state.assetTabKey = payload.assetTabKey
104
+ }
105
+ if (payload.ordinalsAssetTabKey !== undefined) {
106
+ state.ordinalsAssetTabKey = payload.ordinalsAssetTabKey
107
+ }
108
+
109
+ if (payload.catAssetTabKey !== undefined) {
110
+ state.catAssetTabKey = payload.catAssetTabKey
111
+ }
112
+ if (payload.alkanesAssetTabKey !== undefined) {
113
+ state.alkanesAssetTabKey = payload.alkanesAssetTabKey
114
+ }
115
+ return state
116
+ },
117
+ updateTxCreateScreen(
118
+ state,
119
+ action: {
120
+ payload: {
121
+ toInfo?: {
122
+ address: string
123
+ domain: string
124
+ inscription?: Inscription
125
+ }
126
+ inputAmount?: string
127
+ enableRBF?: boolean
128
+ feeRate?: number
129
+ }
130
+ }
131
+ ) {
132
+ if (action.payload.toInfo !== undefined) {
133
+ state.uiTxCreateScreen.toInfo = action.payload.toInfo
134
+ }
135
+ if (action.payload.inputAmount !== undefined) {
136
+ state.uiTxCreateScreen.inputAmount = action.payload.inputAmount
137
+ }
138
+ if (action.payload.enableRBF !== undefined) {
139
+ state.uiTxCreateScreen.enableRBF = action.payload.enableRBF
140
+ }
141
+ if (action.payload.feeRate !== undefined) {
142
+ state.uiTxCreateScreen.feeRate = action.payload.feeRate
143
+ }
144
+ },
145
+ resetTxCreateScreen(state) {
146
+ state.uiTxCreateScreen = initialState.uiTxCreateScreen
147
+ },
148
+ updateBabylonSendScreen(
149
+ state,
150
+ action: {
151
+ payload: {
152
+ inputAmount?: string
153
+ memo?: string
154
+ }
155
+ }
156
+ ) {
157
+ if (action.payload.inputAmount !== undefined) {
158
+ state.babylonSendScreen.inputAmount = action.payload.inputAmount
159
+ }
160
+ if (action.payload.memo !== undefined) {
161
+ state.babylonSendScreen.memo = action.payload.memo
162
+ }
163
+ },
164
+ resetBabylonSendScreen(state) {
165
+ state.babylonSendScreen = initialState.babylonSendScreen
166
+ },
167
+ setNavigationSource(state, action: { payload: NavigationSource }) {
168
+ state.navigationSource = action.payload
169
+ },
170
+ setBalanceHidden(state, action: { payload: boolean }) {
171
+ state.isBalanceHidden = action.payload
172
+ },
173
+ },
174
+ extraReducers: builder => {
175
+ builder.addCase(updateVersion, state => {
176
+ // todo
177
+ if (!state.assetTabKey) {
178
+ state.assetTabKey = AssetTabKey.ORDINALS
179
+ }
180
+ if (!state.ordinalsAssetTabKey) {
181
+ state.ordinalsAssetTabKey = OrdinalsAssetTabKey.ALL
182
+ }
183
+ if (!state.catAssetTabKey) {
184
+ state.catAssetTabKey = CATAssetTabKey.CAT20
185
+ }
186
+ if (!state.alkanesAssetTabKey) {
187
+ state.alkanesAssetTabKey = AlkanesAssetTabKey.TOKEN
188
+ }
189
+ if (!state.uiTxCreateScreen) {
190
+ state.uiTxCreateScreen = initialState.uiTxCreateScreen
191
+ }
192
+ if (!state.babylonSendScreen) {
193
+ state.babylonSendScreen = initialState.babylonSendScreen
194
+ }
195
+ if (state.isBalanceHidden === undefined) {
196
+ state.isBalanceHidden = false
197
+ }
198
+ })
199
+ },
200
+ })
201
+
202
+ export const uiActions = slice.actions
203
+ export default slice.reducer
@@ -0,0 +1,43 @@
1
+ import { configureStore } from '@reduxjs/toolkit';
2
+ import type { AppState } from '../types';
3
+
4
+ // Import reducers (to be implemented)
5
+ // import { accountsReducer } from '../slices/accounts';
6
+ // import { transactionsReducer } from '../slices/transactions';
7
+ // import { settingsReducer } from '../slices/settings';
8
+ // import { globalReducer } from '../slices/global';
9
+ // import { keyringsReducer } from '../slices/keyrings';
10
+ // import { uiReducer } from '../slices/ui';
11
+
12
+ /**
13
+ * Create store with platform-specific middleware and persistence
14
+ */
15
+ export function createWalletStore(options?: {
16
+ persistedKeys?: string[];
17
+ middleware?: any[];
18
+ }) {
19
+ return configureStore({
20
+ reducer: {
21
+ // accounts: accountsReducer,
22
+ // transactions: transactionsReducer,
23
+ // settings: settingsReducer,
24
+ // global: globalReducer,
25
+ // keyrings: keyringsReducer,
26
+ // ui: uiReducer,
27
+ },
28
+ middleware: (getDefaultMiddleware) => {
29
+ let middleware = getDefaultMiddleware({ thunk: true });
30
+
31
+ if (options?.middleware) {
32
+ middleware = middleware.concat(options.middleware);
33
+ }
34
+
35
+ return middleware;
36
+ },
37
+ // Platform-specific preloaded state will be handled by the consuming app
38
+ });
39
+ }
40
+
41
+ export type WalletStore = ReturnType<typeof createWalletStore>;
42
+ export type WalletDispatch = WalletStore['dispatch'];
43
+ export type { AppState };
@@ -0,0 +1,37 @@
1
+ // Redux state types
2
+ export interface AppState {
3
+ accounts: AccountsState;
4
+ transactions: TransactionsState;
5
+ settings: SettingsState;
6
+ global: GlobalState;
7
+ keyrings: KeyringsState;
8
+ ui: UIState;
9
+ }
10
+
11
+ // Individual state slice types (to be populated from existing code)
12
+ export interface AccountsState {
13
+ // To be populated with actual account state structure
14
+ }
15
+
16
+ export interface TransactionsState {
17
+ // To be populated with actual transaction state structure
18
+ }
19
+
20
+ export interface SettingsState {
21
+ // To be populated with actual settings state structure
22
+ }
23
+
24
+ export interface GlobalState {
25
+ // To be populated with actual global state structure
26
+ }
27
+
28
+ export interface KeyringsState {
29
+ // To be populated with actual keyrings state structure
30
+ }
31
+
32
+ export interface UIState {
33
+ // To be populated with actual UI state structure
34
+ }
35
+
36
+ // Re-export common types
37
+ export * from '@unisat/wallet-types';