Skip to content

Commit

Permalink
Merge branch 'main' of github.com:TrustlessComputer/bvm-website
Browse files Browse the repository at this point in the history
  • Loading branch information
camewell071 committed Sep 6, 2024
2 parents 8eaa8b2 + 2ca6119 commit 6314947
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 87 deletions.
8 changes: 5 additions & 3 deletions src/modules/blockchains/Buy/hooks/useCheckNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ import {
} from '../mockup_3';
import {
draggedDappIndexesSignal,
draggedIds2DSignal
draggedIds2DSignal,
} from '../signals/useDragSignal';
import useDappsStore from '../stores/useDappStore';
import { needReactFlowRenderSignal } from '../studio/ReactFlowRender';
import { cloneDeep } from '../utils';
import { IModelOption } from '@/types/customize-model';
import { mouseDroppedPositionSignal } from '@/modules/blockchains/Buy/signals/useMouseDroppedPosition';
import useFormChain from './useFormChain';
import { useAAModule } from '@/modules/blockchains/detail_v4/hook/useAAModule';

export default function useCheckNodes() {
const { field } = useOrderFormStoreV3();
const { nodes, setNodes, edges, setEdges } = useFlowStore();
const { getCurrentFieldFromChain } = useFormChain();
const { lineBridgeStatus } = useBridgesModule();
const { lineAAStatus } = useAAModule();
const { dapps } = useDappsStore();
const store = useStoreApi();
const {
Expand Down Expand Up @@ -123,11 +125,11 @@ export default function useCheckNodes() {
target: `account_abstraction`,
targetHandle: `account_abstraction-t-${rootNode}`,
type: 'customEdge',
label: handleStatusEdges('', lineBridgeStatus, 'account_abstraction')
label: handleStatusEdges('', lineAAStatus, 'account_abstraction')
.icon,
animated: handleStatusEdges(
'',
lineBridgeStatus,
lineAAStatus,
'account_abstraction',
).animate,
markerEnd: {
Expand Down
11 changes: 8 additions & 3 deletions src/modules/blockchains/Buy/hooks/useFetchingTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,22 @@ export default function useFetchingTemplate() {
const newDraggedDappIndexes = [];

if (isAAInstalled) {
newDraggedDappIndexes.push(0);
const dappIndex = dapps.findIndex(
(dapp) => dapp.key === 'account_abstraction',
);
newDraggedDappIndexes.push(dappIndex);
newDraggedIds2D.push([]);
}

if (isBridgeInstalled) {
newDraggedDappIndexes.push(1);
const dappIndex = dapps.findIndex((dapp) => dapp.key === 'bridge_apps');
newDraggedDappIndexes.push(dappIndex);
newDraggedIds2D.push([]);
}

if (isGamingAppsInstalled) {
newDraggedDappIndexes.push(2);
const dappIndex = dapps.findIndex((dapp) => dapp.key === 'gaming_apps');
newDraggedDappIndexes.push(dappIndex);
newDraggedIds2D.push([]);
}

Expand Down
129 changes: 84 additions & 45 deletions src/modules/blockchains/Buy/hooks/useHandleDragging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ export default function useHandleDragging() {
const ignoreKeys = ['bridge_apps', 'gaming_apps'];
console.log('runnnnnnnn 1');
if (!rightDragging && !overIsFinalDroppable && overSuffix1 !== 'right') {
if(isMultiChoice) {
if (isMultiChoice) {
const currentValues = (field[activeKey].value || []) as string[];
const isCurrentEmpty = currentValues.length === 0;
const newValue = [...currentValues, active.data.current.value];
const bridgeAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'bridge_apps',
);
const gamingAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'gaming_apps',
);

if (currentValues.includes(active.data.current.value)) return;

Expand All @@ -140,19 +146,25 @@ export default function useHandleDragging() {

if (
activeKey === 'bridge_apps' &&
!draggedDappIndexesSignal.value.includes(1) &&
!draggedDappIndexesSignal.value.includes(bridgeAppsIndex) &&
!activeIsParent
) {
draggedDappIndexesSignal.value = [...draggedDappIndexesSignal.value, 1];
draggedDappIndexesSignal.value = [
...draggedDappIndexesSignal.value,
bridgeAppsIndex,
];
draggedIds2DSignal.value = [...draggedIds2DSignal.value, []];
}

if (
activeKey === 'gaming_apps' &&
!draggedDappIndexesSignal.value.includes(2) &&
!draggedDappIndexesSignal.value.includes(gamingAppsIndex) &&
!activeIsParent
) {
draggedDappIndexesSignal.value = [...draggedDappIndexesSignal.value, 2];
draggedDappIndexesSignal.value = [
...draggedDappIndexesSignal.value,
gamingAppsIndex,
];
draggedIds2DSignal.value = [...draggedIds2DSignal.value, []];
}

Expand Down Expand Up @@ -262,12 +274,18 @@ export default function useHandleDragging() {
// setValueOptionInputStore(optionKey, '');
deleteValueOptionInputStore(optionKey);
});
const bridgeAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'bridge_apps',
);
const gamingAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'gaming_apps',
);

setField(activeKey, [], false);
setDraggedFields(draggedFields.filter((field) => field !== activeKey));

if (activeKey === 'bridge_apps') {
const index = draggedDappIndexesSignal.value.indexOf(1);
const index = draggedDappIndexesSignal.value.indexOf(bridgeAppsIndex);

if (index !== -1) {
draggedDappIndexesSignal.value = removeItemAtIndex(
Expand All @@ -283,7 +301,7 @@ export default function useHandleDragging() {
}

if (activeKey === 'gaming_apps') {
const index = draggedDappIndexesSignal.value.indexOf(2);
const index = draggedDappIndexesSignal.value.indexOf(gamingAppsIndex);

if (index !== -1) {
draggedDappIndexesSignal.value = removeItemAtIndex(
Expand All @@ -303,13 +321,20 @@ export default function useHandleDragging() {
console.log('runnnnnnnn 7');
// Multi choice case
if (
((over && (overIsFinalDroppable || overIsParentOfActiveDroppable)) ||
(!overIsFinalDroppable && overSuffix1 === 'right')) || !over
(over && (overIsFinalDroppable || overIsParentOfActiveDroppable)) ||
(!overIsFinalDroppable && overSuffix1 === 'right') ||
!over
) {
console.log('runnnnnnnn 8');
const currentValues = (field[activeKey].value || []) as string[];
const isCurrentEmpty = currentValues.length === 0;
const newValue = [...currentValues, active.data.current.value];
const bridgeAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'bridge_apps',
);
const gamingAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'gaming_apps',
);

if (currentValues.includes(active.data.current.value)) return;

Expand All @@ -318,19 +343,25 @@ export default function useHandleDragging() {

if (
activeKey === 'bridge_apps' &&
!draggedDappIndexesSignal.value.includes(1) &&
!draggedDappIndexesSignal.value.includes(bridgeAppsIndex) &&
!activeIsParent
) {
draggedDappIndexesSignal.value = [...draggedDappIndexesSignal.value, 1];
draggedDappIndexesSignal.value = [
...draggedDappIndexesSignal.value,
bridgeAppsIndex,
];
draggedIds2DSignal.value = [...draggedIds2DSignal.value, []];
}

if (
activeKey === 'gaming_apps' &&
!draggedDappIndexesSignal.value.includes(2) &&
!draggedDappIndexesSignal.value.includes(gamingAppsIndex) &&
!activeIsParent
) {
draggedDappIndexesSignal.value = [...draggedDappIndexesSignal.value, 2];
draggedDappIndexesSignal.value = [
...draggedDappIndexesSignal.value,
gamingAppsIndex,
];
draggedIds2DSignal.value = [...draggedIds2DSignal.value, []];
}
} else {
Expand All @@ -353,10 +384,16 @@ export default function useHandleDragging() {

setField(activeKey, newValue, !isEmpty);
if (isEmpty) {
const bridgeAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'bridge_apps',
);
const gamingAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'gaming_apps',
);
setDraggedFields(draggedFields.filter((field) => field !== activeKey));

if (activeKey === 'bridge_apps') {
const index = draggedDappIndexesSignal.value.indexOf(1);
const index = draggedDappIndexesSignal.value.indexOf(bridgeAppsIndex);

if (index !== -1) {
draggedDappIndexesSignal.value = removeItemAtIndex(
Expand All @@ -372,7 +409,7 @@ export default function useHandleDragging() {
}

if (activeKey === 'gaming_apps') {
const index = draggedDappIndexesSignal.value.indexOf(2);
const index = draggedDappIndexesSignal.value.indexOf(gamingAppsIndex);

if (index !== -1) {
draggedDappIndexesSignal.value = removeItemAtIndex(
Expand Down Expand Up @@ -837,7 +874,7 @@ export default function useHandleDragging() {
if (activeIsABaseModule) {
const totalPlaced = draggedDappIndexesSignal.value.filter(
(index) => index === dappIndex,
).length
).length;
// prettier-ignore
const canPlaceMoreBaseModule = baseModuleFieldMapping[dappIndex][activeOriginalKey].placableAmount === -1 ||
totalPlaced < baseModuleFieldMapping[dappIndex][activeOriginalKey].placableAmount;
Expand Down Expand Up @@ -1077,42 +1114,44 @@ export default function useHandleDragging() {
// Case 2.1: Dragged lego is a base block
if (activeIsABase) {
const totalTemplateDapps = (templateDapps || []).length;
const removeIndex = activeBaseIndex + 1 + totalTemplateDapps;
const removeIndex = activeBaseIndex + 1 + totalTemplateDapps - 1;
console.log('HEHEHEHEHEHHEHEHEHHEHE', {
nodes: nodes,
edges: edges.length,
removeIndex,
activeBaseIndex,
totalTemplateDapps,
});
const rootNode = 'blockchain';

const newEdges = edges.filter(
(item) => item.target !== nodes[removeIndex].id,
);
let newNodes = removeItemAtIndex(nodes, removeIndex);

let getHandleNodeBlockChain = nodes.find(
(item) => item.id === rootNode,
);

let countSourceHandle = 0;

for (let i = 0; i < edges.length; i++) {
if (edges[i].sourceHandle === `${rootNode}-s-${thisDapp.title}`) {
countSourceHandle += 1;
}
}

if (countSourceHandle == 1) {
const newSourceHandles =
getHandleNodeBlockChain?.data.sourceHandles?.filter(
(item) => item !== `${rootNode}-s-${thisDapp.title}`,
);
const data = {
...getHandleNodeBlockChain,
data: {
...getHandleNodeBlockChain?.data,
sourceHandles: newSourceHandles,
},
};
newNodes = newNodes.map((item) =>
item.id === rootNode ? data : item,
) as AppState['nodes'];
}
// for (let i = 0; i < edges.length; i++) {
// if (edges[i].sourceHandle === `${rootNode}-s-${thisDapp.title}`) {
// countSourceHandle += 1;
// }
// }

// if (countSourceHandle == 1) {
// const newSourceHandles =
// getHandleNodeBlockChain?.data.sourceHandles?.filter(
// (item) => item !== `${rootNode}-s-${thisDapp.title}`,
// );
// const data = {
// ...getHandleNodeBlockChain,
// data: {
// ...getHandleNodeBlockChain?.data,
// sourceHandles: newSourceHandles,
// },
// };
// newNodes = newNodes.map((item) =>
// item.id === rootNode ? data : item,
// ) as AppState['nodes'];
// }

const formDapp = formDappSignal.value;

Expand Down Expand Up @@ -1155,7 +1194,7 @@ export default function useHandleDragging() {

//Drag remove node
setNodes(newNodes);
setEdges(newEdges);
// setEdges(newEdges);
needReactFlowRenderSignal.value = true;

return;
Expand Down
26 changes: 22 additions & 4 deletions src/modules/blockchains/Buy/hooks/useNodeFlowControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ export default function useNodeFlowControl() {
};

useSignalEffect(() => {
const bridgeAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'bridge_apps',
);
const gamingAppsIndex = dapps.findIndex(
(dapp) => dapp.key === 'gaming_apps',
);
const accountAbstractionIndex = dapps.findIndex(
(dapp) => dapp.key === 'account_abstraction',
);
console.log('[useNodeFlowControl]', { nodes });

needReactFlowRenderSignal.value = true;
Expand All @@ -105,7 +114,10 @@ export default function useNodeFlowControl() {

needReactFlowRenderSignal.value = true;

if (draggedDappIndexesSignal.value.includes(0) && isAAInstalled) {
if (
draggedDappIndexesSignal.value.includes(accountAbstractionIndex) &&
isAAInstalled
) {
if (!nodes.some((node) => node.id === 'account_abstraction')) {
const rootNode = 'blockchain';
const thisDapp = accountAbstractionAsADapp;
Expand Down Expand Up @@ -172,7 +184,10 @@ export default function useNodeFlowControl() {
}
}

if (draggedDappIndexesSignal.value.includes(1) && isBridgeInstalled) {
if (
draggedDappIndexesSignal.value.includes(bridgeAppsIndex) &&
isBridgeInstalled
) {
console.log('[useNodeFlowControl] case 1');

if (!nodes.some((node) => node.id === 'bridge_apps')) {
Expand Down Expand Up @@ -233,10 +248,13 @@ export default function useNodeFlowControl() {
}
}

if (draggedDappIndexesSignal.value.includes(2) && isGamingAppsInstalled) {
if (
draggedDappIndexesSignal.value.includes(gamingAppsIndex) &&
isGamingAppsInstalled
) {
if (!nodes.some((node) => node.id === 'gaming_apps')) {
const rootNode = 'blockchain';
const thisDapp = bridgesAsADapp;
const thisDapp = gamingAppsAsADapp;
let nodesData = nodes;
const newNodeId = 'gaming_apps';
const newNode: DappNode = {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/blockchains/Buy/hooks/useOnlyFetchDapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const useOnlyFetchDapp = () => {

_dapps.push(...otherDapps);

console.log('[useOnlyFetchDapp] dapps', _dapps);

const sortedDapps = _dapps.sort((a, b) => a.order - b.order);

setDapps(preDataAirdropTask(sortedDapps, tokens, airdropTasks));
Expand Down
4 changes: 2 additions & 2 deletions src/modules/blockchains/Buy/mockup_3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const bridgesAsADapp: DappModel = {
key: 'bridge_apps',
title: 'Bridges',
icon: 'https://storage.googleapis.com/bvm-network/icons-tool/icon-issue-a-token.svg',
order: 2,
order: 1,
color: '#855AFF',
color_border: '#855AFF',
created_at: '2021-09-14T09:00:00.000Z',
Expand Down Expand Up @@ -120,7 +120,7 @@ export const gamingAppsAsADapp: DappModel = {
key: 'gaming_apps',
title: 'Gaming Apps',
icon: 'https://storage.googleapis.com/bvm-network/icons-tool/icon-issue-a-token.svg',
order: 3,
order: 1,
color: '#FFB800',
color_border: '#FFB800',
created_at: '2021-09-14T09:00:00.000Z',
Expand Down
Loading

0 comments on commit 6314947

Please sign in to comment.