-
Notifications
You must be signed in to change notification settings - Fork 48
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 #767 from BoltzExchange/configurable-refs
feat: configurable referral values
- Loading branch information
Showing
31 changed files
with
2,210 additions
and
269 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,43 @@ | ||
import { Arguments } from 'yargs'; | ||
import { GetReferralsRequest } from '../../proto/boltzrpc_pb'; | ||
import { ApiType, BuilderTypes } from '../BuilderComponents'; | ||
import { callback, loadBoltzClient } from '../Command'; | ||
|
||
export const command = 'getreferrals [id]'; | ||
|
||
export const describe = 'gets referrals from the database'; | ||
|
||
export const builder = { | ||
id: { | ||
type: 'string', | ||
describe: 'optional ID of a referral to query for', | ||
}, | ||
}; | ||
|
||
export const handler = ( | ||
argv: Arguments<BuilderTypes<typeof builder> & ApiType>, | ||
): void => { | ||
const req = new GetReferralsRequest(); | ||
|
||
if (argv.id) { | ||
req.setId(argv.id); | ||
} | ||
|
||
loadBoltzClient(argv).getReferrals( | ||
req, | ||
callback((res) => { | ||
const toPrint: Record<string, any> = {}; | ||
|
||
for (const entry of res.getReferralList()) { | ||
toPrint[entry.getId()] = { | ||
id: entry.getId(), | ||
config: entry.hasConfig() | ||
? JSON.parse(entry.getConfig()!) | ||
: undefined, | ||
}; | ||
} | ||
|
||
return toPrint; | ||
}), | ||
); | ||
}; |
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,70 @@ | ||
import { Arguments } from 'yargs'; | ||
import { deepMerge } from '../../Utils'; | ||
import { | ||
GetReferralsRequest, | ||
GetReferralsResponse, | ||
SetReferralRequest, | ||
} from '../../proto/boltzrpc_pb'; | ||
import { ApiType, BuilderTypes } from '../BuilderComponents'; | ||
import { callback, loadBoltzClient } from '../Command'; | ||
|
||
export const command = 'setreferral <id> [config] [amend]'; | ||
|
||
export const describe = 'updates the config of a referral'; | ||
|
||
export const builder = { | ||
id: { | ||
type: 'string', | ||
describe: 'optional ID of the referral', | ||
}, | ||
config: { | ||
type: 'object', | ||
describe: 'config changes to be applied', | ||
}, | ||
amend: { | ||
type: 'bool', | ||
describe: 'amends the existing config instead of overwriting it', | ||
}, | ||
}; | ||
|
||
export const handler = async ( | ||
argv: Arguments<BuilderTypes<typeof builder> & ApiType>, | ||
): Promise<void> => { | ||
const req = new SetReferralRequest(); | ||
|
||
if (argv.id) { | ||
req.setId(argv.id); | ||
} | ||
|
||
const client = loadBoltzClient(argv); | ||
|
||
if (argv.amend) { | ||
const getReq = new GetReferralsRequest(); | ||
getReq.setId(argv.id); | ||
|
||
const existing = ( | ||
await new Promise<GetReferralsResponse>((resolve, reject) => | ||
client.getReferrals(getReq, (error, response) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(response); | ||
} | ||
}), | ||
) | ||
).getReferralList()[0]; | ||
|
||
if (existing.hasConfig()) { | ||
const merged = JSON.parse(existing.getConfig()!); | ||
deepMerge(merged, JSON.parse(argv.config)); | ||
|
||
req.setConfig(JSON.stringify(merged)); | ||
} else { | ||
req.setConfig(argv.config); | ||
} | ||
} else { | ||
req.setConfig(argv.config); | ||
} | ||
|
||
client.setReferral(req, callback()); | ||
}; |
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
Oops, something went wrong.