Skip to content

Commit

Permalink
fix: set the network for all wallet transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Jan 24, 2025
1 parent f6831bf commit 0af8d1d
Show file tree
Hide file tree
Showing 42 changed files with 260 additions and 91 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions applications/tari_dan_wallet_cli/src/command/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use tari_wallet_daemon_client::{
AccountGetResponse,
AccountsTransferRequest,
ConfidentialTransferRequest,
SettingsGetResponse,
TransactionGetResultRequest,
TransactionSubmitDryRunRequest,
TransactionSubmitRequest,
Expand Down Expand Up @@ -241,7 +242,10 @@ pub async fn handle_submit(args: SubmitArgs, client: &mut WalletDaemonClient) ->
fee_account = client.accounts_get_default().await?.account;
}

let SettingsGetResponse { network, .. } = client.get_settings().await?;

let mut builder = Transaction::builder()
.for_network(network.byte)
.fee_transaction_pay_from_component(
fee_account.address.as_component_address().unwrap(),
Amount::try_from(common.max_fee.unwrap_or(1000))?,
Expand Down Expand Up @@ -309,7 +313,10 @@ async fn handle_submit_manifest(
fee_account = client.accounts_get_default().await?.account;
}

let SettingsGetResponse { network, .. } = client.get_settings().await?;

let builder = Transaction::builder()
.for_network(network.byte)
.with_fee_instructions(
instructions
.fee_instructions
Expand Down
11 changes: 9 additions & 2 deletions applications/tari_dan_wallet_daemon/src/handlers/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use tari_dan_common_types::optional::Optional;
use tari_dan_wallet_sdk::apis::{config::ConfigKey, jwt::JrpcPermission};
use tari_wallet_daemon_client::types::{SettingsGetResponse, SettingsSetRequest, SettingsSetResponse};
use tari_wallet_daemon_client::types::{NetworkInfo, SettingsGetResponse, SettingsSetRequest, SettingsSetResponse};

use crate::handlers::HandlerContext;

Expand All @@ -19,8 +19,15 @@ pub async fn handle_get(
.get(ConfigKey::IndexerUrl)
.optional()?
.unwrap_or_else(|| sdk.get_network_interface().get_endpoint().to_string());
let network = sdk.config_api().get_network()?;

Ok(SettingsGetResponse { indexer_url })
Ok(SettingsGetResponse {
indexer_url,
network: NetworkInfo {
name: network.to_string(),
byte: network.as_byte(),
},
})
}

pub async fn handle_set(
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_dan_wallet_daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ pub fn initialize_wallet_sdk(
config.dan_wallet_daemon.indexer_node_json_rpc_url.clone()
};
let indexer = IndexerJsonRpcNetworkInterface::new(indexer_jrpc_endpoint);
let wallet_sdk = DanWalletSdk::initialize(store, indexer, sdk_config)?;
let wallet_sdk = DanWalletSdk::initialize(config.dan_wallet_daemon.network, store, indexer, sdk_config)?;
Ok(wallet_sdk)
}
4 changes: 2 additions & 2 deletions applications/tari_dan_wallet_web_ui/package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,21 @@ export const useAccountsGetDefault = () => {
notifyOnChangeProps: ["data", "error"],
retryOnMount: false,
retry: false,
onError: (error: ApiError) => {
error;
},
onError: (_error: ApiError) => {},
});
};
export const useAccountsGet = (account: ComponentAddressOrName) => {
return useQuery({
queryKey: ["accounts_get"],
queryFn: () => accountsGet({ name_or_address: account }),
onError: (error: ApiError) => {
error;
},
onError: (_error: ApiError) => {},
});
};

export const useAccountNFTsList = (account: ComponentAddressOrName | null, offset: number, limit: number) => {
return useQuery({
queryKey: ["nfts_list"],
queryFn: () => nftList({ account, offset, limit }),
onError: (error: ApiError) => {
error;
},
onError: (_error: ApiError) => {},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import useAccountStore from "../../store/accountStore";
import Onboarding from "../Onboarding/Onboarding";
import MyAssets from "./Components/MyAssets";
import { substateIdToString } from "@tari-project/typescript-bindings";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import FetchStatusCheck from "../../Components/FetchStatusCheck";
import { ApiError } from "../../api/helpers/types";

function AssetVault() {
const { account, setAccount, setPublicKey } = useAccountStore();
Expand All @@ -46,7 +47,6 @@ function AssetVault() {
return (
<FetchStatusCheck errorMessage={""} isError={false} isLoading={isLoading}>
{account ? <MyAssets /> : <Onboarding />}
{/*{accountId ? <>{accountId}</> : <Onboarding />}*/}
</FetchStatusCheck>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import { useState } from "react";
import { FormEvent, useState } from "react";
import { Form } from "react-router-dom";
import TextField from "@mui/material/TextField/TextField";
import Box from "@mui/material/Box";
Expand All @@ -42,7 +42,8 @@ function Onboarding() {
accountName: "",
});

const handleCreateAccount = () => {
const handleCreateAccount = (e: FormEvent) => {
e.preventDefault();
mutate(
{
account: { Name: accountFormState.accountName },
Expand All @@ -59,7 +60,6 @@ function Onboarding() {
};

const onAccountChange = (e: React.ChangeEvent<HTMLInputElement>) => {
e.preventDefault();
setAccountFormState({
...accountFormState,
[e.target.name]: e.target.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ import Box from "@mui/material/Box";
import { useTheme } from "@mui/material/styles";
import IndexerSettings from "./IndexerSettings";
import { Divider } from "@mui/material";
import React from "react";
import React, { useEffect, useState } from "react";
import { settingsGet } from "../../../utils/json_rpc";

function GeneralSettings() {
const theme = useTheme();
const items = [
{
label: "Network",
content: <NetworkSettings />,
},
{
label: "Indexer Url",
content: <IndexerSettings />,
Expand Down Expand Up @@ -60,4 +65,16 @@ function GeneralSettings() {
);
}

function NetworkSettings() {
const [network, setNetwork] = useState("");

useEffect(() => {
settingsGet().then((res) => {
setNetwork(res.network.name);
});
}, []);

return <Typography>{network}</Typography>;
}

export default GeneralSettings;
4 changes: 4 additions & 0 deletions bindings/dist/types/wallet-daemon-client/NetworkInfo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface NetworkInfo {
name: string;
byte: number;
}
2 changes: 2 additions & 0 deletions bindings/dist/types/wallet-daemon-client/NetworkInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export {};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { NetworkInfo } from "./NetworkInfo";
export interface SettingsGetResponse {
indexer_url: string;
network: NetworkInfo;
}
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export {};
1 change: 1 addition & 0 deletions bindings/dist/wallet-daemon-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export * from "./types/wallet-daemon-client/TransactionWaitResultRequest";
export * from "./types/wallet-daemon-client/ClaimValidatorFeesResponse";
export * from "./types/wallet-daemon-client/ConfidentialCreateOutputProofRequest";
export * from "./types/wallet-daemon-client/KeysCreateRequest";
export * from "./types/wallet-daemon-client/NetworkInfo";
export * from "./types/wallet-daemon-client/SettingsGetResponse";
export * from "./types/wallet-daemon-client/TransactionSubmitDryRunResponse";
export * from "./types/wallet-daemon-client/ClaimBurnResponse";
Expand Down
1 change: 1 addition & 0 deletions bindings/dist/wallet-daemon-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export * from "./types/wallet-daemon-client/TransactionWaitResultRequest";
export * from "./types/wallet-daemon-client/ClaimValidatorFeesResponse";
export * from "./types/wallet-daemon-client/ConfidentialCreateOutputProofRequest";
export * from "./types/wallet-daemon-client/KeysCreateRequest";
export * from "./types/wallet-daemon-client/NetworkInfo";
export * from "./types/wallet-daemon-client/SettingsGetResponse";
export * from "./types/wallet-daemon-client/TransactionSubmitDryRunResponse";
export * from "./types/wallet-daemon-client/ClaimBurnResponse";
Expand Down
2 changes: 1 addition & 1 deletion bindings/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tari-project/typescript-bindings",
"version": "1.3.1",
"version": "1.3.2",
"description": "",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions bindings/src/types/wallet-daemon-client/NetworkInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface NetworkInfo {
name: string;
byte: number;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { NetworkInfo } from "./NetworkInfo";

export interface SettingsGetResponse {
indexer_url: string;
network: NetworkInfo;
}
1 change: 1 addition & 0 deletions bindings/src/wallet-daemon-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export * from "./types/wallet-daemon-client/TransactionWaitResultRequest";
export * from "./types/wallet-daemon-client/ClaimValidatorFeesResponse";
export * from "./types/wallet-daemon-client/ConfidentialCreateOutputProofRequest";
export * from "./types/wallet-daemon-client/KeysCreateRequest";
export * from "./types/wallet-daemon-client/NetworkInfo";
export * from "./types/wallet-daemon-client/SettingsGetResponse";
export * from "./types/wallet-daemon-client/TransactionSubmitDryRunResponse";
export * from "./types/wallet-daemon-client/ClaimBurnResponse";
Expand Down
2 changes: 1 addition & 1 deletion clients/javascript/wallet_daemon_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@tari-project/typescript-bindings": "^1.3.1"
"@tari-project/typescript-bindings": "^1.3.2"
},
"devDependencies": {
"typescript": "^5.3.3"
Expand Down
2 changes: 2 additions & 0 deletions clients/javascript/wallet_daemon_client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ export class WalletDaemonClient {
{ token: this.token, timeout_millis: null },
);

// TODO: Handle errors by throwing a custom error type

return response;
}
}
5 changes: 5 additions & 0 deletions clients/wallet_daemon_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ use crate::{
PublishTemplateResponse,
RevealFundsRequest,
RevealFundsResponse,
SettingsGetResponse,
TransactionGetAllRequest,
TransactionGetAllResponse,
TransactionGetRequest,
Expand Down Expand Up @@ -501,6 +502,10 @@ impl WalletDaemonClient {
.await
}

pub async fn get_settings(&mut self) -> Result<SettingsGetResponse, WalletDaemonClientError> {
self.send_request("settings.get", &json!({})).await
}

fn next_request_id(&mut self) -> i64 {
self.request_id += 1;
self.request_id
Expand Down
12 changes: 12 additions & 0 deletions clients/wallet_daemon_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,18 @@ pub struct SettingsSetResponse {}
)]
pub struct SettingsGetResponse {
pub indexer_url: String,
pub network: NetworkInfo,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(
feature = "ts",
derive(TS),
ts(export, export_to = "../../bindings/src/types/wallet-daemon-client/")
)]
pub struct NetworkInfo {
pub name: String,
pub byte: u8,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down
10 changes: 5 additions & 5 deletions dan_layer/template_test_tooling/templates/faucet/Cargo.lock

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

1 change: 1 addition & 0 deletions dan_layer/wallet/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license.workspace = true

[dependencies]
tari_bor = { workspace = true }
tari_common = { workspace = true }
tari_common_types = { workspace = true }
tari_crypto = { workspace = true, features = ["borsh"] }
tari_engine_types = { workspace = true }
Expand Down
Loading

0 comments on commit 0af8d1d

Please sign in to comment.