Skip to content

Instantly share code, notes, and snippets.

@tgmarinho
Created November 11, 2022 21:12
Show Gist options
  • Select an option

  • Save tgmarinho/3e26d98c229bb61199bf4117fbdc775b to your computer and use it in GitHub Desktop.

Select an option

Save tgmarinho/3e26d98c229bb61199bf4117fbdc775b to your computer and use it in GitHub Desktop.
order object by key
const data = {
amount_marketplace: null,
amount: 500000000000000000000,
latest_settlement_offer_address: null,
released_at: null,
arbitrator_fee: 500,
marketplace: '0x0000000000000000000000000000000000000777',
split_marketplace: 1000,
refunded_at: null,
amount_arbitrator: null,
amount_unicrow: null,
latest_settlement_offer_buyer: null,
latest_settlement_offer_seller: null,
claimed: false,
challenge_period_start: 1668124288,
marketplace_fee: 1000,
arbitrator: '0x36C6fd67A91D3592a310a485ec6aD526A8de28a4',
seller: '0x952e927887aB169761f727E36c5f8e10837E1A6d',
challenge_period_end: 1668124888,
consensus_seller: -1,
settled_at: null,
transaction_hash:
'0xde7a20bad8b9ce197adf307105e845d8b54b6aaae273b2915f3d9fef3cd8da07',
split_buyer: 10000,
split_seller: 0,
name: 'Challenge',
arbitrator_proposer: null,
challenge_period_extension: 600,
currency: '0x585859ADA2E7cBb63dD31eB6c0f6b71bdd01E5ab',
arbitrated: false,
amount_seller: null,
amount_buyer: null,
escrow_id: 7,
block_number: 5334,
challenged_at: 1668123750,
status_arbitration: 'ArbitratorApproved',
split_unicrow: 100,
deposit_transaction_hash:
'0xb5114973b95b04fe6aa891c254ad21b202f0f9edad229ff5e45883aad9b7ba88',
paid_at: 1668123688,
challenge_period: 600,
consensus_buyer: 1,
buyer: '0xBA8B519232c579C14ae81669B2C824a25C85984a'
}
Object.keys(data).sort().reduce((o, key) => ({...o, [key]: data[key]}), {})
// JSON.stringify(Object.keys(a).sort().reduce((o, key) => ({...o, [key]: a[key]}), {}))
// '{"amount":500000000000000000000,"amount_arbitrator":null,"amount_buyer":null,"amount_marketplace":null,"amount_seller":null,"amount_unicrow":null,"arbitrated":false,"arbitrator":"0x36C6fd67A91D3592a310a485ec6aD526A8de28a4","arbitrator_fee":500,"arbitrator_proposer":null,"block_number":5334,"buyer":"0xBA8B519232c579C14ae81669B2C824a25C85984a","challenge_period":600,"challenge_period_end":1668124888,"challenge_period_extension":600,"challenge_period_start":1668124288,"challenged_at":1668123750,"claimed":false,"consensus_buyer":1,"consensus_seller":-1,"currency":"0x585859ADA2E7cBb63dD31eB6c0f6b71bdd01E5ab","deposit_transaction_hash":"0xb5114973b95b04fe6aa891c254ad21b202f0f9edad229ff5e45883aad9b7ba88","escrow_id":7,"latest_settlement_offer_address":null,"latest_settlement_offer_buyer":null,"latest_settlement_offer_seller":null,"marketplace":"0x0000000000000000000000000000000000000777","marketplace_fee":1000,"name":"Challenge","paid_at":1668123688,"refunded_at":null,"released_at":null,"seller":"0x952e927887aB169761f727E36c5f8e10837E1A6d","settled_at":null,"split_buyer":10000,"split_marketplace":1000,"split_seller":0,"split_unicrow":100,"status_arbitration":"ArbitratorApproved","transaction_hash":"0xde7a20bad8b9ce197adf307105e845d8b54b6aaae273b2915f3d9fef3cd8da07"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment