Skip to content

Commit

Permalink
Remove dripsJsonTemplate in favor of methods for changed template
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Brown committed Dec 6, 2024
1 parent 045dc89 commit 802061e
Showing 1 changed file with 3 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
// Map(Object.entries(JSON.parse(jsonText)))

// JSON.stringify(Object.fromEntries(foo.entries()))

// Object.keys(existingJson.drips).map((key) => {
// return `
// "${key}"
// `
// })
const NUM_SPACES = 2;

export const getChangedTemplate = (
existingJson: object,
Expand All @@ -15,7 +7,7 @@ export const getChangedTemplate = (
): [string, [number | null, number | null]] => {
// no change, so don't highlight anything
if (Object.keys(existingJson).length === 0) {
return [JSON.stringify(objectTemplate(address, network), null, 2), [null, null]];
return [JSON.stringify(objectTemplate(address, network), null, NUM_SPACES), [null, null]];
}

// object are now iterated in order, so when we add the new network here, it will
Expand All @@ -25,23 +17,15 @@ export const getChangedTemplate = (
ownedBy: address,
};

const asJSON = JSON.stringify(existingJsonCopy, null, 2);
const asJSON = JSON.stringify(existingJsonCopy, null, NUM_SPACES);
const end = asJSON.lastIndexOf('}');
// TODO: can we make this magic string based of the actual content?
const start =
end - ' "": {\n "ownedBy": ""\n }\n }\n'.length - network.length - address.length;

return [asJSON, [start, end]];
// or whatever this should do
// something like take the full config as an object
// take the user's current configuration as an object
// take the network we want to add
// take the users fill configuration and add the network
// return it as a string?
};

// the code box should also take indices, which specificy highlight position(s)

export const objectTemplate = (address: string, network = 'ethereum') => {
return {
drips: {
Expand All @@ -51,12 +35,3 @@ export const objectTemplate = (address: string, network = 'ethereum') => {
},
};
};

export default (address: string, network = 'ethereum') => `{
"drips": {
"${network}": {
"ownedBy": "${address}"
}
}
}
`;

0 comments on commit 802061e

Please sign in to comment.