Skip to content

Commit

Permalink
Merge pull request #2391 from zeitgeistpm/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Apr 8, 2024
2 parents aa54a66 + eb07bcf commit cb77553
Show file tree
Hide file tree
Showing 14 changed files with 1,738 additions and 316 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ NEXT_PUBLIC_SITE_URL=http://localhost:3000
# disable grillchat
NEXT_PUBLIC_GRILLCHAT_DISABLE=true

#wallet connect
NEXT_PUBLIC_WC_PROJECT_ID=

# web3auth
NEXT_PUBLIC_WEB3AUTH_CLIENT_ID=
NEXT_PUBLIC_AUTH0_CLIENT_ID=
Expand Down
5 changes: 3 additions & 2 deletions components/account/WalletSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseDotsamaWallet } from "@talismn/connect-wallets";
import { BaseDotsamaWallet, Wallet } from "@talismn/connect-wallets";
import { useAccountModals } from "lib/state/account";
import { usePrevious } from "lib/hooks/usePrevious";
import { supportedWallets, useWallet } from "lib/state/wallet";
Expand All @@ -18,7 +18,7 @@ const WalletSelect = () => {

const wasConnected = usePrevious(connected);

const handleSelectWallet = async (wallet: BaseDotsamaWallet) => {
const handleSelectWallet = async (wallet: BaseDotsamaWallet | Wallet) => {
if (!wallet.installed && wallet.extensionName !== "web3auth") {
window.open(wallet.installUrl);
} else {
Expand Down Expand Up @@ -101,6 +101,7 @@ const WalletSelect = () => {
const hasError = error != null;
return (
<WalletIcon
key={wallet.extensionName}
onClick={() => {
handleSelectWallet(wallet);
}}
Expand Down
2 changes: 1 addition & 1 deletion components/create/editor/Publishing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const Publishing = ({ editor, creationParams }: PublishingProps) => {
);

const { data: baseFee } = useQuery(
[creationParams, wallet.activeAccount],
[creationParams?.metadata, wallet.activeAccount?.address],
async () => {
if (!feesEnabled) {
return new Decimal(0);
Expand Down
2 changes: 2 additions & 0 deletions lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const SUPPORTED_WALLET_NAMES = [
"web3auth",
];

export const ZTG_CHAIN_ID = "polkadot:1bf2a2ecb4a868de66ea8610f2ce7c8c";

export const endpoints: EndpointOption[] = [
{
value: "wss://zeitgeist-rpc.dwellir.com",
Expand Down
1 change: 0 additions & 1 deletion lib/hooks/queries/useFeePayingAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export const useFeePayingAsset = (
sufficientBalance: true,
};
} else if (IOForeignAssetId.is(assetSelection.value)) {
console.log(IOForeignAssetId.is(assetSelection.value));
const balance = foreignAssetBalances.find(
(asset) =>
IOForeignAssetId.is(assetSelection.value) &&
Expand Down
102 changes: 52 additions & 50 deletions lib/hooks/useCrossChainExtrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,59 +68,61 @@ export const useCrossChainExtrinsic = <T>(
if (!signer || !extrinsic || !sourceChainApi || !destinationChainApi)
return;

const extrinsicCallbackParams = {
api: sourceChainApi,
notifications,
successCallback: async (data) => {
callbacks?.onSourceSuccess && callbacks.onSourceSuccess(data);

const unsub = await destinationChainApi.query.system.events(
(events) => {
for (const record of events) {
const { event } = record;
const { method } = event;
const types = event.typeDef;

// assumes that any activity for the connected address on the destination
// chain means that there has been a successful deposit
const destinationChainActivityDetected = event.data.some(
(data, index) =>
types[index].type === "AccountId32" &&
["deposit", "deposited"].includes(method.toLowerCase()) &&
encodeAddress(
decodeAddress(wallet.activeAccount?.address),
) === encodeAddress(decodeAddress(data.toString())),
);

if (destinationChainActivityDetected) {
unsub();
setIsLoading(false);
setIsSuccess(true);
callbacks?.onDestinationSuccess &&
callbacks.onDestinationSuccess();

queryClient.invalidateQueries([
id,
currencyBalanceRootKey,
wallet.activeAccount?.address,
]);
break;
}
}
},
);
},
failCallback: (error) => {
setIsLoading(false);
setIsError(true);

callbacks?.onSourceError && callbacks.onSourceError();
notifications.pushNotification(error, { type: "Error" });
},
};

signAndSend(
extrinsic,
signer,
extrinsicCallback({
api: sourceChainApi,
notifications,
successCallback: async (data) => {
callbacks?.onSourceSuccess && callbacks.onSourceSuccess(data);

const unsub = await destinationChainApi.query.system.events(
(events) => {
for (const record of events) {
const { event } = record;
const { method } = event;
const types = event.typeDef;

// assumes that any activity for the connected address on the destination
// chain means that there has been a successful deposit
const destinationChainActivityDetected = event.data.some(
(data, index) =>
types[index].type === "AccountId32" &&
["deposit", "deposited"].includes(method.toLowerCase()) &&
encodeAddress(
decodeAddress(wallet.activeAccount?.address),
) === encodeAddress(decodeAddress(data.toString())),
);

if (destinationChainActivityDetected) {
unsub();
setIsLoading(false);
setIsSuccess(true);
callbacks?.onDestinationSuccess &&
callbacks.onDestinationSuccess();

queryClient.invalidateQueries([
id,
currencyBalanceRootKey,
wallet.activeAccount?.address,
]);
break;
}
}
},
);
},
failCallback: (error) => {
setIsLoading(false);
setIsError(true);

callbacks?.onSourceError && callbacks.onSourceError();
notifications.pushNotification(error, { type: "Error" });
},
}),
extrinsicCallback(extrinsicCallbackParams),
IOForeignAssetId.is(fee?.assetId) ? fee?.assetId.ForeignAsset : undefined,
).catch((error) => {
notifications.pushNotification(error?.toString() ?? "Unknown Error", {
Expand Down
56 changes: 29 additions & 27 deletions lib/hooks/useExtrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,38 @@ export const useExtrinsic = <T>(
}
}

const extrinsicCallbackParams = {
api: sdk.api,
notifications,
broadcastCallback: () => {
setIsBroadcasting(true);
callbacks?.onBroadcast
? callbacks.onBroadcast()
: notifications?.pushNotification("Broadcasting transaction...", {
autoRemove: true,
});
},
successCallback: (data) => {
setIsLoading(false);
setIsSuccess(true);
setIsBroadcasting(false);

callbacks?.onSuccess && callbacks.onSuccess(data);
},
failCallback: (error) => {
setIsLoading(false);
setIsError(true);
setIsBroadcasting(false);

callbacks?.onError && callbacks.onError();
notifications.pushNotification(error, { type: "Error" });
},
};

signAndSend(
extrinsic,
signer,
extrinsicCallback({
api: sdk.api,
notifications,
broadcastCallback: () => {
setIsBroadcasting(true);
callbacks?.onBroadcast
? callbacks.onBroadcast()
: notifications?.pushNotification("Broadcasting transaction...", {
autoRemove: true,
});
},
successCallback: (data) => {
setIsLoading(false);
setIsSuccess(true);
setIsBroadcasting(false);

callbacks?.onSuccess && callbacks.onSuccess(data);
},
failCallback: (error) => {
setIsLoading(false);
setIsError(true);
setIsBroadcasting(false);

callbacks?.onError && callbacks.onError();
notifications.pushNotification(error, { type: "Error" });
},
}),
extrinsicCallback(extrinsicCallbackParams),
IOForeignAssetId.is(fee?.assetId) ? fee?.assetId.ForeignAsset : undefined,
).catch((error) => {
notifications.pushNotification(error?.toString() ?? "Unknown Error", {
Expand Down
Loading

0 comments on commit cb77553

Please sign in to comment.