-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from input-output-hk/fix/update-repo-with-feedback
LW-10152 Feedback on repo
- Loading branch information
Showing
16 changed files
with
333 additions
and
1,556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { ObservableWallet } from '@cardano-sdk/wallet'; | ||
import { inspectAndSignTx } from '../utils'; | ||
import { ObservableWallet } from "@cardano-sdk/wallet"; | ||
import { inspectAndSignTx } from "../utils"; | ||
|
||
export const sendCoins = async ({ | ||
connectedWallet | ||
connectedWallet, | ||
}: { | ||
connectedWallet: ObservableWallet; | ||
}): Promise<{ hash: string; txId: string }> => { | ||
const builder = connectedWallet.createTxBuilder(); | ||
const output = await builder.buildOutput().handle('rhys').coin(10_000_000n).build(); | ||
const output = await builder | ||
.buildOutput() | ||
.handle("rhys") | ||
.coin(10_000_000n) | ||
.build(); | ||
const builtTx = builder.addOutput(output).build(); | ||
|
||
return new Promise(async (resolve) => { | ||
const { hash, txId } = await inspectAndSignTx({ builtTx, connectedWallet }); | ||
resolve({ hash, txId }); | ||
}); | ||
const { hash, txId } = await inspectAndSignTx({ builtTx, connectedWallet }); | ||
return { hash, txId }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
import { EMPTY, catchError, take, tap } from 'rxjs'; | ||
import { ObservableWallet } from '@cardano-sdk/wallet'; | ||
import { inspectAndSignTx } from '../utils'; | ||
import { logger } from '@cardano-sdk/util-dev'; | ||
import { firstValueFrom } from "rxjs"; | ||
import { ObservableWallet } from "@cardano-sdk/wallet"; | ||
import { inspectAndSignTx } from "../utils"; | ||
|
||
export const sendSeveralAssets = ({ | ||
connectedWallet | ||
export const sendSeveralAssets = async ({ | ||
connectedWallet, | ||
}: { | ||
connectedWallet: ObservableWallet; | ||
}): Promise<{ hash: string; txId: string }> => | ||
new Promise((resolve, reject) => { | ||
connectedWallet.balance.utxo.available$ | ||
.pipe( | ||
take(1), | ||
tap(async (availableBalance) => { | ||
if (!availableBalance.assets || availableBalance.assets?.size === 0) { | ||
reject(new Error('Your wallet has no assets')); | ||
return; | ||
} | ||
}): Promise<{ hash: string; txId: string } | null> => { | ||
if (!connectedWallet) { | ||
return null; | ||
} | ||
|
||
let nftCount = 0; | ||
let tokenCount = 0; | ||
const assetMap = new Map(); | ||
for (const [key, value] of availableBalance.assets) { | ||
if (value === 1n && nftCount < 1) { | ||
nftCount++; | ||
assetMap.set(key, value); | ||
} else if (value > 1n && tokenCount < 1) { | ||
tokenCount++; | ||
assetMap.set(key, 1000n); | ||
} | ||
} | ||
const availableBalance = await firstValueFrom( | ||
connectedWallet.balance.utxo.available$ | ||
); | ||
|
||
if (assetMap.size < 2) reject(new Error("Didn't find 1NFT and FT to send")); | ||
if (!availableBalance.assets || availableBalance.assets?.size === 0) { | ||
throw new Error("Your wallet has no assets"); | ||
} | ||
|
||
if (!connectedWallet) { | ||
return null; | ||
} | ||
let nftCount = 0; | ||
let tokenCount = 0; | ||
const assetMap = new Map(); | ||
for (const [key, value] of availableBalance.assets) { | ||
if (value === 1n && nftCount < 1) { | ||
nftCount++; | ||
assetMap.set(key, value); | ||
} else if (value > 1n && tokenCount < 1) { | ||
tokenCount++; | ||
assetMap.set(key, 1000n); | ||
} | ||
} | ||
|
||
const builder = connectedWallet.createTxBuilder(); | ||
const output = await builder.buildOutput().handle('rhys').coin(10_000_000n).build(); | ||
const builtTx = builder.addOutput(output).build(); | ||
const { hash, txId } = await inspectAndSignTx({ builtTx, connectedWallet }); | ||
if (assetMap.size < 2) throw new Error("Didn't find 1NFT and FT to send"); | ||
|
||
resolve({ hash, txId }); | ||
}), | ||
catchError((error) => { | ||
logger.error('Error fetching assets', error); | ||
reject(new Error('Error fetching assets')); | ||
return EMPTY; | ||
}) | ||
) | ||
.subscribe(); | ||
const builder = connectedWallet.createTxBuilder(); | ||
const output = await builder | ||
.buildOutput() | ||
.handle("rhys") | ||
.coin(10_000_000n) | ||
.build(); | ||
const builtTx = builder.addOutput(output).build(); | ||
const { hash, txId } = await inspectAndSignTx({ | ||
builtTx, | ||
connectedWallet, | ||
}); | ||
|
||
return { hash, txId }; | ||
}; |
Oops, something went wrong.