-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e149ec
commit ace8647
Showing
13 changed files
with
1,083 additions
and
579 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import axios from 'axios'; | ||
import { TransactionResults } from '@blockstack/stacks-blockchain-sidecar-types'; | ||
|
||
const api = 'https://sidecar.staging.blockstack.xyz/sidecar'; | ||
|
||
// | ||
// TODO: move to sidecar repo, should be documented there | ||
export interface AddressBalanceResponse { | ||
stx: { | ||
balance: string; | ||
total_sent: string; | ||
total_received: string; | ||
}; | ||
fungible_tokens: any; | ||
non_fungible_tokens: any; | ||
} | ||
|
||
async function getAddressBalance(address: string) { | ||
return await axios.get<AddressBalanceResponse>(api + `/v1/address/${address}/balances`); | ||
} | ||
|
||
async function getAddressTransactions(address: string) { | ||
return await axios.get<TransactionResults>(api + `/v1/address/${address}/transactions`); | ||
} | ||
|
||
export const Api = { | ||
getAddressBalance, | ||
getAddressTransactions, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Dispatch } from '../index'; | ||
import { createAction } from '@reduxjs/toolkit'; | ||
import { safeAwait } from '@blockstack/ui'; | ||
|
||
import { Api, AddressBalanceResponse } from '../../api/get-account-details'; | ||
|
||
export const fetchAddress = createAction('address/fetch-address'); | ||
export const fetchAddressDone = createAction<AddressBalanceResponse>('address/fetch-address-done'); | ||
export const fetchAddressFail = createAction('address/fetch-address-fail'); | ||
|
||
export function getAddressDetails(address: string) { | ||
return async (dispatch: Dispatch) => { | ||
dispatch(fetchAddress()); | ||
const [error, response] = await safeAwait(Api.getAddressBalance(address)); | ||
if (error) { | ||
dispatch(fetchAddressFail()); | ||
return; | ||
} | ||
if (response) { | ||
const address = response.data; | ||
dispatch(fetchAddressDone(address)); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { createReducer, createSelector } from '@reduxjs/toolkit'; | ||
|
||
import { RootState } from '..'; | ||
import { fetchAddressDone } from './address.actions'; | ||
|
||
export interface AddressState { | ||
balance: string | null; | ||
} | ||
|
||
const initialState: AddressState = { | ||
balance: null, | ||
}; | ||
|
||
export const addressReducer = createReducer(initialState, builder => | ||
builder.addCase(fetchAddressDone, (_state, { payload }) => ({ | ||
balance: payload.stx.balance, | ||
})) | ||
); | ||
|
||
export const selectAddressState = (state: RootState) => state.address; | ||
|
||
export const selectAddressBalance = createSelector(selectAddressState, state => state.balance); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './address.reducer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.