Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dw): Fund btn + networkId #2621

Merged
merged 3 commits into from
Oct 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
chainId: ChainId;
fundAccount?: (chainId: ChainId) => Promise<ITransaction>;
editable?: boolean;
onItemChange?: (key: string, value: any) => void;

Check warning on line 26 in packages/apps/dev-wallet/src/Components/AccountBalanceDistribution/components/ChainBalance.tsx

View workflow job for this annotation

GitHub Actions / Build & unit test

Unexpected any. Specify a different type
}

export const ChainBalance: FC<IProps> = ({
Expand Down Expand Up @@ -63,12 +63,11 @@
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
Loading