Skip to content

Commit

Permalink
Merge branch 'main' into feat/130-localize-numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
dkackman committed Jan 20, 2025
2 parents 047f344 + 8a345ef commit 16d8ec2
Show file tree
Hide file tree
Showing 28 changed files with 1,578 additions and 625 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions crates/sage-api/src/requests/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ pub struct GetDidsResponse {
pub dids: Vec<DidRecord>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type)]
pub struct GetMinterDidIds {}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct GetMinterDidIdsResponse {
pub did_ids: Vec<String>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type)]
pub struct GetPendingTransactions {}

Expand Down
1 change: 1 addition & 0 deletions crates/sage-cli/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ routes!(
get_cats await: GetCats = "/get_cats",
get_cat await: GetCat = "/get_cat",
get_dids await: GetDids = "/get_dids",
get_minter_did_ids await: GetMinterDidIds = "/get_minter_did_ids",
get_pending_transactions await: GetPendingTransactions = "/get_pending_transactions",
get_transactions await: GetTransactions = "/get_transactions",
get_transaction await: GetTransaction = "/get_transaction",
Expand Down
19 changes: 18 additions & 1 deletion crates/sage-database/src/primitives/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ impl Database {
fetch_nft_data(&self.pool, hash).await
}

pub async fn distinct_minter_dids(&self) -> Result<Vec<Option<Bytes32>>> {
distinct_minter_dids(&self.pool).await
}

pub async fn search_nfts(
&self,
params: NftSearchParams,
Expand Down Expand Up @@ -438,6 +442,16 @@ async fn insert_nft_data(
Ok(())
}

async fn distinct_minter_dids(conn: impl SqliteExecutor<'_>) -> Result<Vec<Option<Bytes32>>> {
let rows = sqlx::query!("SELECT DISTINCT minter_did FROM nfts WHERE minter_did IS NOT NULL")
.fetch_all(conn)
.await?;

rows.into_iter()
.map(|row| row.minter_did.map(|bytes| to_bytes32(&bytes)).transpose())
.collect()
}

async fn fetch_nft_data(conn: impl SqliteExecutor<'_>, hash: Bytes32) -> Result<Option<NftData>> {
let hash = hash.as_ref();

Expand Down Expand Up @@ -754,7 +768,10 @@ async fn search_nfts(
}

// Bind group parameters if present
if let Some(NftGroup::Collection(id) | NftGroup::MinterDid(id)) = &params.group {
//if let Some(NftGroup::Collection(id) | NftGroup::MinterDid(id)) = &params.group {
if let Some(NftGroup::Collection(id) | NftGroup::MinterDid(id) | NftGroup::OwnerDid(id)) =
&params.group
{
query = query.bind(id.as_ref());
}

Expand Down
33 changes: 26 additions & 7 deletions crates/sage/src/endpoints/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ use hex_literal::hex;
use sage_api::{
AddressKind, Amount, AssetKind, CatRecord, CoinRecord, DerivationRecord, DidRecord, GetCat,
GetCatCoins, GetCatCoinsResponse, GetCatResponse, GetCats, GetCatsResponse, GetDerivations,
GetDerivationsResponse, GetDids, GetDidsResponse, GetNft, GetNftCollection,
GetNftCollectionResponse, GetNftCollections, GetNftCollectionsResponse, GetNftData,
GetNftDataResponse, GetNftResponse, GetNfts, GetNftsResponse, GetPendingTransactions,
GetPendingTransactionsResponse, GetSyncStatus, GetSyncStatusResponse, GetTransaction,
GetTransactionResponse, GetTransactions, GetTransactionsResponse, GetXchCoins,
GetXchCoinsResponse, NftCollectionRecord, NftData, NftRecord, NftSortMode as ApiNftSortMode,
PendingTransactionRecord, TransactionCoin, TransactionRecord,
GetDerivationsResponse, GetDids, GetDidsResponse, GetMinterDidIds, GetMinterDidIdsResponse,
GetNft, GetNftCollection, GetNftCollectionResponse, GetNftCollections,
GetNftCollectionsResponse, GetNftData, GetNftDataResponse, GetNftResponse, GetNfts,
GetNftsResponse, GetPendingTransactions, GetPendingTransactionsResponse, GetSyncStatus,
GetSyncStatusResponse, GetTransaction, GetTransactionResponse, GetTransactions,
GetTransactionsResponse, GetXchCoins, GetXchCoinsResponse, NftCollectionRecord, NftData,
NftRecord, NftSortMode as ApiNftSortMode, PendingTransactionRecord, TransactionCoin,
TransactionRecord,
};
use sage_database::{
CoinKind, CoinStateRow, Database, NftGroup, NftRow, NftSearchParams, NftSortMode,
Expand Down Expand Up @@ -244,6 +245,24 @@ impl Sage {
Ok(GetDidsResponse { dids })
}

pub async fn get_minter_did_ids(
&self,
_req: GetMinterDidIds,
) -> Result<GetMinterDidIdsResponse> {
let wallet = self.wallet()?;

let did_ids = wallet
.db
.distinct_minter_dids()
.await?
.into_iter()
.filter_map(|did| did.map(|d| encode_address(d.to_bytes(), "did:chia:").ok()))
.flatten()
.collect();

Ok(GetMinterDidIdsResponse { did_ids })
}

pub async fn get_pending_transactions(
&self,
_req: GetPendingTransactions,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"react-hook-form": "^7.53.0",
"react-imask": "^7.6.1",
"react-router-dom": "^6.26.0",
"react-toastify": "^11.0.3",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
"tauri-plugin-safe-area-insets": "^0.1.0",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,15 @@ pub async fn get_dids(state: State<'_, AppState>, req: GetDids) -> Result<GetDid
Ok(state.lock().await.get_dids(req).await?)
}

#[command]
#[specta]
pub async fn get_minter_did_ids(
state: State<'_, AppState>,
req: GetMinterDidIds,
) -> Result<GetMinterDidIdsResponse> {
Ok(state.lock().await.get_minter_did_ids(req).await?)
}

#[command]
#[specta]
pub async fn get_pending_transactions(
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn run() {
commands::get_cats,
commands::get_cat,
commands::get_dids,
commands::get_minter_did_ids,
commands::get_nft_collections,
commands::get_nft_collection,
commands::get_nfts,
Expand Down
29 changes: 25 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import useInitialization from './hooks/useInitialization';
import { useWallet } from './hooks/useWallet';
import { loadCatalog } from './i18n';
import Addresses from './pages/Addresses';
import Collection from './pages/Collection';
import CreateProfile from './pages/CreateProfile';
import CreateWallet from './pages/CreateWallet';
import { DidList } from './pages/DidList';
Expand All @@ -47,6 +46,9 @@ import { ViewSavedOffer } from './pages/ViewSavedOffer';
import Wallet from './pages/Wallet';
import { fetchState } from './state';
import QRScanner from './pages/QrScanner';
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { Slide } from 'react-toastify';

export interface DarkModeContext {
toggle: () => void;
Expand Down Expand Up @@ -76,11 +78,11 @@ const router = createHashRouter(
<Route path='/nfts' element={<Wallet />}>
<Route path='' element={<NftList />} />
<Route path=':launcher_id' element={<Nft />} />
<Route path='collections/:collection_id' element={<NftList />} />
<Route path='owners/:owner_did' element={<NftList />} />
<Route path='minters/:minter_did' element={<NftList />} />
<Route path='mint' element={<MintNft />} />
</Route>
<Route path='/collections' element={<Wallet />}>
<Route path=':collection_id' element={<Collection />} />
</Route>
<Route path='/dids' element={<Wallet />}>
<Route path='' element={<DidList />} />
<Route path='create' element={<CreateProfile />} />
Expand Down Expand Up @@ -133,6 +135,25 @@ export default function App() {
</ErrorProvider>
</SafeAreaProvider>
</DarkModeContext.Provider>
<ToastContainer
position='bottom-right'
autoClose={5000}
hideProgressBar={false}
newestOnTop={false}
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover
theme={dark ? 'dark' : 'light'}
transition={Slide}
style={
{
'--toastify-toast-transition-timing': 'ease',
'--toastify-toast-transition-duration': '750ms',
} as React.CSSProperties
}
/>
</LanguageProvider>
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ async getCat(req: GetCat) : Promise<GetCatResponse> {
async getDids(req: GetDids) : Promise<GetDidsResponse> {
return await TAURI_INVOKE("get_dids", { req });
},
async getMinterDidIds(req: GetMinterDidIds) : Promise<GetMinterDidIdsResponse> {
return await TAURI_INVOKE("get_minter_did_ids", { req });
},
async getNftCollections(req: GetNftCollections) : Promise<GetNftCollectionsResponse> {
return await TAURI_INVOKE("get_nft_collections", { req });
},
Expand Down Expand Up @@ -293,6 +296,8 @@ export type GetKey = { fingerprint?: number | null }
export type GetKeyResponse = { key: KeyInfo | null }
export type GetKeys = Record<string, never>
export type GetKeysResponse = { keys: KeyInfo[] }
export type GetMinterDidIds = Record<string, never>
export type GetMinterDidIdsResponse = { did_ids: string[] }
export type GetNetworks = Record<string, never>
export type GetNetworksResponse = { networks: { [key in string]: Network } }
export type GetNft = { nft_id: string }
Expand Down
Loading

0 comments on commit 16d8ec2

Please sign in to comment.