Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions crates/sage-api/src/requests/wallet_connect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde::{Deserialize, Serialize};

use crate::Amount;

/// Filter unlocked coins from a list
#[cfg_attr(
feature = "openapi",
Expand Down Expand Up @@ -109,7 +111,7 @@ pub struct Coin {
/// Puzzle hash
pub puzzle_hash: String,
/// Amount in mojos
pub amount: u64,
pub amount: Amount,
}

/// Lineage proof for CAT coins
Expand All @@ -127,7 +129,7 @@ pub struct LineageProof {
pub inner_puzzle_hash: Option<String>,
/// Amount
#[cfg_attr(feature = "openapi", schema(nullable = true))]
pub amount: Option<u64>,
pub amount: Option<Amount>,
}

/// Sign a message with a public key
Expand Down
24 changes: 15 additions & 9 deletions crates/sage/src/endpoints/wallet_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ use chia_wallet_sdk::{
driver::P2DelegatedConditionsLayer,
prelude::*,
};
use sage_api::wallet_connect::{
self, AssetCoinType, FilterUnlockedCoins, FilterUnlockedCoinsResponse, GetAssetCoins,
GetAssetCoinsResponse, LineageProof, SendTransactionImmediately,
SendTransactionImmediatelyResponse, SignMessageByAddress, SignMessageByAddressResponse,
SignMessageWithPublicKey, SignMessageWithPublicKeyResponse, SpendableCoin,
use sage_api::{
Amount,
wallet_connect::{
self, AssetCoinType, FilterUnlockedCoins, FilterUnlockedCoinsResponse, GetAssetCoins,
GetAssetCoinsResponse, LineageProof, SendTransactionImmediately,
SendTransactionImmediatelyResponse, SignMessageByAddress, SignMessageByAddressResponse,
SignMessageWithPublicKey, SignMessageWithPublicKeyResponse, SpendableCoin,
},
};
use sage_database::{AssetFilter, CoinFilterMode, CoinSortMode, DeserializePrimitive, P2Puzzle};
use sage_wallet::{Status, SyncCommand, Transaction, insert_transaction, submit_to_peers};
Expand Down Expand Up @@ -141,7 +144,7 @@ impl Sage {
coin: wallet_connect::Coin {
parent_coin_info: hex::encode(row.coin.parent_coin_info),
puzzle_hash: hex::encode(row.coin.puzzle_hash),
amount: row.coin.amount,
amount: Amount::u64(row.coin.amount),
},
coin_name: hex::encode(row.coin.coin_id()),
puzzle: hex::encode(ctx.serialize(&puzzle)?),
Expand All @@ -152,12 +155,12 @@ impl Sage {
Some(Proof::Eve(proof)) => Some(LineageProof {
parent_name: Some(hex::encode(proof.parent_parent_coin_info)),
inner_puzzle_hash: None,
amount: Some(proof.parent_amount),
amount: Some(Amount::u64(proof.parent_amount)),
}),
Some(Proof::Lineage(proof)) => Some(LineageProof {
parent_name: Some(hex::encode(proof.parent_parent_coin_info)),
inner_puzzle_hash: Some(hex::encode(proof.parent_inner_puzzle_hash)),
amount: Some(proof.parent_amount),
amount: Some(Amount::u64(proof.parent_amount)),
}),
},
});
Expand Down Expand Up @@ -329,6 +332,9 @@ fn rust_coin(coin: wallet_connect::Coin) -> Result<Coin> {
Ok(Coin {
parent_coin_info: parse_coin_id(coin.parent_coin_info)?,
puzzle_hash: parse_hash(coin.puzzle_hash)?,
amount: coin.amount,
amount: coin
.amount
.to_u64()
.ok_or(Error::InvalidCoinAmount(coin.amount.to_string()))?,
})
}
4 changes: 2 additions & 2 deletions src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ puzzle_hash: string;
/**
* Amount in mojos
*/
amount: number }
amount: Amount }
export type CoinFilterMode = "all" | "selectable" | "owned" | "spent" | "clawback"
export type CoinJson = { parent_coin_info: string; puzzle_hash: string; amount: Amount }
export type CoinRecord = { coin_id: string; address: string; amount: Amount; transaction_id: string | null; offer_id: string | null; clawback_timestamp: number | null; created_height: number | null; spent_height: number | null; spent_timestamp: number | null; created_timestamp: number | null }
Expand Down Expand Up @@ -1751,7 +1751,7 @@ innerPuzzleHash: string | null;
/**
* Amount
*/
amount: number | null }
amount: Amount | null }
export type LogFile = { name: string; text: string }
/**
* Login to a wallet using a fingerprint
Expand Down
4 changes: 2 additions & 2 deletions src/locales/de-DE/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ msgstr "Port"
msgid "Port:"
msgstr "Port:"

#: src/pages/QrScanner.tsx:74
#: src/pages/QrScanner.tsx:91
msgid "Position the QR code within the frame"
msgstr ""

Expand Down Expand Up @@ -3413,7 +3413,7 @@ msgstr ""
msgid "Saving..."
msgstr ""

#: src/pages/QrScanner.tsx:63
#: src/pages/QrScanner.tsx:80
msgid "Scan QR Code"
msgstr ""

Expand Down
4 changes: 2 additions & 2 deletions src/locales/en-US/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ msgstr "Port"
msgid "Port:"
msgstr "Port:"

#: src/pages/QrScanner.tsx:74
#: src/pages/QrScanner.tsx:91
msgid "Position the QR code within the frame"
msgstr "Position the QR code within the frame"

Expand Down Expand Up @@ -3413,7 +3413,7 @@ msgstr "Save Theme"
msgid "Saving..."
msgstr "Saving..."

#: src/pages/QrScanner.tsx:63
#: src/pages/QrScanner.tsx:80
msgid "Scan QR Code"
msgstr "Scan QR Code"

Expand Down
4 changes: 2 additions & 2 deletions src/locales/es-MX/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ msgstr "Puerto"
msgid "Port:"
msgstr "Puerto:"

#: src/pages/QrScanner.tsx:74
#: src/pages/QrScanner.tsx:91
msgid "Position the QR code within the frame"
msgstr "Posiciona el código QR dentro del marco"

Expand Down Expand Up @@ -3413,7 +3413,7 @@ msgstr ""
msgid "Saving..."
msgstr ""

#: src/pages/QrScanner.tsx:63
#: src/pages/QrScanner.tsx:80
msgid "Scan QR Code"
msgstr "Escanea el código QR"

Expand Down
4 changes: 2 additions & 2 deletions src/locales/zh-CN/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ msgstr "端口"
msgid "Port:"
msgstr "端口:"

#: src/pages/QrScanner.tsx:74
#: src/pages/QrScanner.tsx:91
msgid "Position the QR code within the frame"
msgstr ""

Expand Down Expand Up @@ -3413,7 +3413,7 @@ msgstr ""
msgid "Saving..."
msgstr ""

#: src/pages/QrScanner.tsx:63
#: src/pages/QrScanner.tsx:80
msgid "Scan QR Code"
msgstr ""

Expand Down
8 changes: 4 additions & 4 deletions src/walletconnect/commands.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { z } from 'zod';

const safeAmount = z.number().or(z.string());

const coinType = z.object({
parent_coin_info: z.string(),
puzzle_hash: z.string(),
amount: z.number(),
amount: safeAmount,
});

const coinSpendType = z.object({
Expand All @@ -17,8 +19,6 @@ const spendBundleType = z.object({
aggregated_signature: z.string(),
});

const safeAmount = z.number().or(z.string());

const assetAmount = z.object({
assetId: z.string(),
hiddenPuzzleHash: z.string().optional(),
Expand Down Expand Up @@ -118,7 +118,7 @@ export const walletConnectCommands = {
.object({
parentName: z.string().nullable(),
innerPuzzleHash: z.string().nullable(),
amount: z.number().nullable(),
amount: safeAmount.nullable(),
})
.nullable(),
}),
Expand Down
Loading