Skip to content

Commit

Permalink
Make transactions work again
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Dec 8, 2024
1 parent 5bab3d0 commit b81b732
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 26 deletions.
23 changes: 18 additions & 5 deletions src/components/NftCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@/bindings';
import { amount } from '@/lib/formTypes';
import { nftUri } from '@/lib/nftUri';
import { toMojos } from '@/lib/utils';
import { useWalletState } from '@/state';
import { zodResolver } from '@hookform/resolvers/zod';
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
Expand Down Expand Up @@ -103,7 +104,11 @@ export function NftCard({ nft, updateNfts, selectionState }: NftProps) {

const onTransferSubmit = (address: string, fee: string) => {
commands
.transferNfts({ nft_ids: [nft.launcher_id], address, fee })
.transferNfts({
nft_ids: [nft.launcher_id],
address,
fee: toMojos(fee, walletState.sync.unit.decimals),
})
.then((result) => {
setTransferOpen(false);
if (result.status === 'error') {
Expand All @@ -116,7 +121,11 @@ export function NftCard({ nft, updateNfts, selectionState }: NftProps) {

const onAssignSubmit = (profile: string, fee: string) => {
commands
.assignNftsToDid({ nft_ids: [nft.launcher_id], did_id: profile, fee })
.assignNftsToDid({
nft_ids: [nft.launcher_id],
did_id: profile,
fee: toMojos(fee, walletState.sync.unit.decimals),
})
.then((result) => {
setAssignOpen(false);
if (result.status === 'error') {
Expand All @@ -129,7 +138,11 @@ export function NftCard({ nft, updateNfts, selectionState }: NftProps) {

const onUnassignSubmit = (fee: string) => {
commands
.assignNftsToDid({ nft_ids: [nft.launcher_id], did_id: null, fee })
.assignNftsToDid({
nft_ids: [nft.launcher_id],
did_id: null,
fee: toMojos(fee, walletState.sync.unit.decimals),
})
.then((result) => {
setUnassignOpen(false);
if (result.status === 'error') {
Expand Down Expand Up @@ -164,7 +177,7 @@ export function NftCard({ nft, updateNfts, selectionState }: NftProps) {
nft_id: nft.launcher_id,
uri: values.url,
kind: values.kind as NftUriKind,
fee: values.fee,
fee: toMojos(values.fee, walletState.sync.unit.decimals),
})
.then((result) => {
setAddUrlOpen(false);
Expand All @@ -181,7 +194,7 @@ export function NftCard({ nft, updateNfts, selectionState }: NftProps) {
.transferNfts({
nft_ids: [nft.launcher_id],
address: walletState.sync.burn_address,
fee,
fee: toMojos(fee, walletState.sync.unit.decimals),
})
.then((result) => {
setBurnOpen(false);
Expand Down
10 changes: 1 addition & 9 deletions src/lib/formTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ export const amount = (decimals: number) =>
);

return mojos.isLessThanOrEqualTo(BigNumber('18446744073709551615'));
}, 'Values is too large')

.transform((amount) => {
const mojos = BigNumber(amount || 0).multipliedBy(
BigNumber(10).pow(decimals),
);

return mojos.toString();
});
}, 'Values is too large');

export const positiveAmount = (decimals: number) =>
amount(decimals).refine(
Expand Down
9 changes: 7 additions & 2 deletions src/pages/DidList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Switch } from '@/components/ui/switch';
import { useDids } from '@/hooks/useDids';
import { toMojos } from '@/lib/utils';
import { useWalletState } from '@/state';
import {
EyeIcon,
Expand Down Expand Up @@ -149,7 +150,11 @@ function Profile({ did, updateDids }: ProfileProps) {

const onTransferSubmit = (address: string, fee: string) => {
commands
.transferDids({ did_ids: [did.launcher_id], address, fee })
.transferDids({
did_ids: [did.launcher_id],
address,
fee: toMojos(fee, walletState.sync.unit.decimals),
})
.then((result) => {
setTransferOpen(false);
if (result.status === 'error') {
Expand All @@ -165,7 +170,7 @@ function Profile({ did, updateDids }: ProfileProps) {
.transferDids({
did_ids: [did.launcher_id],
address: walletState.sync.burn_address,
fee,
fee: toMojos(fee, walletState.sync.unit.decimals),
})
.then((result) => {
setBurnOpen(false);
Expand Down
8 changes: 6 additions & 2 deletions src/pages/IssueToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@/components/ui/form';
import { Input } from '@/components/ui/input';
import { amount, positiveAmount } from '@/lib/formTypes';
import { toMojos } from '@/lib/utils';
import { zodResolver } from '@hookform/resolvers/zod';
import { useState } from 'react';
import { useForm } from 'react-hook-form';
Expand Down Expand Up @@ -44,8 +45,11 @@ export default function IssueToken() {
.issueCat({
name: values.name,
ticker: values.ticker,
amount: values.amount.toString(),
fee: values.fee?.toString() || '0',
amount: toMojos(values.amount.toString(), 3),
fee: toMojos(
values.fee?.toString() || '0',
walletState.sync.unit.decimals,
),
})
.then((result) => {
if (result.status === 'error') {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/NftList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function NftList() {
if (result.status === 'ok') {
setNfts(result.data.nfts);
} else {
throw new Error('Failed to get NFTs');
console.error('Failed to get NFTs', result.error);
}
});
} else if (view === 'collection') {
Expand All @@ -68,7 +68,7 @@ export function NftList() {
if (result.status === 'ok') {
setCollections(result.data.collections);
} else {
throw new Error('Failed to get NFT collections');
console.error('Failed to get NFT collections', result.error);
}
});
}
Expand All @@ -77,7 +77,7 @@ export function NftList() {
);

useEffect(() => {
updateNfts(0);
updateNfts(1);
}, [updateNfts]);

useEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ export default function Send() {
command({
address: values.address,
amount: toMojos(values.amount.toString(), asset?.decimals || 12),
fee: toMojos(values.fee?.toString() || '0', asset?.decimals || 12),
fee: toMojos(
values.fee?.toString() || '0',
walletState.sync.unit.decimals,
),
}).then((confirmation) => {
if (confirmation.status === 'error') {
console.error(confirmation.error);
Expand Down
9 changes: 6 additions & 3 deletions src/pages/Token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { usePrices } from '@/contexts/PriceContext';
import { amount } from '@/lib/formTypes';
import { toDecimal } from '@/lib/utils';
import { toDecimal, toMojos } from '@/lib/utils';
import { useWalletState } from '@/state';
import { zodResolver } from '@hookform/resolvers/zod';
import { RowSelectionState } from '@tanstack/react-table';
Expand Down Expand Up @@ -434,7 +434,10 @@ function CoinCard({
});

const onCombineSubmit = (values: z.infer<typeof combineFormSchema>) => {
combineHandler?.({ coin_ids: selectedCoinIds, fee: values.combineFee })
combineHandler?.({
coin_ids: selectedCoinIds,
fee: toMojos(values.combineFee, walletState.sync.unit.decimals),
})
.then((result) => {
setCombineOpen(false);

Expand Down Expand Up @@ -465,7 +468,7 @@ function CoinCard({
splitHandler?.({
coin_ids: selectedCoinIds,
output_count: values.outputCount,
fee: values.splitFee,
fee: toMojos(values.splitFee, walletState.sync.unit.decimals),
})
.then((result) => {
setSplitOpen(false);
Expand Down
5 changes: 4 additions & 1 deletion src/pages/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ export function TokenList() {
~$
{getBalanceInUsd(
'xch',
toDecimal(walletState.sync.balance, 3),
toDecimal(
walletState.sync.balance,
walletState.sync.unit.decimals,
),
)}
</div>
</CardContent>
Expand Down

0 comments on commit b81b732

Please sign in to comment.