Skip to content
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build": "vite build",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes the "tsc" step in build because vite already compiles it and I got an error in node_modules when upgrading @agoric/web-components https://gist.github.com/samsiegart/7794b51ef6875a14fc5521a53bf9fdb0

Thanks for explaining this. In the other PR I asked for tsc to be in lint. I won't ask that here. I thought of asking that the reason for omission be mentioned in the README but maybe by the time someone tries to add tsc back it won't have problems. If it does they won't have wasted much time finding out.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a yarn lint:types with a warning. My standpoint is that this would take some effort to debug here and in Agoric/dapp-inter#401 and these apps are going to be shut down soon anyway

"preview": "vite preview",
"lint": "eslint src",
"lint:types": "echo 'XXX tsc is not working, even though vite build is successful' && tsc --noEmit",
"format": "prettier --write . && yarn lint --fix",
"test": "vitest",
"coverage": "vitest run --coverage",
Expand All @@ -25,7 +26,7 @@
"@agoric/smart-wallet": "^0.5.3",
"@agoric/synpress": "^3.8.5-beta.0",
"@agoric/ui-components": "^0.9.0",
"@agoric/web-components": "^0.15.0",
"@agoric/web-components": "^0.17.0",
"@agoric/zoe": "^0.26.2",
"@endo/eventual-send": "^1.1.2",
"@headlessui/react": "^1.6.6",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChainConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toast } from 'react-toastify';
import { Oval } from 'react-loader-spinner';
import {
makeAgoricWalletConnection,
AgoricKeplrConnectionErrors as Errors,
Errors,
suggestChain,
} from '@agoric/web-components';
import {
Expand Down
47 changes: 34 additions & 13 deletions src/components/ProvisionSmartWalletDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const useSmartWalletFeeQuery = (rpc?: string) => {
const [smartWalletFee, setFee] = useState<{
fee: bigint;
feeUnit: bigint;
feeUnitName: string;
} | null>(null);
const [error, setError] = useState<Error | null>(null);

Expand All @@ -24,8 +25,16 @@ const useSmartWalletFeeQuery = (rpc?: string) => {
const feeUnit = params.params.beansPerUnit.find(
({ key }: { key: string }) => key === 'feeUnit'
)?.beans;
assert(feeUnit);
setFee({ fee: BigInt(beansPerSmartWallet), feeUnit: BigInt(feeUnit) });
const feeUnitName = params.params?.feeUnitPrice[0]?.denom;
assert(
beansPerSmartWallet && feeUnit && feeUnitName,
'missing fee params'
);
setFee({
fee: BigInt(beansPerSmartWallet),
feeUnit: BigInt(feeUnit),
feeUnitName,
});
} catch (e) {
setError(e as Error);
}
Expand Down Expand Up @@ -54,12 +63,20 @@ const ProvisionSmartWalletNoticeDialog = ({
const { smartWalletFee, error: _smartWalletFeeError } =
useSmartWalletFeeQuery(rpc);

const feeUnitNameForDisplay =
smartWalletFee?.feeUnitName === 'uist' ? 'IST' : 'BLD';
const smartWalletFeeForDisplay = smartWalletFee
? String(smartWalletFee.fee / smartWalletFee.feeUnit) + ' IST'
? String(smartWalletFee.fee / smartWalletFee.feeUnit) +
' ' +
feeUnitNameForDisplay
: null;

const purses = useAtomValue(pursesAtom);
const istPurse = purses?.find(p => p.brandPetname === 'IST');
const bldPurse = purses?.find(p => p.brandPetname === 'BLD');
const purseToDisplay =
smartWalletFee?.feeUnitName === 'uist' ? istPurse : bldPurse;

const { displayAmount, getDecimalPlaces } =
useAtomValue(displayFunctionsAtom) ?? {};

Expand All @@ -73,37 +90,41 @@ const ProvisionSmartWalletNoticeDialog = ({
&quot;Proceed&quot; to provision wallet and submit transaction.
</div>
<div className="my-4 flex justify-center gap-4">
{istPurse && displayAmount && (
{purseToDisplay && displayAmount && (
<div className="flex items-center">
<span>
IST Balance: <b>{displayAmount(istPurse.currentAmount)}</b>
{feeUnitNameForDisplay} Balance:{' '}
<b>{displayAmount(purseToDisplay.currentAmount)}</b>
</span>
</div>
)}
{istPurse && (
{purseToDisplay && (
<LeapLiquidityModal
selectedAsset={istPurse.brand}
selectedAsset={purseToDisplay.brand}
direction={Direction.deposit}
/>
)}
</div>
</>
);
const istDecimals =
istPurse && getDecimalPlaces && getDecimalPlaces(istPurse.brand);
const decimalsToDisplay =
purseToDisplay &&
getDecimalPlaces &&
getDecimalPlaces(purseToDisplay.brand);

// "feeUnit" is observed to be 1000000000000n, so when "fee" is 1000000000000n
// that means 1 IST (after dividing "fee" by "feeUnit"). To convert to uIST,
// we then multiply by 10^6.
const denominatedSmartWalletFee =
istDecimals &&
decimalsToDisplay &&
smartWalletFee &&
(smartWalletFee.fee / smartWalletFee.feeUnit) * 10n ** BigInt(istDecimals);
(smartWalletFee.fee / smartWalletFee.feeUnit) *
10n ** BigInt(decimalsToDisplay);

const hasRequiredFee =
denominatedSmartWalletFee &&
istPurse !== undefined &&
istPurse.currentAmount.value >= denominatedSmartWalletFee;
purseToDisplay !== undefined &&
purseToDisplay.currentAmount.value >= denominatedSmartWalletFee;

return (
<ActionsDialog
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/specs/swap-tokens.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ describe('Swap Tokens Tests', () => {
expect(amount).to.be.oneOf([
limitFloat(istBalance - amountToSwap - provisionFee),
limitFloat(istBalance - amountToSwap - provisionFee - transactionFee),
limitFloat(istBalance - amountToSwap), // If provision fee in IST is removed
limitFloat(istBalance - amountToSwap - transactionFee),
])
);
});
Expand Down
Loading