Skip to content

Commit

Permalink
fix(dw): Fund btn + networkId (#2621)
Browse files Browse the repository at this point in the history
* fix(dw): Fund btn + networkId

* fix(dw): sig builder

* fix(dw): sig builder
  • Loading branch information
javadkh2 authored Oct 25, 2024
1 parent cb02e7e commit 09e7584
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ export const ChainBalance: FC<IProps> = ({
Chain {chainId}
</Text>
{!editable && activeNetwork?.faucetContract && fundAccount && (
<span className={fundButtonClass}>
<FundOnTestnetButton
fundAccountHandler={fundAccount}
chainId={chainId}
/>
</span>
<FundOnTestnetButton
className={fundButtonClass}
fundAccountHandler={fundAccount}
chainId={chainId}
/>
)}
</Stack>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const fundButtonClass = style({
'&:focus': {
opacity: 1,
},
'&.pending': {
opacity: 1,
},
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@ import { ITransaction } from '@/modules/transaction/transaction.repository';
import { useWallet } from '@/modules/wallet/wallet.hook';
import { TxContainer } from '@/pages/transaction/components/TxContainer';
import { ChainId } from '@kadena/client';
import { Button } from '@kadena/kode-ui';
import { MonoAutorenew } from '@kadena/kode-icons/system';
import { Button, Stack } from '@kadena/kode-ui';
import classNames from 'classnames';
import { useState } from 'react';

export function FundOnTestnetButton({
account,
chainId,
fundAccountHandler,
className,
}: {
account?: IAccount;
chainId?: ChainId;
fundAccountHandler: (chainId: ChainId) => Promise<ITransaction>;
className?: string;
}) {
const [fundTx, setFundTx] = useState<ITransaction>();
const { syncAllAccounts } = useWallet();
const [done, setDone] = useState(false);

return (
<>
<Stack
gap={'sm'}
alignItems={'center'}
className={classNames(className, fundTx && 'pending')}
>
{!fundTx && (
<Button
variant="outlined"
Expand All @@ -46,12 +55,22 @@ export function FundOnTestnetButton({
} else {
syncAllAccounts();
}
if (tx.result?.result.status === 'success') {
setTimeout(() => setFundTx(undefined), 2000);
}
setDone(true);
}}
/>
)}
</>
{fundTx && done && (
<Button
isCompact
variant="transparent"
onClick={() => {
setFundTx(undefined);
setDone(false);
}}
>
<MonoAutorenew />
</Button>
)}
</Stack>
);
}
9 changes: 7 additions & 2 deletions packages/apps/dev-wallet/src/modules/db/db.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const setupDatabase = execInSequence(async (): Promise<IDBDatabase> => {
unique: true,
},
]);
create('network', 'uuid', [{ index: 'networkId' }]);
create('network', 'uuid', [{ index: 'networkId', unique: true }]);
create('fungible', 'contract', [{ index: 'symbol', unique: true }]);
create('keyset', 'uuid', [
{ index: 'profileId' },
Expand All @@ -105,10 +105,15 @@ export const setupDatabase = execInSequence(async (): Promise<IDBDatabase> => {
},
]);
create('transaction', 'uuid', [
{ index: 'hash', unique: true },
{ index: 'hash' },
{ index: 'profileId' },
{ index: 'groupId' },
{ index: 'network', indexKeyPath: ['profileId', 'networkUUID'] },
{
index: 'unique-tx',
indexKeyPath: ['profileId', 'networkUUID', 'hash'],
unique: true,
},
{
index: 'network-status',
indexKeyPath: ['profileId', 'networkUUID', 'status'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export interface TransactionRepository {
getTransaction: (uuid: string) => Promise<ITransaction>;
getTransactionByHash: (hash: string) => Promise<ITransaction>;
getTransactionsByGroup: (groupId: string) => Promise<ITransaction[]>;
getTransactionByHashNetworkProfile: (
profileId: string,
networkUUID: UUID,
hash: string,
) => Promise<ITransaction>;
addTransaction: (transaction: ITransaction) => Promise<void>;
updateTransaction: (transaction: ITransaction) => Promise<void>;
deleteTransaction: (transactionId: string) => Promise<void>;
Expand Down Expand Up @@ -108,6 +113,21 @@ const createTransactionRepository = ({
const tx = getAll('transaction', hash, 'hash');
return Array.isArray(tx) ? tx[0] : undefined;
},
getTransactionByHashNetworkProfile: async (
profileId: string,
networkUUID: UUID,
hash: string,
) => {
const txs = (await getAll(
'transaction',
IDBKeyRange.only([profileId, networkUUID, hash]),
'unique-tx',
)) as ITransaction[];
if (txs.length > 1) {
throw new Error('Multiple transactions with the same hash');
}
return txs[0];
},
getTransactionsByGroup: async (
groupId: string,
): Promise<ITransaction[]> => {
Expand Down
Loading

0 comments on commit 09e7584

Please sign in to comment.