Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
09bbdb3
cosigner pair view
louisinger Oct 14, 2021
ca4b1fb
add cosigner in settings menu
louisinger Oct 14, 2021
e2ee44d
bump ldk
louisinger Oct 14, 2021
cd5297d
add account domain and MainAccount in Wallet reducer
louisinger Oct 14, 2021
87c03a4
clean unused import
louisinger Oct 14, 2021
66b8888
wip multisig account
louisinger Oct 15, 2021
442e46a
comment account domain
louisinger Oct 18, 2021
6132cd7
move utxos and txs to wallet reducer
louisinger Oct 18, 2021
5356c12
refacto WalletState (former 'IWallet')
louisinger Oct 19, 2021
3c0a544
flush all accounts utxos in networks menu
louisinger Oct 19, 2021
ed0a562
fix imports
louisinger Oct 19, 2021
e63852a
updaters depends on Account domain
louisinger Oct 19, 2021
4b0d1f9
ADD_RESTRICTED_ACCOUNT_DATA action
louisinger Oct 19, 2021
f8392d4
UI cleaning
louisinger Oct 20, 2021
9ff562b
use restored from state for Multisig accounts
louisinger Oct 20, 2021
941747f
pair-sucess page
louisinger Oct 20, 2021
e53da0a
drop isRegtestAsset
louisinger Oct 20, 2021
f6a87df
MultisigWithCosigner Identity
louisinger Oct 20, 2021
639a2f1
updaterWorker logic
louisinger Oct 21, 2021
d750c04
fix deleteUtxo action
louisinger Oct 21, 2021
8dbc7e2
cleaning and prettier
louisinger Oct 21, 2021
ea42cff
only one account
louisinger Oct 21, 2021
9095aef
balances for several accounts
louisinger Oct 22, 2021
b50eecb
selectTransactions and selectUtxos for all accounts
louisinger Oct 22, 2021
77ec2e0
prettier and lint
louisinger Oct 22, 2021
d738c8d
MainAccountID constant in MmenmonicAccount
louisinger Oct 22, 2021
6457633
refacto choose-fee component
louisinger Oct 22, 2021
941386a
blind with blinder
louisinger Oct 22, 2021
8772211
send with multiple accounts
louisinger Oct 25, 2021
d0d57c7
fix blindPSET with several identities
louisinger Oct 25, 2021
cafaed5
multiple providers implementation
louisinger Oct 25, 2021
1586541
allow UI (connect popup)
louisinger Oct 25, 2021
03312f9
allow remove cosigner URL in pairing form
louisinger Oct 25, 2021
5cc6b69
allow coin better params + returns the sighash none pset
louisinger Oct 27, 2021
3e27a43
first version of coinos provider
louisinger Oct 27, 2021
f5b4b42
add key attribute in allow-coin.tsx
louisinger Oct 27, 2021
c296a21
refacto onboarding create wallet form + add checkbox to pair with cos…
louisinger Oct 28, 2021
035ab8e
bump ldk & liquidjs-lib
louisinger Oct 28, 2021
6e2aa61
no need redeemscript anymore
louisinger Oct 28, 2021
2161155
prettier and lint
louisinger Oct 28, 2021
63668b2
avoid dust in spend.test.ts
louisinger Oct 28, 2021
09f103c
implment async tasks using redux-saga (and drop thunks)
louisinger Nov 10, 2021
e05784e
end of sagas
louisinger Nov 11, 2021
4332934
remove utxos/txs update and replace by "updateTask"
louisinger Nov 11, 2021
47edddd
lint and prettier
louisinger Nov 11, 2021
f47ac67
remove createAddress in wallet.ts utils file
louisinger Nov 11, 2021
c17efef
prettier
louisinger Nov 11, 2021
f36261f
asset updater
louisinger Nov 11, 2021
2bcb4c2
prettier
louisinger Nov 11, 2021
0995b6a
utxos updater with saga done
louisinger Nov 11, 2021
ad6987e
updater workers in background: 3
louisinger Nov 11, 2021
7ad890d
remove console.warm logs
louisinger Nov 11, 2021
33eeab9
remove restricted account feature
louisinger Dec 8, 2021
5468096
prettier
louisinger Dec 8, 2021
e9ea27f
linter
louisinger Dec 8, 2021
05f7ca3
merge with master + fix conflicts
louisinger Dec 9, 2021
eb5b204
prettier and lint
louisinger Dec 9, 2021
6cade93
ignore fetch taxi errors
louisinger Dec 9, 2021
166accf
prettier fix
louisinger Dec 9, 2021
d45517c
fix address increment (handle -Inf case)
louisinger Dec 9, 2021
2656069
wallet-restore & wallet-create css changes --> OnboardingForm
louisinger Dec 10, 2021
0e229f6
SaveMnemonicModal in ReceiveSendButtons component
louisinger Dec 10, 2021
403e6c4
revert update tx history effect in TransactionsView
louisinger Dec 10, 2021
3243fd7
document redux/actions/setOnboardingVerified
louisinger Dec 10, 2021
2892695
prettier
louisinger Dec 10, 2021
813261a
add isFullyBlinded check in blindAndSignPset
louisinger Dec 10, 2021
f736493
add migration manifest for wallet reducer
louisinger Dec 10, 2021
f461ab1
refacto increment
louisinger Dec 10, 2021
2890087
"invalid *" strings in constant file
louisinger Dec 10, 2021
00d8449
compute utxos from transactions
louisinger Dec 14, 2021
86b5cda
unit test for migration
louisinger Dec 14, 2021
5112c92
fix rendering error in Login Form
louisinger Dec 14, 2021
2539ca6
bump ldk
louisinger Dec 14, 2021
603b6d8
comment customSagaParser
louisinger Dec 15, 2021
9680c4f
use wallet.sendTx and add "SEND ALL" button in send page
louisinger Dec 15, 2021
1ee0ca6
Merge branch 'master' into account
louisinger Dec 15, 2021
5c04a96
protect transactions.tsx component if location state is null
louisinger Dec 15, 2021
522e5e5
send end of flow: add signedTx to location state in case of error
louisinger Dec 15, 2021
42e95dd
Update src/domain/account.ts
louisinger Dec 20, 2021
b777c29
typeof MainAccountID (account.ts)
louisinger Dec 20, 2021
55db03d
fetch asset info updating (ticker != name)
louisinger Dec 20, 2021
b126ed3
Merge branch 'master' into account
tiero Dec 20, 2021
293995c
handle errors in assetWorker
louisinger Dec 20, 2021
c90e411
Merge branch 'account' of github.com:louisinger/marina into account
louisinger Dec 20, 2021
8a3a6c7
do not relaunch periodic updater if any is running
louisinger Dec 20, 2021
338a04d
cleaning
louisinger Dec 20, 2021
58a77ef
force the lang of input in address-amount-form
louisinger Dec 28, 2021
e32570b
Revert "compute utxos from transactions"
louisinger Jan 5, 2022
577973d
update after revert
louisinger Jan 5, 2022
57a5fa2
Merge branch 'master' into account
louisinger Jan 6, 2022
9bea6d1
smart management of network switching
louisinger Jan 6, 2022
b0ea612
fetch asset info according to network unspent
louisinger Jan 6, 2022
3e49cb3
Merge branch 'master' into account
louisinger Jan 7, 2022
03f900b
remove application/utils/index.ts
louisinger Jan 7, 2022
6d40083
prettier
louisinger Jan 7, 2022
9d8b118
merge with master
louisinger Jan 7, 2022
30b9b8e
Merge branch 'master' into account
louisinger Jan 11, 2022
38e96ef
fix sendAll unfeatured asset
louisinger Jan 11, 2022
5c4738e
start a periodic update of assets in utxos set with updater
louisinger Jan 11, 2022
b55af7f
use browser.alarms for periodic tasks
louisinger Jan 12, 2022
ddff8a5
Merge branch 'master' into account
louisinger Jan 12, 2022
2d4aef8
Merge branch 'master' into account
louisinger Jan 17, 2022
a0e40ef
dispatch UPDATE_TASK for current network after each LOGIN
louisinger Jan 21, 2022
e5bfcd5
update yarn.lock
louisinger Jan 21, 2022
20b3db3
prettier
louisinger Jan 21, 2022
eb075a5
merge master
bordalix Jan 21, 2022
c329f00
replace gRPC by REST on taxi
bordalix Jan 21, 2022
e25e363
taxi assets by network
louisinger Jan 24, 2022
445458a
error handling fix in choose-fee view
louisinger Jan 24, 2022
09484bd
Merge branch 'account_with_taxi_rest' into account
louisinger Jan 24, 2022
33c3c6f
update taxi at login
louisinger Jan 24, 2022
93eda2a
fix taxi assets selector (by network)
louisinger Jan 24, 2022
6cc2110
prettier
louisinger Jan 24, 2022
d667cbc
Promise.resolve
louisinger Jan 24, 2022
4527bcd
Fix bug where periodic updaters were lost after extension update.
bordalix Jan 24, 2022
e3b1bc7
Coerce assetAmount and assetSpread into number.
bordalix Jan 25, 2022
ef78e90
yarn add ldk@0.4.3
bordalix Jan 25, 2022
f8bca88
bug fix: don't trust on browser default font size
bordalix Jan 26, 2022
236c98d
Bug fix: clicking on asset and then on Receive would show a blank page
bordalix Jan 26, 2022
ff87eda
fixes bug where taxi transactions would throw an error since first in…
bordalix Jan 28, 2022
88c5c41
fixes #100: In address-amount the back button should pop from the stack
bordalix Jan 28, 2022
0549d7e
Merge branch 'account_with_taxi_fixed' into account
bordalix Jan 28, 2022
e6a6ff9
comments inputBlindingDataMap function
louisinger Jan 28, 2022
6007a98
prettier
bordalix Jan 28, 2022
1470f4e
adds radix to parseInt
bordalix Jan 28, 2022
94cfdc5
coerce with Number
bordalix Jan 30, 2022
4d1728c
merge master
bordalix Feb 1, 2022
0b110fd
fix merge error
bordalix Feb 1, 2022
34b972f
remove not used constant
bordalix Feb 1, 2022
745b9b7
prettier
bordalix Feb 1, 2022
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"decimal.js": "^10.2.1",
"formik": "^2.2.6",
"google-protobuf": "^3.15.8",
"ldk": "^0.4.0",
"ldk": "0.4.3",
"lodash.debounce": "^4.0.8",
"lottie-web": "^5.7.8",
"marina-provider": "^1.4.5",
Expand All @@ -47,7 +47,7 @@
"readable-stream": "^3.6.0",
"redux": "^4.1.0",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0",
"redux-saga": "^1.1.3",
"stream-browserify": "^3.0.0",
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.1.2",
"taxi-protobuf": "vulpemventures/taxi-protobuf",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"manifest_version": 2,
"description": "Liquid Wallet Web Extension",
"permissions": [
"alarms",
"storage",
"unlimitedStorage",
"idle",
"alarms",
"<all_urls>"
],
"background": {
Expand Down
16 changes: 12 additions & 4 deletions src/application/constants/cypress.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { initialRestorerOpts, MnemonicAccountData } from '../../domain/account';
import { PasswordHash } from '../../domain/password-hash';

export const testPasswordHash: PasswordHash =
'8314b7cd43641c00d3389128fe0d8ff2c286d5bb42313fe88da1d6c88a60f48e';

/**
* test wallet data using to skip the onboarding step for Cypress.
* data:
* | mnemonic = "gas muscle wonder talk sand length swap immense critic opera tree fatigue"
* | pwd = marinatest
*/
export const testWalletData = {
restorerOpts: {},
export const testWalletData: MnemonicAccountData = {
restorerOpts: {
liquid: initialRestorerOpts,
testnet: initialRestorerOpts,
regtest: initialRestorerOpts,
},
encryptedMnemonic:
'f343ad95c7be4b07b213ea489d6135b3fb7d659dfb4c9dc2ee9c9e7202100043b5fba308dd2f5d23cd3061452b644653b7c33d79704261feaefd220e9ef9a39784d593bb887f484dccd85b1eb7d53aba',
masterXPub:
'vpub5SLqN2bLY4WeYFQ5AFRZPCrhemcgnMPFCcM3L4aepayNa38B7xfjtfan5mNJevzBuUWA98y1CWab2L8dpefgywg3D7dvuNtY1X9UjUKgHvC',
masterBlindingKey: 'd4422429e8f06ba093524b31b0ef6d69e2d26e0dd87fade4ab5c875fba2e85d1',
passwordHash: '8314b7cd43641c00d3389128fe0d8ff2c286d5bb42313fe88da1d6c88a60f48e',
confidentialAddresses: [],
};

export const testAppURL = 'https://vulpemventures.github.io/marina-api-test-app/';
20 changes: 11 additions & 9 deletions src/application/redux/actions/action-types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Wallet
export const WALLET_SET_DATA = 'WALLET_SET_DATA';
export const SET_RESTORER_OPTS = 'SET_RESTORER_OPTS';
export const ADD_UTXO = 'ADD_UTXO';
export const DELETE_UTXO = 'DELETE_UTXO';
export const FLUSH_UTXOS = 'FLUSH_UTXOS';
export const UPDATE_UTXOS = 'UPDATE_UTXOS';
export const SET_DEEP_RESTORER_GAP_LIMIT = 'SET_DEEP_RESTORER_GAP_LIMIT';
export const SET_DEEP_RESTORER_IS_LOADING = 'SET_DEEP_RESTORER_IS_LOADING';
export const SET_DEEP_RESTORER_ERROR = 'SET_DEEP_RESTORER_ERROR';
export const NEW_ADDRESS_SUCCESS = 'NEW_ADDRESS_SUCCESS';
export const NEW_CHANGE_ADDRESS_SUCCESS = 'NEW_CHANGE_ADDRESS_SUCCESS';
export const INCREMENT_EXTERNAL_ADDRESS_INDEX = 'INCREMENT_EXTERNAL_ADDRESS_INDEX';
export const INCREMENT_INTERNAL_ADDRESS_INDEX = 'INCREMENT_INTERNAL_ADDRESS_INDEX';
export const SET_VERIFIED = 'SET_VERIFIED';
export const RESET_WALLET = 'RESET_WALLET';
export const SET_UPDATER_LOADER = 'SET_UPDATER_LOADER';
export const POP_UPDATER_LOADER = 'POP_UPDATER_LOADER';
export const PUSH_UPDATER_LOADER = 'PUSH_UPDATER_LOADER';

// App
export const AUTHENTICATION_SUCCESS = 'AUTHENTICATION_SUCCESS';
Expand All @@ -26,13 +27,13 @@ export const RESET_APP = 'RESET_APP';
export const ONBOARDING_SET_MNEMONIC_AND_PASSWORD = 'ONBOARDING_SET_MNEMONIC_AND_PASSWORD';
export const ONBOARDING_FLUSH = 'ONBOARDING_FLUSH';
export const ONBOARDING_SET_IS_FROM_POPUP_FLOW = 'ONBOARDING_SET_IS_FROM_POPUP_FLOW';
export const ONBOARDING_SET_VERIFIED = 'ONBOARDING_SET_VERIFIED';

// Transactions history
export const UPDATE_TXS = 'UPDATE_TXS';
export const ADD_TX = 'ADD_TX';
export const RESET_TXS = 'RESET_TXS';

// Pending transaction
export const PENDING_TX_SET_STEP = 'PENDING_TX_SET_STEP';
export const PENDING_TX_SET_ASSET = 'PENDING_TX_SET_ASSET';
export const PENDING_TX_SET_ADDRESSES_AND_AMOUNT = 'PENDING_TX_SET_ADDRESSES_AND_AMOUNT';
export const PENDING_TX_SET_FEE_CHANGE_ADDRESS = 'PENDING_TX_SET_FEE_CHANGE_ADDRESS';
Expand All @@ -52,18 +53,19 @@ export const SET_MSG = 'SET_MSG';
export const FLUSH_MSG = 'FLUSH_MSG';
export const SELECT_HOSTNAME = 'SELECT_HOSTNAME';
export const FLUSH_SELECTED_HOSTNAME = 'FLUSH_SELECTED_HOSTNAME';
export const SET_APPROVE_REQUEST_PARAM = 'SET_APPROVE_REQUEST_PARAM';
export const RESET_CONNECT = 'RESET_CONNECT';

// Taxi
export const SET_TAXI_ASSETS = 'SET_TAXI_ASSETS';
export const UPDATE_TAXI_ASSETS = 'UPDATE_TAXI_ASSETS';
export const RESET_TAXI = 'RESET_TAXI';

// Alarms
export const START_PERIODIC_UPDATE = 'START_PERIODIC_UPDATE';

// Restoration
export const START_DEEP_RESTORATION = 'START_DEEP_RESTORATION';

// Reset
export const RESET = 'RESET';

// Updater taskes
export const UPDATE_TASK = 'UPDATE_TASK';
11 changes: 5 additions & 6 deletions src/application/redux/actions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ONBOARDING_COMPLETETED,
LOGOUT_SUCCESS,
CHANGE_NETWORK_SUCCESS,
START_PERIODIC_UPDATE,
SET_EXPLORER,
RESET,
} from './action-types';
Expand All @@ -13,6 +12,7 @@ import { Password } from '../../../domain/password';
import { match, PasswordHash } from '../../../domain/password-hash';
import { ExplorerURLs } from '../../../domain/app';
import { NetworkString } from 'ldk';
import { INVALID_PASSWORD_ERROR } from '../../utils/constants';

export const setExplorer = (explorer: ExplorerURLs, network: NetworkString): AnyAction => ({
type: SET_EXPLORER,
Expand All @@ -26,7 +26,10 @@ export const onboardingCompleted = (): AnyAction => ({
export function logIn(password: Password, passwordHash: PasswordHash): AnyAction {
try {
if (!match(password, passwordHash)) {
return { type: AUTHENTICATION_FAILURE, payload: { error: new Error('Invalid password') } };
return {
type: AUTHENTICATION_FAILURE,
payload: { error: new Error(INVALID_PASSWORD_ERROR) },
};
}

return { type: AUTHENTICATION_SUCCESS };
Expand All @@ -43,10 +46,6 @@ export function changeNetwork(network: NetworkString): AnyAction {
return { type: CHANGE_NETWORK_SUCCESS, payload: { network } };
}

export function startPeriodicUpdate(): AnyAction {
return { type: START_PERIODIC_UPDATE };
}

export function reset(): AnyAction {
return { type: RESET };
}
20 changes: 18 additions & 2 deletions src/application/redux/actions/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import {
ONBOARDING_FLUSH,
ONBOARDING_SET_MNEMONIC_AND_PASSWORD,
ONBOARDING_SET_IS_FROM_POPUP_FLOW,
ONBOARDING_SET_VERIFIED,
} from './action-types';
import { AnyAction } from 'redux';

export function setPasswordAndOnboardingMnemonic(password: string, mnemonic: string): AnyAction {
export function setPasswordAndOnboardingMnemonic(
password: string,
mnemonic: string,
needSecurityAccount: boolean
): AnyAction {
return {
type: ONBOARDING_SET_MNEMONIC_AND_PASSWORD,
payload: { mnemonic, password },
payload: { mnemonic, password, needSecurityAccount },
};
}

Expand All @@ -22,3 +27,14 @@ export function setBackup(mnemonic: string): AnyAction {
payload: { mnemonic },
};
}

// Onboarding Verified is a temporary state for verification of the secret mnemonic
// It aims to flag the new wallet as verified if
// (1) the user has already backed up the mnemonic via onboarding/wallet-confirm
// (2) the user is restoring a wallet via onboarding/wallet-restore
// then `wallet.isVerified` is set to `onboarding.verified` during onboarding /end-of-flow confirm step
export function setOnboardingVerified(): AnyAction {
return {
type: ONBOARDING_SET_VERIFIED,
};
}
5 changes: 3 additions & 2 deletions src/application/redux/actions/taxi.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { NetworkString } from 'ldk';
import { AnyAction } from 'redux';
import { SET_TAXI_ASSETS, UPDATE_TAXI_ASSETS } from './action-types';

export function setTaxiAssets(newAssets: string[]): AnyAction {
export function setTaxiAssets(network: NetworkString, newAssets: string[]): AnyAction {
return {
type: SET_TAXI_ASSETS,
payload: newAssets,
payload: { network, assets: newAssets },
};
}

Expand Down
43 changes: 27 additions & 16 deletions src/application/redux/actions/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,40 @@ import {
PENDING_TX_SET_ADDRESSES_AND_AMOUNT,
PENDING_TX_SET_FEE_CHANGE_ADDRESS,
PENDING_TX_SET_FEE_AMOUNT_AND_ASSET,
UPDATE_TXS,
PENDING_TX_SET_PSET,
PENDING_TX_SET_STEP,
ADD_TX,
} from './action-types';
import { AnyAction } from 'redux';
import { Address } from '../../../domain/address';
import { TxDisplayInterface } from '../../../domain/transaction';
import { NetworkString } from 'ldk';
import { NetworkString, UnblindedOutput, TxInterface } from 'ldk';
import { AccountID } from '../../../domain/account';
import { ActionWithPayload } from '../../../domain/common';
import { PendingTxStep } from '../reducers/transaction-reducer';

export type AddTxAction = ActionWithPayload<{
tx: TxInterface;
network: NetworkString;
accountID: AccountID;
}>;

export function setAsset(asset: string): AnyAction {
return { type: PENDING_TX_SET_ASSET, payload: { asset } };
}

export function setPendingTxStep(step: PendingTxStep): AnyAction {
return { type: PENDING_TX_SET_STEP, payload: { step } };
}

export function setAddressesAndAmount(
receipientAddress: Address,
changeAddress: Address,
amountInSatoshi: number
amountInSatoshi: number,
changeAddresses?: Address[],
recipientAddress?: Address
): AnyAction {
return {
type: PENDING_TX_SET_ADDRESSES_AND_AMOUNT,
payload: { receipientAddress, changeAddress, amountInSatoshi },
payload: { recipientAddress, changeAddresses, amountInSatoshi },
};
}

Expand All @@ -40,22 +53,20 @@ export function flushPendingTx(): AnyAction {
return { type: PENDING_TX_FLUSH };
}

export function updateTxs(): AnyAction {
return {
type: UPDATE_TXS,
};
}

export function setPset(pset: string): AnyAction {
export function setPset(pset: string, utxos: UnblindedOutput[]): AnyAction {
return {
type: PENDING_TX_SET_PSET,
payload: { pset },
payload: { pset, utxos },
};
}

export function addTx(tx: TxDisplayInterface, network: NetworkString): AnyAction {
export function addTx(
accountID: AccountID,
tx: TxDisplayInterface,
network: NetworkString
): AnyAction {
return {
type: ADD_TX,
payload: { tx, network },
payload: { tx, network, accountID },
};
}
14 changes: 14 additions & 0 deletions src/application/redux/actions/updater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NetworkString } from 'ldk';
import { AccountID } from '../../../domain/account';
import { ActionWithPayload } from '../../../domain/common';
import { UPDATE_TASK } from './action-types';

export type UpdateTaskAction = ActionWithPayload<{ accountID: AccountID; network: NetworkString }>;

export const updateTaskAction = (
accountID: AccountID,
network: NetworkString
): UpdateTaskAction => ({
type: UPDATE_TASK,
payload: { accountID, network },
});
35 changes: 24 additions & 11 deletions src/application/redux/actions/utxos.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import { UnblindedOutput } from 'ldk';
import { NetworkString, UnblindedOutput } from 'ldk';
import { AnyAction } from 'redux';
import { ADD_UTXO, DELETE_UTXO, FLUSH_UTXOS, UPDATE_UTXOS } from './action-types';
import { AccountID } from '../../../domain/account';
import { ActionWithPayload } from '../../../domain/common';
import { ADD_UTXO, DELETE_UTXO, FLUSH_UTXOS } from './action-types';

export function updateUtxos(): AnyAction {
return { type: UPDATE_UTXOS };
}
export type AddUtxoAction = ActionWithPayload<{
accountID: AccountID;
utxo: UnblindedOutput;
network: NetworkString;
}>;

export function addUtxo(utxo: UnblindedOutput): AnyAction {
return { type: ADD_UTXO, payload: { utxo } };
export function addUtxo(
accountID: AccountID,
utxo: UnblindedOutput,
network: NetworkString
): AddUtxoAction {
return { type: ADD_UTXO, payload: { accountID, utxo, network } };
}

export function deleteUtxo(txid: string, vout: number): AnyAction {
return { type: DELETE_UTXO, payload: { txid, vout } };
export function deleteUtxo(
accountID: AccountID,
txid: string,
vout: number,
network: NetworkString
): AnyAction {
return { type: DELETE_UTXO, payload: { txid, vout, accountID, network } };
}

export function flushUtxos(): AnyAction {
return { type: FLUSH_UTXOS };
export function flushUtxos(accountID: AccountID, network: NetworkString): AnyAction {
return { type: FLUSH_UTXOS, payload: { accountID, network } };
}
Loading